1

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

5
  • How do you generate your swagger documentation? Manually, or using a library such as swagger-core? Commented Dec 12, 2014 at 14:04
  • @webron, I am 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. Commented Dec 12, 2014 at 17:07
  • whats your api definition in java? Are you using @QueryParam for each input parameter in your api declaration? Commented Dec 12, 2014 at 17:15
  • To clarify, those are not maven plugins but rather dependencies. Answer coming up. Commented Dec 12, 2014 at 18:32
  • @Jack, yep, I'm currently using @QueryParam for each input parameter. Commented Dec 12, 2014 at 19:19

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Just to clarify, Swagger 2.0 is final. The support for it in swagger-core is not, but we're very close to a milestone release. One of the benefits of the library is that it is independent of the application, so the SNAPSHOT offers minimal risk, but it is understandable why your client may prefer not to use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.