I am generating swagger docs for my REST API. The generated docs show the params are required. How to make them not-required in swagger ? In actual REST invocations they are not-required (as expected); so problem is just in documentation.
import javax.ws.rs.*;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getBaz(
@DefaultValue("false") @QueryParam("foo") final boolean myFoo,
@DefaultValue("") @QueryParam("bar") final String myBar
) { ... }
The generated swagger.json has
... "parameters":[{ ... snip "myBar":"bar","required":true}
The
@ApiParam
annotation will do the trick. From the Swagger documentation:According to the javadoc, you can use
required
to specify if the parameter is required or not. To use it, do as following:Check the javadoc for more details.