ajv: Meta-Schema-Validation not working / no guide available

What version of Ajv are you using? Does the issue happen if you use the latest version?

Integrating Ajv2019 from "ajv": "^6.12.6", with Angular

Ajv options object


 const ajv = new Ajv2019({allErrors: true});

JSON Schema

Use case: Trying to validate custom schemas against meta schema draft 2019-09 e.g:


{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "$id": "https://example.com/schemas/template.json",
    "title": "Template",
    "type": "object",
    "properties": {},
    "required": [],
    "additionalProperties": false
}

Your code


const ajv = new Ajv2019({allErrors: true});
 valid = ajv.validateSchema(json);
errors = ajv.errors;

Validation result, data AFTER validation, error messages

no schema with key or ref "https://json-schema.org/draft/2019-09/schema"

What results did you expect?

Meta-Schema validation working.

Are you going to resolve the issue?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16 (3 by maintainers)

Most upvoted comments

In my use case the user creates custom schemas and therefore I need to explicitly validate the schema against the meta schema (draft 2019-09) and report any issues with the validation.

Should’ve started with that.

Get the validator function directly then:

const validateMetaSchema = ajv.getSchema("https://json-schema.org/draft/2019-09/schema")

How should validateSchema behave with an instance of Ajv2019?

It would validate it agains draft-2019 meta-schema

It shouldn’t be included because the usage of Ajv2019 already implies "https://json-schema.org/draft/2019-09/schema" meta-schema. Also you aren’t using validateSchema() properly.