Skip to content
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

Could array items contain an array of schemas? #1869

Closed
adjenks opened this issue Mar 19, 2019 · 5 comments
Closed

Could array items contain an array of schemas? #1869

adjenks opened this issue Mar 19, 2019 · 5 comments

Comments

@adjenks
Copy link

adjenks commented Mar 19, 2019

I'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 😀.

@adjenks adjenks changed the title Why can't array items contain an array of schemas? Could array items contain an array of schemas? Mar 19, 2019
@handrews
Copy link
Member

@adjenks see #1532 for one possible way forward on this and other JSON Schema compatibility issues.

@adjenks
Copy link
Author

adjenks commented Mar 20, 2019

@handrews Thank you for pointing me to one of the possible future solutions. It does look interesting, with support for other types of schema definitions. It is good to keep things decoupled. In the meantime I'll just work around it.

@mariotoffia
Copy link

@handrews, @analogue Hi I've got the same problem. Actually ordering of my objects is not specific but the kind of objects are. Did you solve it? If so, can you please share that?

For example i need different named objects to contain different properties, e.g.:

[
 { "n" : "fanspeed", "maxSpeed" : 999, "stepping" : 10, "ot" : "Fan" },
 { "n" : "aqi", "good" : 44, "poor" : 124, "hazardous" : 150, "ot" : "PM" }
]

Where the ot = Fan and PM ar completely different schema objects.

Cheers,
Mario

@handrews
Copy link
Member

@mariotoffia PR #1977 updates the forthcoming OpenAPI Specification 3.1 to use JSON Schema draft 2019-09, which includes the tuple form of items. So OAS 3.1 will solve this, but it's not available as part of OAS 3.0 or earlier.

@philsturgeon
Copy link
Contributor

This was fixed in #1977 so we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants