swagger not showing parameter annotated with @Context

1,909 views
Skip to first unread message

prateek sharma

unread,
Jul 30, 2013, 12:34:59 PM7/30/13
to swagger-sw...@googlegroups.com
I am using swagger-2.9.1_1.2.5 to document my rest API. I have one rest call which is as follows

    @GET
    @Path("/")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Get user",
                    responseClass = "com.thed.rpc.bean.RemoteUser")
    @ApiErrors(value = { @ApiError(code = 400, reason = "Invalid criteria supplied"),
                            @ApiError(code = 404, reason = "User not found with provided criteria") })
    public Response getUsersByCriteria(
            @ApiParam(value = "Token fetched from cookie", required = false)  @CookieParam("token") Cookie tokenFromCookie,
            @ApiParam(value = "Query params passed in URL.", allowMultiple = true, allowableValues = "id, name, startdate, enddate, status", required = false)
            @Context UriInfo uriInfo) {..........}

So my rest API are supposed to fetch query parameters from the URI and process accordingly.

Now when I give the URL

http://localhost:8002/api/api-docs/users

I get only one parameter i.e. token but not UriInfo. Is it intentional that parameters annotated with @Context annotation are not supposed to be taken as a parameter in swagger UI? If yes then how can I pass query parameter using swagger UI?

Thanks,
Pratz

tony tam

unread,
Jul 30, 2013, 1:52:16 PM7/30/13
to swagger-sw...@googlegroups.com
Hi, there are two parts to this question.

First, the @Context is not parsed automatically by swagger.  If you upgrade to 1.3.0-RC2 of the swagger-core code, you can write your own reader and add that parsing capability directly into the system similar to this:


The advantage of doing that is that your spec will remain in sync with the server code.

The other solution is to remove the @ApiParam annotations on that field and add an @ApiParamImplicit as such:

@ApiParamsImplicit({ @ApiParamImplicit(value = "Query params passed into URL.", dataType = "string", paramType = "header") })

This param is not "bound" to the operation but will add the query into the swagger definition.

Note the above example is if you're using 1.2.x.  If you're using 1.3.x it's slightly different.

prateek sharma

unread,
Jul 31, 2013, 5:19:45 AM7/31/13
to swagger-sw...@googlegroups.com
gr8... I tried ApiParamsImplicit and it worked but with some changes required to my REST api. Earlier my query params were in the form of
?id=1&name=user1&address=earth

now I need to change it to
?criteria=id:1,name:user1,address:earth

I am thinking of upgrading swagger to 1.3.

Thanks,
Prateek


--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/n7f2POj6HkI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages