Skip to content
Latchkey

ajv "must have required property" validation error in CI

ajv validated your data against a JSON Schema and a required field was absent. It reports "must have required property 'X'" with the JSON path to the object that is missing it.

What this error means

ajv-cli exits non-zero with "data must have required property 'version'" (or similar) and an instancePath. The document parsed fine but does not satisfy the schema.

ajv
config.json invalid
[
  {
    "instancePath": "",
    "schemaPath": "#/required",
    "keyword": "required",
    "params": { "missingProperty": "version" },
    "message": "must have required property 'version'"
  }
]

Common causes

A mandatory field is missing from the data

The schema lists the property in required, but the config file never sets it, so validation fails.

The field exists but under the wrong name or level

A typo or wrong nesting means the required key is not where the schema expects it, so ajv still reports it missing.

How to fix it

Add the required field to the data

  1. Read the instancePath and missingProperty from ajv's output.
  2. Add the property at that path with a valid value.
  3. Re-run ajv validate to confirm.
Terminal
ajv validate -s schema.json -d config.json

Relax the schema if the field is genuinely optional

If the property should not be mandatory, remove it from the schema's required array.

schema.json
{
  "type": "object",
  "required": ["name"],
  "properties": { "name": { "type": "string" }, "version": { "type": "string" } }
}

How to prevent it

  • Keep the schema and the documented config in sync when fields change.
  • Validate configs against the schema in a pre-commit hook.
  • Use instancePath in errors to jump straight to the missing field.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →