ajv-cli compile: Validate the Schema Itself
ajv compile -s schema.json compiles a schema and fails if the schema is malformed or breaks strict-mode rules.
Before you trust a schema to guard config, validate the schema itself. ajv compile catches typos and strict-mode violations that would otherwise silently pass everything.
What it does
ajv-cli compile loads a schema and compiles it without any data, verifying it against the JSON Schema metaschema and Ajv strict-mode rules. It exits non-zero if the schema has an unknown keyword, an invalid $ref, or a type that strict mode rejects.
Common usage
# compile (validate) the schema in strict mode
npx ajv compile -s schema.json
# compile against a specific draft
npx ajv compile -s schema.json --spec=draft2020
# compile with referenced schemas resolved
npx ajv compile -s schema.json -r "schemas/*.json"Options
| Flag | What it does |
|---|---|
| -s <file> | Schema to compile and check |
| -r <glob> | Referenced schemas ($ref targets) |
| --spec=<draft> | JSON Schema draft to compile against |
| --strict=true|false | Toggle strict-mode diagnostics (default true) |
| --strict-tuples=false | Relax the tuple/items strict check |
| -o <file> | Write a standalone validation module |
In CI
Run ajv compile on every schema file in a lint job so a broken schema fails fast rather than validating nothing. Keeping --strict=true catches keyword typos (minLenght) that strict mode flags but lenient validators ignore.
Common errors in CI
strict mode: unknown keyword: "minLenght" flags a misspelled keyword (strict mode treats unknown keywords as errors). strict mode: missing type "object" for keyword "properties" means a subschema uses properties without declaring "type": "object". can't resolve reference #/definitions/Foo means a $ref points at a definition that does not exist. reference "..." resolves to more than one schema means duplicate $id values.