4

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.

1 Answer 1

9

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": {} } } 
Sign up to request clarification or add additional context in comments.

3 Comments

When I do that, the Swagger editor kicks back an error: "Missing required property: items"
I hate that Swagger claims to use JSON Schema, but then doesn't implement it properly. If Swagger requires items, you can set it as an empty schema. I'll update the answer to reflect that.
@Jason please look at this problem related to same stackoverflow.com/questions/38739750/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.