How do you format array parameters for a POST request in Swagger UI's "Try it out" feature?

13,398 views
Skip to first unread message

Paul Leader

unread,
Oct 29, 2013, 11:02:16 AM10/29/13
to swagger-sw...@googlegroups.com
I'm quite new to Swagger, so it's entirely probably I'm missing something obvious, but I've read the documentation and I can't see anything obvious.

Is it possible to supply an array to a parameter? If so, what format should it be in?

I have an API that accepts an array for one of the parameters to a POST request. In the Swagger UI, is there a way to supply an array of items to this parameter when trying out the method? I've tried the obvious like "[1, 2, 3]" but with no success.

The API works just fine, so I'm pretty sure it's something I'm doing wrong with Swagger.

If it isn't currently a feature I will look at adding it. Swagger is really nice, and very useful, so I'd like to get involved in making it better.

Paul

tony tam

unread,
Nov 4, 2013, 1:15:54 PM11/4/13
to swagger-sw...@googlegroups.com
Hi, if you're sending JSON in a POST operation, you would simply define the input as follows:

"type": "array",
"items": {
   "$ref": "User"
}

If the input is an array of User objects.  If it's a primitive:

"type": "array",
"items": {
   "type": "integer",
   "format": "int64"
}

For example

A Euphemism

unread,
Mar 18, 2014, 8:24:01 PM3/18/14
to swagger-sw...@googlegroups.com
An example is at http://petstore.swagger.wordnik.com/#!/pet/findPetsByTags

There it's done by comma separating the values. But the data type in that example is 'string' - in my api it's array[string]. In the example, the backend code is obviously splitting the string into separate params. But how to pass values when the type is array?

Seems that @valdemon is onto it with https://github.com/wordnik/swagger-js/pull/83/files

Brad

tony tam

unread,
Mar 18, 2014, 9:22:20 PM3/18/14
to swagger-sw...@googlegroups.com
Please take a look at the petstore example:


Note the post INPUT accepts an array of JSON objects.

A Euphemism

unread,
Mar 19, 2014, 12:31:15 AM3/19/14
to swagger-sw...@googlegroups.com
Sorry, my mistake in reading this thread. I was looking at GET query parameter arrays, eg name=fred&name=jane&name=bob, which I don't see supported outside of the aforementioned github change

Shraddha Shah

unread,
Sep 19, 2014, 7:16:34 AM9/19/14
to swagger-sw...@googlegroups.com
Hey,
I am using JAVA, Jaxrs, apachewink and swagger for the UI documentation. My API is same as
http://petstore.swagger.wordnik.com/#!/user/createUsersWithArrayInput

On the swagger page, I want to show the array of object as the DataType just as the above API. I have used the @ApiModel,a @ApiModelProperty annotations. But the swagger page does not show this array of object in the DataType  column. I donot get the Model and Model Schema sections under it.

The same code works, if I replace the array of object with just 1 object.

Please could you suggest what I am missing here, any  annotations that say that this is an array of objects to the swagger UI?

Ron

unread,
Sep 19, 2014, 8:28:42 AM9/19/14
to swagger-sw...@googlegroups.com
Can you share a code snippet of what works and what doesn't work?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shraddha

unread,
Sep 19, 2014, 8:41:54 AM9/19/14
to swagger-sw...@googlegroups.com

Does not show Dthe Model, Modle Schema in Data Type column of the swagger UI
    public Response applypatches( @ApiParam(value="xxxxxx") ApplyPatchRequest[] patchRequest) throws UnknownHostException {
               
Shows the Model, Model Schema in Data Type column of the swagger UI
public Response applypatches( @ApiParam(value="xxxxxx") ApplyPatchRequest patchRequest) throws UnknownHostException {

ApplyPatchRequest is the class that has the @ApiModel and @@ApiModelProperty annotations
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Sep 19, 2014, 12:48:22 PM9/19/14
to swagger-sw...@googlegroups.com
Are you sure about that?
The "Model" section indeed doesn't show that it is an array, but the "Model Schema" wraps it inside an array.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Shraddha

unread,
Sep 22, 2014, 2:24:15 AM9/22/14
to swagger-sw...@googlegroups.com
Yes, for array, I don't see the Model and the Model Schema.

Ron

unread,
Sep 22, 2014, 6:04:24 AM9/22/14
to swagger-sw...@googlegroups.com
Can you share a screenshot? And possibly your swagger json?

On 22 September 2014 09:24, Shraddha <shrad...@gmail.com> wrote:
Yes, for array, I don't see the Model and the Model Schema.

--
Reply all
Reply to author
Forward
0 new messages