Reputation: 581
@ApiOperation
has an attribute response
to which we can pass the Response type. In @ApiResponse
also we have an attribute response
to which we can pass the Response type. So What is the exact difference between them?
Upvotes: 9
Views: 26569
Reputation: 2843
You must specify the success response in @ApiOperation
while you can specify ALL possible response objects in @ApiResponse
.
@ApiResponse
is used wrapped inside @ApiResponses
and generally used to specify error codes and exceptional cases like Resource Not Found
or Bad Request
etc. You can also specify success
response, but it is not mandatory to do so, as the success response is anyway mentioned in @ApiOperation
.
Upvotes: 7
Reputation: 27048
The usage of @ApiOperation
and @ApiResponse
is a bit different. With @ApiOperation you can specify the return type of the REST method using response
. With @ApiResponse you can send back other information like HTTP code, user defined message and other headers if any you want to return
Upvotes: 0