I'm trying to describe the following post parameter in swagger:
"AnyOne" = [["971", 50.0, 70.0], ["832", 50.0, 30.0], ["134A", 50.0, 100.0]]
I'm trying to describe the following post parameter in swagger:
"AnyOne" = [["971", 50.0, 70.0], ["832", 50.0, 30.0], ["134A", 50.0, 100.0]]
Your nested array can be considered an array of tuples. Tuples are defined using prefixItems
. An array of tuples is defined as follows:
# openapi: 3.1.0
type: array
items:
type: array
prefixItems:
# The 1st item
- type: string
description: Description of the 1st item
example: "971"
# The 2nd item
- type: number
description: Description of the 2nd item
example: 50.0
# The 2nd item
- type: number
description: Description of the 3nd item
example: 70.0
# The total number of items in this tuple
minItems: 3
maxItems: 3
additionalItems: false # can be omitted if `maxItems` is specified
The inner array can be defined as a generic mixed-type array, i.e. "can contain strings and numbers". But you cannot specifically define that the 1st element is a string and the rest are numbers. This gives us:
type: array
items:
type: array
items:
oneOf:
- type: string
- type: number
example: ["971", 50.0, 70.0]
This version does not really support mixed-type arrays like ["971", 50.0, 70.0]
. The most you can do is to use a typeless schema {}
for the items
of the inner array, which means the inner array can contain any values except null
s. You cannot specify the exact types for items
, but you can add an example
of an array with different item types.
# swagger: '2.0'
type: array
items:
type: array
items: {}
example: ["971", 50.0, 70.0]