How to document multiple data types array in OpenAPI Definition
Hi all,
I'm looking for an OpenAPI representation for an array type when the array has one specific data type item at one time, the array data type can be multiple types. That means as an example:
let's assume I have an array called `arry` with two data types integer and string, when I receive `arry`, It can be contained items only one type. It can be an integer array(arry[] -> [integer, integer, integer]) or string array (arry[]-> [string, string, string]).
If I use oneOf data model :
....
arry:
type: array
items:
oneOf:
- type: string
- type: integer
it will return the mixed type array arry[]->[integer, string, integer, integer, string]
Could you please let me know, how can I represent array arry[] -> [integer, integer, integer] or arry[]-> [string, string, string] in the OpenAPI definition?
You are almost there. Here's how to define a non-mixed array:
arry: oneOf: - type: array items: type: integer - type: array items: type: string
Depending on how well your tooling handles "oneOf", this can be simplified into:
arry: type: array oneOf: - items: type: integer - items: type: string