-
-
Notifications
You must be signed in to change notification settings - Fork 865
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
Is there a strict mode to decline extra data in JSON? #139
Comments
You need to use additionalProperties keyword in the schema. There is no such thing as strict mode in the standard. By default additional properties are allowed. |
Perfect, just missed that. Thanks! |
That page goes on to say "This shortcoming is perhaps one of the biggest surprises of the combining operations in JSON schema: it does not behave like inheritance in an object-oriented language. There are some proposals to address this in the next version of the JSON schema specification". However, I can't find any indication of consensus within the json-schema community about how to move forward with this. A "strict mode" in AJV would bridge that gap. |
@hatfinch please see #134 (comment) |
Thank you for your response! I don't think any of the proposed solutions described at that link really fit my use case. I have something like the (simplified) following:
Your solution #1 at that link, "don't worry about additionalProperties and simply allow them", comes closest: I'm really only looking for strictness. (It's possible that $merge could be used, but I can't see how to go that route without it ending up more verbose than just defining
As he says, "First, we need to make it possible to distinguish between use cases #1 and #2. Currently we do not have inheritance (allOf is more of an intersection operator). So I would say that “additionalProperties: false” on its own should indicate #2: the desire for strict validation of property names. That is it’s most clear current effect, and many, many JSON Schema users have indicated that that is why they use “additionalProperties: false”." It seems to me that although it's difficult to obtain consensus on how to achieve strictness in the spec, the tools could allow it as a global option, and that this would be useful to "many, many JSON Schema users". |
We see that extra data added outside the scope of the schema is allowed and passes
ajv
validation. Is there a way to block this?Schema:
JSON configuration:
It looks like the added values of
capability_group
andcapability_sets
are extra data that aren't in the JSON schema and passajv
validation. Is there a flag or way around this to not allow extra data here?The text was updated successfully, but these errors were encountered: