Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Swagger, how do I define a parameter as a multidimensional array?

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.

like image 988
jtalarico Avatar asked Oct 20 '25 17:10

jtalarico


1 Answers

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": {}
  }
}
like image 141
Jason Desrosiers Avatar answered Oct 22 '25 05:10

Jason Desrosiers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!