I want to define a schema for a data structure that contains an array with values of different types:
{
"some_array": [
"string_value0",
"string_value1",
"string_value2",
{
"some_nested_array": [
{
"some_value0": "value0",
"some_value1": "value1",
"some_value2": "value2"
}
],
"some_value": "value"
}
]
}
I tried to do it this way, but all the generators I use don’t assume that some_array
can have values of different types:
components:
schemas:
SomeArraySchema:
type: object
properties:
some_array:
type: array
items:
oneOf:
- $ref: '#/components/schemas/PlainTextElement'
- $ref: '#/components/schemas/ComplextElement'
PlainTextElement:
type: string
ComplextElement:
type: object
properties:
some_nested_array:
type: array
items:
type: object
properties:
some_value0:
type: string
some_value1:
type: string
some_value2:
type: string
some_value:
type: string
For example, here is the error produced by code generated by OpenAPITools openapi-generator:
Expected BEGIN_OBJECT but was STRING at path $.some_array[0]
How to define some_array
properly to handle different types of its values?