Reputation: 359
How to set swagger-ui to properly encode a list of parameters properly? Eg: I have a service that receives a list of integers in the following format:
http://server/api/resource?id=1&id=2&id=3
However, in my swagger-ui documentation, the parameter is displayed as a single text-field, which expects a comma-separated list. If I provide the parameters on such format, I get the following response from service(which is written using RestEasy, btw):
Unable to extract parameter from http request: javax.ws.rs.QueryParam(\"id\") value is '1,2,3' for public javax.ws.rs.core.Response companyname.methodname(java.util.List)"
The swagger spec is being generated using a set of maven plugins: swagger-jersey-jaxrs, swagger-annotations, swagger-core and swagger-jaxrs. The main swagger spec json is being generated at application startup, through com.wordnik.swagger.jaxrs.config.BeanConfig, injected at my spring context.
I am clearly stucked at this point. If someone could provide any thought, I would really appreciate that.
Thanks in advance! Vinicius
Upvotes: 1
Views: 3924
Reputation: 14830
The support for repeating query parameter names is not well defined and implemented using Swagger 1.2 and the corresponding swagger-ui.
To properly support it, you need to move to Swagger 2.0 and the latest version of swagger-ui (current master).
The Swagger-Core support for Swagger 2.0 is currently under development but is close to a milestone release. You can get the SNAPSHOT from sonatype or build it yourself from the develop_2.0 branch of the github repository. The version of swagger-core that supports Swagger 2.0 is 1.5.
The support for it is done via the collectionFormat
property, with the value of multi
.
Upvotes: 2