Hello all,
Swagger is running well for our project currently. But since there are multiple methods, and they have very similar response codes and messages, we have to annotate each of them with the same set of @ApiResponse repetitively. The code is like:
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "XXXX", response = XXXX.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = MESSAGE_OK),
@ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = MESSAGE_INVALID_ID),
@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = MESSAGE_ACCESS_DENIED),
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = MESSAGE_NO_TOPIC) })
public XXX get(@ApiParam(value = "XXX id", required = true) @PathParam("id") final String id) {
...
}
@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "XXXX", response = XXX.class)
@ApiResponses(value = {
@ApiResponse(code = HttpURLConnection.HTTP_OK, message = MESSAGE_OK),
@ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = MESSAGE_INVALID_ID),
@ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = MESSAGE_ACCESS_DENIED),
@ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = MESSAGE_NO_TOPIC) })
public XXXX put(@ApiParam(value = "XXX id", required = true) @PathParam("id") String id, @ApiParam(value = "XXX object", required = true) @NotNull final XXXX xxxx) {
...
}
There is a way that we can have something like an annotations wrapper to bundle the duplicate annotations so that we do only one annotation for each method?
It could be like @ApiResponses(value = {@ApiResponseBundle()}).
Thank you!