Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ApiOperation vs @ApiResponse in Swagger

@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?

like image 251
Virat Avatar asked Apr 11 '17 13:04

Virat


People also ask

What is use of @ApiOperation annotation in spring boot?

@ApiOperation- This annotation is used to describe the exposed REST API. It describes an operation or typically a HTTP method against a specific path.

What is the use of @ApiResponse?

Annotation Type ApiResponse. Describes a possible response of an operation. This can be used to describe possible success and error codes from your REST API call.


Video Answer


1 Answers

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.

like image 130
gaganbm Avatar answered Oct 07 '22 06:10

gaganbm