A GitHub Action for validating JSON or YAML file against a schema. Fails if validation doesn't succeed. Uses schemasafe validator under the hood.
- name: Validate package.json against a local schema
uses: cardinalby/schema-validator-action@v3
with:
file: 'package.json'
schema: 'schemas/package.schema.json'
- name: Validate action.yml against a remote schema
uses: cardinalby/schema-validator-action@v3
with:
file: 'action.yml'
schema: 'https://json.schemastore.org/github-action.json'
- name: Validate all json files using their own $schema properties
uses: cardinalby/schema-validator-action@v3
with:
file: 'dir/*.json'
- name: Validate 3 files using the same schema
uses: cardinalby/schema-validator-action@v3
with:
file: 'first.json|second.json|third.json'
schema: 'https://json.schemastore.org/swagger-2.0.json'
file
RequiredPath to the JSON or YAML file to be validated.
|
symbol.schema
Path or URL to JSON or YAML file with a schema to validate against.
Can be empty if all validated files contain valid $schema
property.
Input value has a priority over $schema
property in file if both present.
mode
default value: "default"Sets the strictness of the schema compiling. Possible values:
lax
: the most relaxed modespec
: mode is the same as 'lax' but also disables format assertion in draft2019-09 and newer $schema versionsdefault
: used by default, doesn't allow unknown keywords and unreachable checks to be present in the schema strong
: the most strict modeRead details in schemasafe documentation.
fixSchema
experimental, default value: "false"If true
, tries to fix schema by stripping non-default "format" instructions to make it valid for the
underlying library.
This input is experimental, and it's behaviour can be changed in future versions.
fileParser
default value: "auto"Determines the way files will be parsed (as JSON or as YAML). Possible values:
auto
(default) - based on file extension (json/yml/yaml). It means, .json files containing
yaml will lead to error. If file extension is unknown, it will behave as json|yaml
optionjson
- parse all files as JSONyaml
- parse all files as YAMLjson|yaml
- try to parse files both with json and yaml parser (compatible with v2)refSchemasMap
Contains a JSON object with the schemas needed to resolve external $ref
s in the main schema.
JSON object should contain pairs of:
Example: {"https://my-schemas.com/schema-id": "schema_files/my.schema.json"}
refSchemasArray
Contains a JSON array with the schemas needed to resolve external $ref
s in the main schema.
JSON array should contain string elements, each pointing to schema file path or URL to download schema from.
All schemas should contain $id
(or id
for draft-04) property to be identified.
This input is more convenient alternative for refSchemasMap
input if all external schemas
contain $id
property.
Example: ["schema_files/my.schema.json"]
errorType
Is empty if validation succeeds.
file
: file loading or parsing failedschema
: schema loading, parsing or refs resolving failedvalidation
: file data doesn't correspond schemaIn case of multiple files they are processed one by one and errorType
indicates the first error occurred.