Ajv: no schema with key or ref "http://json-schema.org/draft-04/schema#"

Created on 27 Apr 2017  路  9Comments  路  Source: ajv-validator/ajv

I have upgraded from ajv 4.x to ajv 5.0 and I now get above errors when validating json files that I generate using the excellent 'typescript-json-schema' module that generate json schema with
"$schema": "http://json-schema.org/draft-04/schema#".

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

Ajv options object

allErrors: true, verbose: false, addUsedSchema: false, inlineRefs: false,

JSON Schema

{
  ...
  "$schema": "http://json-schema.org/draft-04/schema#"
}

Validation result, data AFTER validation, error messages

 Error: no schema with key or ref "http://json-schema.org/draft-04/schema#"

What results did you expect?

The schema to validate like it did in ajv 4.x

Note, as my schemas are autogenerated they are a little difficult to change, so it would be great if Ajv 5 could accept them (like Ajv 4).

usage

Most helpful comment

@mmc41 I had this issue too, but found the migration guide under the 5.0.0 release notes: https://github.com/epoberezkin/ajv/releases/tag/5.0.0

All 9 comments

@mmc41 I had this issue too, but found the migration guide under the 5.0.0 release notes: https://github.com/epoberezkin/ajv/releases/tag/5.0.0

@adamayogo that is correct. @mmc41 this guide explains how to use draft-04 schemas with 5.x.x version. By default it only includes meta-schema for draft-06.

I do not understand why is the property $id with the url to the schema required for the schema? The property $schema is for the schema url, or not?

I fixed the error no schema with key or ref by adding the $id with the url to the json-schema.
Now my files looks like (snippet):

{
  "$id": "http://json-schema.org/draft-04/schema#",
  "$schema": "http://json-schema.org/draft-04/schema#"
}

I need $schema for the editor (VS Code). Why is id required?

@Domvel $schema is URI of the meta-schema, $id is recommended rather than required, please see JSON schema spec

@epoberezkin Why is not possible to use ajv without $id? Only with $schema. I just added the id property to work with.

It is possible to use ajv without $id, it is only needed if you refer to a schema.

I 'm also experiencing the issue described at the top of this thread. It seems Ajv doesn't accept the $schema field at all. Whatever I put there, I get Error: no schema with key or ref "..."

@steph643 draft-04 meta-schema has to be added to Ajv instance - please see top of readme.

@epoberezkin , thanks for your answer.

I use draft-06, not draft-04, but the readme says to call addMetaSchema for draft-06 also. Sorry, I didn't see this, I will give it a try.

Thanks again.

Was this page helpful?
0 / 5 - 0 ratings