Skip to content

Commit 38952da

Browse files
authored
Merge pull request #74 from GrantBirki/draft-04
Adding `draft-04` support for JSON validations
2 parents c6ca533 + 78ad73d commit 38952da

File tree

9 files changed

+339
-29
lines changed

9 files changed

+339
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Here is a quick example of how to install this action in any workflow:
4040
| `files` | `false` | `""` | List of file paths to validate. Each file path must be on a newline. |
4141
| `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 |
4242
| `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 |
43-
| `json_schema_version` | `false` | `"draft-07"` | The version of the JSON schema to use - `"draft-07"`, `"draft-2019-09"`, `"draft-2020-12"` |
43+
| `json_schema_version` | `false` | `"draft-07"` | The version of the JSON schema to use - `"draft-07"`, `"draft-04"`, `"draft-2019-09"`, `"draft-2020-12"` |
4444
| `json_extension` | `false` | `".json"` | The file extension for JSON files (e.g. .json) |
4545
| `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 |
4646
| `use_ajv_formats` | `false` | `"true"` | Whether or not to use the [AJV formats](https://github.com/ajv-validator/ajv-formats) with the JSON processor |

__tests__/functions/json-validator.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,26 @@ test('processes a real world example when yaml_as_json is true and the single fi
424424
)
425425
})
426426

427+
test('processes a simple example and the single file contains no errors and uses the draft-04 ajv schema', async () => {
428+
process.env.INPUT_BASE_DIR = '__tests__/fixtures/json/valid'
429+
process.env.INPUT_JSON_SCHEMA_VERSION = 'draft-04'
430+
431+
expect(await jsonValidator(excludeMock)).toStrictEqual({
432+
failed: 0,
433+
passed: 1,
434+
skipped: 0,
435+
success: true,
436+
violations: []
437+
})
438+
439+
expect(debugMock).toHaveBeenCalledWith(
440+
'using ajv-formats with json-validator'
441+
)
442+
expect(debugMock).toHaveBeenCalledWith(
443+
'json - using baseDir: __tests__/fixtures/json/valid'
444+
)
445+
})
446+
427447
test('successfully validates json files with a schema when files is defined', async () => {
428448
const files = [
429449
'__tests__/fixtures/json/valid/json1.json',

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inputs:
3434
required: false
3535
default: ""
3636
json_schema_version:
37-
description: The version of the JSON schema to use - "draft-07", "draft-2019-09", "draft-2020-12"
37+
description: The version of the JSON schema to use - "draft-07", "draft-04", "draft-2019-09", "draft-2020-12"
3838
default: "draft-07"
3939
required: false
4040
json_extension:

dist/index.js

+253-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)