In Swagger, I'm able to create a parameter that is an array of any type like this:
"MyType" : {
"description" : "my example object type",
"type" : "object",
"properties" : {
"id" : {
"description" : "identifier",
"type" : "number"
},
"data" : {
"description" : "data container",
"type" : "array",
"items" : {
"type" : "string"
}
}
}
}
Which defines an object that might look like this:
{
"id" : 1,
"data" : ["a", "b", "c"]
}
But what I need to do is define an object that might look like this:
{
"id" : 1,
"data" : [
[0, 1, 2],
["a", "b"],
[true, "foo", 99, false]
]
}
The data property needs to be a multidimensional array, and ideally it could contain any number of "rows", each with any number of columns containing any type of data in each field. I'd even settle for the schema allowing for data to just be an array of anything, but I can't figure out how to get that to work.
All you need to do is change the type of the items schema to be array. The following schema means "data" is an array, whose items are arrays. There are no constraints on the inner arrays.
"data" : {
"description" : "data container",
"type" : "array",
"items" : {
"type" : "array",
"items": {}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With