springdoc-openapi java library helps to automate the generation of API documentation using spring boot projects. SpringBoot3.x version will not support the swagger. If we're working with springboot we need to use the OpenAPI docs.
To implement the OpenAPI docs in a Spring Boot application using Java code, we need to follow these steps:
Step 1: Add Dependencies In your `pom.xml` file add the necessary dependencies.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
To provide the description to the REST operation we need to Use the @Operation and @ApiResponses annotations.
@PostMapping("/create")
@Operation(
summary = "Registration",
description = "Register the customer using the input request object")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful operation")
})
public ResponseEntity<APIResponse> createCustomer(@RequestBody CustomerRequest request) {
return customerService.createCustomer(request);
}
Full source code is available in follwong GitHub repository: SpringBoot OpenApi Docs Example