I use swagger to create a RESTful API, and have several endpoints which return the same errors and responses:
@GET
@Path("/some/endpoint")
@ApiOperation(
value = "Some method",
notes = "Some method")
@ApiResponses(
value = {
@ApiResponse(code = 200, message = RestConstants.HTTP_200, response = Response.class),
@ApiResponse(code = 400, message = RestConstants.HTTP_400, response = Error.class),
@ApiResponse(code = 401, message = RestConstants.HTTP_401, response = Error.class),
@ApiResponse(code = 403, message = RestConstants.HTTP_403, response = Error.class),
@ApiResponse(code = 404, message = RestConstants.HTTP_404, response = Error.class),
@ApiResponse(code = 500, message = RestConstants.HTTP_500, response = Error.class)
})
public Response someMethod(){...}
The amount of @ApiResonses is may about to change. As of now, I need to declare all of theses for my individual endpoint methods. Is there a way to use a constant value as an @ApiResponses value, e.g. like:
@ApiResponses(value = MY_RESPONSES)
Am I missing something?
This unfortunately isn't possible using the Swagger annotations.
For this to work ApiResponse
would have to be a normal class/interface rather than an annotation.