@ApiOperation is a Swagger 1.x/2.x annotation (io.swagger.annotations.ApiOperation) that describes a single REST endpoint in the generated API documentation: its summary, longer notes, response type and tags. It was used mostly with Springfox. For new Spring Boot 3 projects it is obsolete, and the replacement is @Operation from OpenAPI 3 (io.swagger.v3.oas.annotations.Operation), used with springdoc-openapi.
If you maintain an older codebase you will still see @ApiOperation, so it helps to know what it does and how to migrate.
In Swagger 2 documentation, a controller method is an operation. @ApiOperation adds human-readable metadata to that operation, which tools such as Swagger UI display next to the endpoint.
This code compiles against the legacy swagger-annotations library and was typically processed by Springfox (springfox-swagger2).
| Attribute | Purpose |
|---|---|
value | Short summary shown in the operation list |
notes | Longer description of behaviour |
tags | Group the operation under one or more tags |
response | Class of the success response body |
responseContainer | Wrapper such as List or Set |
httpMethod | Overrides the HTTP method inferred from the mapping |
produces / consumes | Media types of the operation |
hidden | Hides the operation from the documentation |
authorizations | Security requirements |
Response codes were described separately with @ApiResponses and @ApiResponse, and parameters with @ApiParam.
io.swagger.v3.oas.annotations.@ApiOperation in Spring projects, is no longer actively maintained and does not support Spring Boot 3. Projects moving to Spring Boot 3 must switch.Add the starter (for Spring Boot 3, use the springdoc-openapi-starter-webmvc-ui artifact):
Check the springdoc documentation for the version that matches your Spring Boot release. With that dependency the API docs are served at /v3/api-docs and Swagger UI at /swagger-ui.html, with no extra configuration. Now annotate the endpoint:
| Swagger 2 | OpenAPI 3 |
|---|---|
@Api(tags = ...) | @Tag(name = ...) |
@ApiOperation(value = ...) | @Operation(summary = ...) |
@ApiOperation(notes = ...) | @Operation(description = ...) |
@ApiResponse(code = 404, message = ...) | @ApiResponse(responseCode = "404", description = ...) |
@ApiParam | @Parameter |
@ApiModel / @ApiModelProperty | @Schema |
@ApiIgnore | @Hidden |
Remember that responseCode is a string and that the response attribute is replaced by a content and schema structure only when you need to override what springdoc infers from the return type.
It belongs to the old Swagger 1.5 annotation set and is not part of OpenAPI 3. Use @Operation in new code.
Springfox does not support Spring Boot 3, so the annotations will not be processed there. Migrate to springdoc-openapi and @Operation.
No. springdoc documents endpoints automatically. Annotations only add summaries, descriptions and extra detail.
value is the short summary and notes is the longer explanation. In OpenAPI 3 they map to summary and description.
@ApiOperation described one REST operation in Swagger 2 and Springfox projects. Today the maintained route is springdoc-openapi with @Operation, @Tag, @ApiResponse and @Parameter, which also works with Spring Boot 3.