How can I get AJV (v5.0.0) to resolve $schema?
Asked Answered
B

1

6

I'm having trouble getting this line to resolve at the top of my JSON Schema when compiling it with AJV: "$schema": "node_modules/ajv/lib/refs/json-schema-draft-04#"

I've also tried this line to work, to no avail: "$schema": "http://json-schema.org/draft-04/schema#"

(And a lot of other permutations of the above.)

No matter what I put, AJV says: "Error: no schema with key or ref..."

What exactly needs to go in this property?

Thank you (BTW AJV is great, thank you.)

Balanced answered 5/12, 2018 at 17:2 Comment(2)
In case you haven't seen this before, there is a "If you need to continue using draft-04 schemas" section in the v5.0.0 release notes. It may or may not be useful in your case.Viens
Thanks - I'm not keen to use 4.0. I'm looking for a way to indicate the version in "$schema" - version 7 is fine, I just can't find ANY string that will not generate an error. The meta schemas are both in my local file system, and I'm connected. But nothing works. What string do you use for $schema?Balanced
F
0

For Draft 7, the correct string is "$schema": "http://json-schema.org/draft-07/schema#".

Here's an example, sample.schema.json:

{
  "$id": "https://www.example.com/sample.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Sample",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "uid": {
      "type": "number"
    }
  },
  "additionalProperties": false
}
Forgive answered 3/7, 2023 at 0:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.