Skip to content

Commit

Permalink
Merge pull request #74 from GrantBirki/draft-04
Browse files Browse the repository at this point in the history
Adding `draft-04` support for JSON validations
  • Loading branch information
GrantBirki authored Aug 22, 2024
2 parents c6ca533 + 78ad73d commit 38952da
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Here is a quick example of how to install this action in any workflow:
| `files` | `false` | `""` | List of file paths to validate. Each file path must be on a newline. |
| `use_dot_match` | `false` | `"true"` | Whether or not to use dot-matching when searching for files - `"true"` or `"false"` - If this is true, directories like `.github`, etc will be searched |
| `json_schema` | `false` | `""` | The full path to the JSON schema file (e.g. ./schemas/schema.json) - Default is `""` which doesn't enforce a strict schema |
| `json_schema_version` | `false` | `"draft-07"` | The version of the JSON schema to use - `"draft-07"`, `"draft-2019-09"`, `"draft-2020-12"` |
| `json_schema_version` | `false` | `"draft-07"` | The version of the JSON schema to use - `"draft-07"`, `"draft-04"`, `"draft-2019-09"`, `"draft-2020-12"` |
| `json_extension` | `false` | `".json"` | The file extension for JSON files (e.g. .json) |
| `json_exclude_regex` | `false` | `""` | A regex to exclude files from validation (e.g. `".*\.schema\.json$"` to exclude all files ending with `.schema.json`) - Default is `""` which doesn't exclude any files |
| `use_ajv_formats` | `false` | `"true"` | Whether or not to use the [AJV formats](https://github.com/ajv-validator/ajv-formats) with the JSON processor |
Expand Down
20 changes: 20 additions & 0 deletions __tests__/functions/json-validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,26 @@ test('processes a real world example when yaml_as_json is true and the single fi
)
})

test('processes a simple example and the single file contains no errors and uses the draft-04 ajv schema', async () => {
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid'
process.env.INPUT_JSON_SCHEMA_VERSION = 'draft-04'

expect(await jsonValidator(excludeMock)).toStrictEqual({
failed: 0,
passed: 1,
skipped: 0,
success: true,
violations: []
})

expect(debugMock).toHaveBeenCalledWith(
'using ajv-formats with json-validator'
)
expect(debugMock).toHaveBeenCalledWith(
'json - using baseDir: __tests__/fixtures/json/valid'
)
})

test('successfully validates json files with a schema when files is defined', async () => {
const files = [
'__tests__/fixtures/json/valid/json1.json',
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ inputs:
required: false
default: ""
json_schema_version:
description: The version of the JSON schema to use - "draft-07", "draft-2019-09", "draft-2020-12"
description: The version of the JSON schema to use - "draft-07", "draft-04", "draft-2019-09", "draft-2020-12"
default: "draft-07"
required: false
json_extension:
Expand Down
260 changes: 253 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 38952da

Please sign in to comment.