@ApiParam multiple values for a single @QueryParam Object

2,787 views
Skip to first unread message

Parth Vyas

unread,
Jan 13, 2015, 5:52:40 PM1/13/15
to swagger-sw...@googlegroups.com
Hello,

Is there a way that I can have multiple values displayed with @ApiParam if my @QueryParam is an object and has many fields withing itself.

For Example, if I had an POJO Pet with the fields age, name, breed; And I had a @GET request with the following parameters:

public Response getPetResponse(@ApiParam("Pet") @QueryParam("") Pet pet)

Can I make changes within the Model to generate multiple query parameters, one for age, name and breed so that the URL looks something like this after hitting try out:

http://example.com/api/api-docs/pet?age=12&name=Max&breed=Retriever

Thanks


tony tam

unread,
Jan 13, 2015, 7:04:59 PM1/13/15
to swagger-sw...@googlegroups.com
Not really, neither swagger-ui nor the swagger-specificaiton allow for complex objects to live in query, path, header, or cookie params.  They need to be "primitive" types (in json-schema v4).  If you want to send an object to your server, you can deconstruct the fields into separate query params or send the payload as a POST.

Parth Vyas

unread,
Jan 21, 2015, 2:13:40 PM1/21/15
to swagger-sw...@googlegroups.com
Hey Tony,

Sorry for the late response, but I cannot make changes to the service method. I believe I cannot annotate @ApiParam over each field within my Pet class as well right?

Can I have multiple @ApiParam's for one @QueryParam which annotates each of the fields, for example

public Response getPetResponse(@ApiParam("Pet.name") @ApiParam("Pet.age") @ApiParam("Pet.breed") @QueryParam("") Pet pet)

If none of these work, should I raise a ticket? This is a major road block in my push to production.

Thanks.

Ron Ratovsky

unread,
Jan 21, 2015, 2:35:48 PM1/21/15
to swagger-sw...@googlegroups.com
What Tony said is that it is literally impossible by design to describe complex models for anything other than body parameters (or responses).
Swagger just doesn't support it. It's not lack of implementation, so opening a ticket won't help.

--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Parth Vyas

unread,
Jan 23, 2015, 7:42:37 PM1/23/15
to swagger-sw...@googlegroups.com
Is there any way that I can make changes within swagger's configuration so that I can manually add these complex models? Otherwise do you have any other suggestion's or workarounds for this issue?
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Jan 24, 2015, 5:15:08 AM1/24/15
to swagger-sw...@googlegroups.com
This is not a matter of configuration, but an intentional restriction by the spec.

The reason for it is that the content type of the HTTP request affects only the payload (by definition).

Say you have a complex model as a query parameter, how would it be presented? JSON? XML? CSV? A Base64 representation of a binary Java object? You simply can't tell the end user how to represent it (again, within the restrictions of the HTTP protocol, one which REST APIs rely). This is the same for header and path parameters.

If you want to use Swagger to document your API, the only workaround is to change the API such that the object fields are sent as individual query parameters or the object as a whole as a body parameter.

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.
Reply all
Reply to author
Forward
0 new messages