Could array items contain an array of schemas?
See original GitHub issueI’m having difficulty understanding why in a requestBody one cannot specify the elements of an array explicitly. One can only have a general schema that applies to all items.
As it states in the latest OpenApi Spec:
items - Value MUST be an object and not an array. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. items MUST be present if the type is array.
But in json schema it states:
The value of “items” MUST be either a valid JSON Schema or an array of valid JSON Schemas.
My particular API REALLY needs to have request bodies that contain arrays with specifically ordered and typed elements, but with the current definition this is not allowed. I’m having a hard time understanding why the specification should disallow the definition of any particular JSON structure.
My schema definition currently breaks all the tools, so I’ve worked around it by defining my schemas as empty like so:
type: array
items: {}
and then I provide the details of how it should really be structured in the examples section.
So, as the title says, I’d like to know why it was chosen to not allow this. I’d also like to know if anyone would be open to the idea of getting rid of the “and not an array” requirement? I know this likely has a variety of implications, but let’s talk about them 😀.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
This was fixed in #1977 so we can close this.
@mariotoffia PR #1977 updates the forthcoming OpenAPI Specification 3.1 to use JSON Schema draft
2019-09
, which includes the tuple form ofitems
. So OAS 3.1 will solve this, but it’s not available as part of OAS 3.0 or earlier.