'AJV: no schema with key or ref "https://json-schema.org/draft-07/schema"
I am using ajv 8.6.2
I have schemas that validate against draft-07 using the default export
When I use the draft-09 export all of my schemas give me this error:
no schema with key or ref "https://json-schema.org/draft-07/schema"
Same error exists if I use this:
no schema with key or ref "https://json-schema.org/draft-09/schema"
Can't seem to figure out what's going on here?
Solution 1:[1]
AJV does not seem to support HTTPs versions of the json-schema identifiers; try using http: instead:
{
"$schema": "http://json-schema.org/draft-07/schema"
}
Solution 2:[2]
If you mean by
When I use the draft-09 export all
that you're using Ajv2019 instance
import Ajv2019 from "ajv/dist/2019"
const ajv = new Ajv2019()
then you need to add the draft-07 metaschema:
const draft7MetaSchema = require("ajv/dist/refs/json-schema-draft-07.json")
ajv.addMetaSchema(draft7MetaSchema)
as explained at https://ajv.js.org/guide/schema-language.html#draft-2019-09-and-draft-2020-12
FYI, don't refer to JSON meta schemas with https://, their identifiers do start with http://, ajv doesn't retrieve them, it packages them instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yossarian21 |
| Solution 2 | Zdenek F |
