cardinalby / schema-validator-action

JSON Schema validator Action
MIT License
11 stars 2 forks source link
json-schema schema schemasafe validation validator yaml

test build

Validate JSON or YAML against a schema

A GitHub Action for validating JSON or YAML file against a schema. Fails if validation doesn't succeed. Uses schemasafe validator under the hood.

Examples

- 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'

Basic inputs

🔻 file Required

Path to the JSON or YAML file to be validated.

🔸 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:

Read 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.

Advanced inputs

🔸 fileParser default value: "auto"

Determines the way files will be parsed (as JSON or as YAML). Possible values:

🔸 refSchemasMap

Contains a JSON object with the schemas needed to resolve external $refs 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 $refs 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"]

Outputs

🔹 errorType

Is empty if validation succeeds.

In case of multiple files they are processed one by one and errorType indicates the first error occurred.