-
-
Notifications
You must be signed in to change notification settings - Fork 886
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
Allow easy detection of ignored default
keywords in schemas
#957
Comments
@not-an-aardvark I understand the problem. The docs list the scenarios where defaults are ignored, but Ajv simply uses them only in properties and items:
So it doesn't really know when defaults are ignored... What would be possible though (I think:) is to make a meta-schema that would fail if a schema has defaults that are ignored, similar to this one: https://github.com/epoberezkin/ajv/blob/master/lib/refs/json-schema-secure.json Then it would be one line of code to validate against it. I don't think it should be an option though - we can just add to the docs this line and you can also call it for user-provided schemas. |
actually meta-schema is not possible, logging or throwing is possible though - see commit f59c995?w=true |
It has to be an option, and it has to be excluded for meta-schema compilation, as several other options are, because standard meta-schema has
|
Thanks for the feedback. One question -- is there a reason we couldn't just remove the ignored |
The meta schema is part of JSON schema specification - I would rather we don’t have a different version of it here. |
Ok thanks, I'll start working on this. |
Cool, thank you, you can continue off my branch with this commit, and then I merge |
@not-an-aardvark it's in 6.10.0. I also added strictKeywords - it is useful to catch typos in keywords that would lead to them being quietly ignored. |
What version of Ajv you are you using?
6.9.1
What problem do you want to solve?
When using ajv with
useDefaults: true
, thedefault
keyword is ignored in some cases, as documented in the readme. If someone is aware of the existence of thedefault
keyword but isn't familiar with the details of where it can be used, they might inadvertently use it in a place where it's ignored, resulting in a buggy schema. (This recently caused some bugs in ESLint rules -- also see eslint/eslint#11427.)We'd like to detect this problem so that schema authors can fix the issue. As far as I can tell, there isn't a simple way for an external tool to figure out whether an ignored
default
keyword exists in a user-provided schema, without reimplementing some of the logic fromajv
.What do you think is the correct solution to problem?
It should be possible to opt into a mode where invalid
default
keywords result in a compilation or validation error, rather than being ignored. It seems like this could in principle be added to the meta-schema, although it could make the meta-schema substantially larger. Another possibility could be to add an option to theAjv
constructor that causes this case to throw an error.Will you be able to implement it?
I'm willing to give it a shot if there is agreement that this is worthwhile.
The text was updated successfully, but these errors were encountered: