question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could array items contain an array of schemas?

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
philsturgeoncommented, Jan 9, 2020

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

2reactions
handrewscommented, Oct 23, 2019

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

array — Understanding JSON Schema 2020-12 documentation
Arrays are used for ordered elements. In JSON, each element in an array may be of a different type. Language-specific info: Python; Ruby....
Read more >
Schema is an array, the 'items' property must be defined
The schema in question is an array schema, but you have not defined the items property for it. Array schemas must have the...
Read more >
JSON Schema: array with exactly n elements of given sub ...
I'm trying to figure out how can I write a JSON Schema for an array which has to contain exactly 2 elements, where...
Read more >
Array type | Opis JSON Schema
An array is valid against this keyword, if the number of items it contains is greater than, or equal to, the value of...
Read more >
Arrays - JSON Schema
A JSON Schema for an array can be seen as set of restrictions that must apply on the elements of the array. In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found