Reputation: 71
I'm integrating dropwizard-swagger into a large existing project.
I've got the Swagger UI
endpoint up and running now, but I'm noticing that it seems adamant that every method must have a body parameter.
Specifically, the first parameter in the method definition that doesn't have an @ApiParam
annotation gets interpreted as a request body. There doesn't appear to be a way to specify a body parameter, nor does there seem to be a way to exclude parameters from being labelled as such automatically by Swagger UI
. This means that the "Try it Out" functionality doesn't work for a large portion of the endpoints, as bodies are disallowed by the spec but Swagger UI
keeps insisting they are present.
For example, consider the below method in the UserResource
file:
@GET
@Path("v1/users/{userId}/subscriptions")
@ApiOperation(value = "Get user subscriptions", notes = "Returns information about the users current and past subscriptions.")
@UserAccessRequired
@RolesAllowed({//a list of appropriate roles})
@Produces(CompanyMediaType.APPLICATION_API_V1_JSON)
public SubscriptionsDTOV1 getSubscriptionsForUser(@Auth DashboardUser dashboardUser, @JooqInject DSLContext database,
@Context ResourceContext resourceContext,
@Context ContainerRequestContext crc,
@ApiParam(value = "ID of user", type = "Integer") @NotNull @UnwrapValidatedValue @PathParam("userId") IntParam userId) {
Swagger is interpreting the first parameter, @Auth DashboardUser dashboardUser
, as being the request body, and generating the below view in Swagger UI
:
Swagger UI with a body parameter
Since this is a GET
, it's not permitted to have a body, and attempting to delete the contents of the body in the Swagger UI
while testing it out doesn't work, as the field autofills with {}
.
How do I indicate to Swagger
that there is no body parameter here and get this to work? Just putting @ApiParam
in front of the other method parameters doesn't work, as that annotation is ignored if there isn't also a @QueryParam
/@PathParam
/etc annotation present.
Upvotes: 2
Views: 868
Reputation: 71
Turns out adding @ApiParam(hidden=true) seems to have done the trick. I tried this before and didn't get results, must have just had a typo somewhere.
Upvotes: 2