Skip to content

Commit 9caf79a

Browse files
authored
Merge pull request #49 from GrantBirki/support-ajv-non-strict-mode
support ajv strict option via inputs
2 parents 0be3fe3 + 51a3ef9 commit 9caf79a

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Here is a quick example of how to install this action in any workflow:
5353
| `use_gitignore` | `true` | `"true"` | Whether or not to use the .gitignore file in the root of the repository to exclude files from validation - `"true"` or `"false"` - Default is `"true"` |
5454
| `git_ignore_path` | `false` | `".gitignore"` | The full path to the .gitignore file to use if use_gitignore is set to "true" (e.g. ./src/.gitignore) - Default is ".gitignore" which uses the .gitignore file in the root of the repository |
5555
| `allow_multiple_documents` | `false` | `"false"` | Whether or not to allow multiple documents in a single YAML file - `"true"` or `"false"` - Default is `"false"`. Useful for k8s documents. |
56+
| `ajv_strict_mode` | `false` | `"true"` | Whether or not to use strict mode for AJV - "true" or "false" - Default is "true" |
5657
| `github_token` | `false` | `${{ github.token }}` | The GitHub token used to create an authenticated client - Provided for you by default! |
5758

5859
## Outputs 📤

__tests__/functions/json-validator.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ beforeEach(() => {
2727
process.env.INPUT_YAML_EXTENSION_SHORT = '.yml'
2828
process.env.INPUT_FILES = ''
2929
process.env.INPUT_JSON_SCHEMA_VERSION = 'draft-07'
30+
process.env.INPUT_AJV_STRICT_MODE = 'true'
3031
})
3132

3233
test('successfully validates a json file with a schema', async () => {

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ inputs:
8585
description: Whether or not to allow multiple documents in a single YAML file - "true" or "false" - Default is "false"
8686
required: false
8787
default: "false"
88+
ajv_strict_mode:
89+
description: Whether or not to use strict mode for AJV - "true" or "false" - Default is "true"
90+
required: false
91+
default: "true"
8892
outputs:
8993
success:
9094
description: Whether or not the validation was successful for all files - "true" or "false"

dist/index.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions/json-validator.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ import {globSync} from 'glob'
1313
// :returns: the compiled schema
1414
async function schema(jsonSchema) {
1515
const jsonSchemaVersion = core.getInput('json_schema_version')
16+
const strict = core.getBooleanInput('ajv_strict_mode')
17+
18+
core.debug(`json_schema_version: ${jsonSchemaVersion}`)
19+
core.debug(`strict: ${strict}`)
1620

1721
var ajv
1822
if (jsonSchemaVersion === 'draft-07') {
19-
ajv = new Ajv({allErrors: true})
23+
ajv = new Ajv({allErrors: true, strict: strict})
2024
} else if (jsonSchemaVersion === 'draft-2019-09') {
21-
ajv = new Ajv2019({allErrors: true})
25+
ajv = new Ajv2019({allErrors: true, strict: strict})
2226
} else if (jsonSchemaVersion === 'draft-2020-12') {
23-
ajv = new Ajv2020({allErrors: true})
27+
ajv = new Ajv2020({allErrors: true, strict: strict})
2428
} else {
2529
core.warning(
2630
`json_schema_version '${jsonSchemaVersion}' is not supported. Defaulting to 'draft-07'`
2731
)
28-
ajv = new Ajv({allErrors: true})
32+
ajv = new Ajv({allErrors: true, strict: strict})
2933
}
3034

3135
// use ajv-formats if enabled

0 commit comments

Comments
 (0)