Validate a schema file: Find typos in property names #380
-
I am writing a json schema file and want to validate that is is correct.
Now my problem: It always tells me that my schema is valid. How can I be sure that I do not have any typos in my property names, when they are always considered valid? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The current meta-schemas (the schema that validates schemas) don't check for mistyped keywords. They instead allow unknown keywords without checking them. So when you mistype a keyword, it's as if that keyword just isn't there. |
Beta Was this translation helpful? Give feedback.
-
In JSON Schema 2020-12 (and all versions that came before it), it's allowed for users to add their own custom keywords. The meta-schema isn't capable of being smart enough to know that IMO, what's really needed for something like this is a linter that is smart enough to notice that That said, there's an easy workaround you can use to validate that your schemas don't have any custom/misspelled keywords. You can use a custom meta-schema. {
"$id": "https://example.com/draft/2020-12/schema/strict",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
"https://json-schema.org/draft/2020-12/vocab/validation": true,
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
"https://json-schema.org/draft/2020-12/vocab/content": true
},
"$dynamicAnchor": "meta",
"$ref": "https://json-schema.org/draft/2020-12/schema",
"unevaluatedProperties": false
} You can validate your schemas against this one or use it's {
"$id": "https://example.com/gamestick-game.schema.json",
"$schema": "https://example.com/draft/2020-12/schema/strict",
...
} |
Beta Was this translation helpful? Give feedback.
In JSON Schema 2020-12 (and all versions that came before it), it's allowed for users to add their own custom keywords. The meta-schema isn't capable of being smart enough to know that
requireds
is a typo and not a custom keyword that you chose to include in your schema.IMO, what's really needed for something like this is a linter that is smart enough to notice that
requireds
looks a whole lot like the known keywordrequired
and give you a warning that it's probably a typo. Unfortunately, a linter capable of checking for those sorts of errors doesn't exist. There's been talk about it for years, but no one has managed to find the time to build it.That said, there's an easy workaround you…