-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Strict Validation #64
Comments
Ajv's strict mode being on by default has caused a lot of problems and misunderstandings because it violates quite a few JSON Schema requirements. Problems caused by strict mode show up on stackoverflow a lot, I hear. Most of what "strict mode" does should be handled by a linter rather than integrated into schema evaluation (although a one-step lint-and-evaluate that was opt-in could work well). You can easily detect typos like {
"$id": "https://example.com/strict-meta-schema",
"$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
} The Validating against such as meta-schema as a build step (even if your schema doesn't declare this meta-schema as it's proper meta-schema) means you don't incur the cost of extra checks at runtime. |
UGH 🤦 that should have been |
Thanks! I can confirm that works because it choked on my extension 😂. In order to get it to validate schemas with my extension, I guess I need to add it to the metaschema somehow, yes? |
I think I got it: {
"$id": "https://example.com/strict-meta-schema",
"$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",
"unevaluatedProperties": false,
"allOf": [
{ "$ref": "https://json-schema.org/draft/2020-12/schema" },
{ "$ref": "file://absolute/path/to/my-extension.schema.json" }
]
} |
@theory yup, that looks good! Although you should use something other than |
LOL, yeah, that was just for public consumption :-) |
I'm switching from Ajv, which has a number of strict options that I will miss. Any chance support for some of these could be added? Will help prevent me from making typos like
descripxtion
.The text was updated successfully, but these errors were encountered: