-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Support JSON Schema "not" #199
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
Comments
Can you give an example for a use case where you'd want to use "not"? Currently, there are other json schema validation conditions that we don't support and we're a bit wary of adding support to some of them due to unnecessary complexity. Since this is a spec procedure, it's better to elaborate how and why think think a change is required. |
@webron sure. The example that got me thinking of this is: With the current version of JSON schema, the simplest way to indicate that a value is not valid for a particular schema is Valid values are a big part of an API's docs, and invalid values also are. Being able to indicate to users that a particular value is something that would be very useful. Thoughts? |
Right, but since you have the validation options, you can actually express it as:
Of course, specifically for email:
It would really help to see an actual example that cannot be expressed this way. |
We have a concept of We can't use something like Let's say the only invalid property is email, then the schema would be: {
"type": "object",
"properties": {
"email": { "not": {} }
}
} This schema is valid for all objects that don't have an Sorry for the small amount of detail in the previous comment. Hope this makes things clearer. |
Yes, it does. Unfortunately, that's one of the side effects we have in Swagger 2.0 which I dislike. To me, that pretty much misses the point of documenting your API. Plus, being able to send/receive a random reply is almost never useful. This wasn't really supported by previous versions of Swagger. I understand some APIs do it, that doesn't mean we should have supported it. There are a few API paradigms out there that we don't support and don't intend to support. That said, this got in Swagger 2.0 and it is what it is. My main concern with adding support for Of course, I understand the need to tell users what a is or isn't a valid input/output, and it is indeed an important part of the documentation. What we can try doing is find those edge cases where we don't want to support |
I see what you mean. Totally agree that in general JSON schema validations can be pretty specific about constraints. Perhaps it might be worth considering a way to specify that a property is not valid instead of supporting the entire "not" feature. |
That's a possible alternative, sure. I'll mark it as a proposal for the next version of the spec, and let's give people a chance to give their input. |
Parent: #579. |
Tackling PR: #741 |
|
http://json-schema.org/latest/json-schema-validation.html#anchor91
The text was updated successfully, but these errors were encountered: