Skip to content
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

Optionally forbid unsupported keywords in metaschema validation? #205

Open
eapache-opslevel opened this issue Jan 10, 2025 · 2 comments
Open

Comments

@eapache-opslevel
Copy link

Per json-schema-org/json-schema-spec#577, JSON Schema metaschemas generally allow unsupported keywords to be present.

We recently hit a similar issue as the person who filed that ticket, where a typo in our schema silently removed some validations we thought were running.

As an implementation, it would be very handy if json_schemer allowed a flag to validate_schema that "turned on" additionalProperties: false for the metaschema in order to catch such things.

@davishmcclurg
Copy link
Owner

This is an interesting idea. It sounds similar to json-schema's strict option:

#
# with the `:strict` option, all properties are considered to have `"required": true` and all objects `"additionalProperties": false`
#

# => true
JSON::Validator.validate(schema, { "a" => 1, "b" => { "x" => 2 } }, :strict => true)
# => false
JSON::Validator.validate(schema, { "a" => 1, "b" => { "x" => 2 }, "c" => 3 }, :strict => true)
# => false
JSON::Validator.validate(schema, { "a" => 1 }, :strict => true)

I think it makes sense to offer it as an option for both metaschema and regular validation. I probably won't work on this in the near future myself, but if you're interested in contributing, I'd be happy to help/review.

For just meta schema validation like you're talking about, you might be able to create a custom meta schema that includes additionalProperties: false everywhere.

@eapache-opslevel
Copy link
Author

you might be able to create a custom meta schema that includes additionalProperties: false everywhere

Yeah, I took a quick peek at this. It's definitely possible, but unfortunately not as trivial as one might hope.

Also found that the next version of the json-schema spec will probably do this by default: https://json-schema.org/blog/posts/the-last-breaking-change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants