-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Schema does not enforce requirement of array items object #174
Comments
That's correct. I'm not sure if it would be a good idea to fix it in the schema. The JSON Schema of JSON Schema (yes, that's confusing) is permissive on such things even though the schema being validated may not be meaningful in terms of the supposed restrictions. |
Having a lax schema kind of defeats the point of a schema at all. Not a big deal, I can work around it but I was surprised when this came up. |
Yes, which is why I'm surprised at JSON Schema's schema as well. As you know, there are a few validations that can't be covered by the schema anyways and have to be manually checked for. But yeah, I admit I'd prefer seeing as much restrictions in the schema as possible. I'll try mapping these things in the next few days and we'll see how we can improve it. Feel free to add here comments on similar issues you may encounter (I'll give you a hint, a "$ref" property can't exist alongside other properties). |
Well, this wasn't that big a deal in 1.2 as there are only a handful of places where |
I don't disagree which is why I'm glad you brought it up. Let's try to make
|
You got it. Any chance we can do like you do for body parameters and enforce the requirement? |
This is pseudo: "schema": {
"oneOf": [
{
"$ref": "#/definitions/arraySchema"
},
{
"$ref": "#/definitions/nonArraySchema"
}
]
} |
* This should eventually be handld by schema validation: OAI/OpenAPI-Specification#174 Fixes #62
It actually doesn't end there. Other validation properties may also be type-specific. For example, min/maxLength are only relevant to strings, multipleOf is only relevant to numbers and so on. I think the main idea is to mention in the schema what's require but not necessarily what's valid. For example, if you combine minLength with a numeric type, the effect is that the minLength is just ignored. This is different than the case than the one you originally mentioned where "items" is mandatory with type array. In any case, I'd like to spend some time going over possible use cases and decide which ones should be added. |
I wonder if we should treat a missing The only thing driving this right now is an inconsistency between the specification documentation and the JSON Schemas. What if we were to just remove this requirement from the Swagger specification documents and support it as discussed above? |
Wish we could, but really, at this point it seems a bit late for it. I'll do my best trying to enforce it in the schema, though if I recall correctly, it was hell (and possibly impossible). |
Well, it's moot now. If it's here, I'll continue doing what I'm doing. I'm just saying the lack of |
There are a few inconsistencies in the spec :-/ Just need to try and improve in the next version. |
Not sure if this is still an active concern. if anyone is still curious as to why JSON Schema works this way, it has to do with the difference between assertions, annotations, and data model keywords (which is discussed more clearly in the soon-to-be-published draft-07).
The third category, annotations, include keywords like Data model keywords themselves never cause validation to fail. They apply subschemas which have assertions, and it is the assertions in the subschemas which cause the pass or fail. This seems weird for use cases like OpenAPI. But consider using JSON Schema to scan arbitrary data for objectionable language with a regex. You don't know or care what data types you'll get. Objects, arrays, strings, numbers, booleans, nulls, nested structures of arbitrary complexity, etc. You just want to apply your regex using If FWIW, JSON Schema does in fact treat a lack of |
We decided not to fix this in the other issue since the schema is not intended to catch all errors, and this is against old OAS versions that aren't being worked on anymore anyway. I think this is safe to close. |
In the 1.2 and 2.0 specifications, it says this regarding the
items
property:Required if type is "array"
. The problem is I can create a property like this without the JSON schema validator throwing an error:The text was updated successfully, but these errors were encountered: