Springdoc-openapi is a library to automate the generation of OpenAPI documentation in Spring Boot projects.
It provides a set of annotations and configuration options to automatically generate an OpenAPI specification
Springdoc openapi works by examining an application at runtime to infer API semantics based on spring configurations, class structure and various annotations. Automatically generates documentation in JSON/YAML and HTML format APIs. This documentation can be completed by comments using swagger-api annotations.
Instalation
Add the following dependency to pom.xml
file
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.14</version>
</dependency>
This will automatically deploy swagger-ui to a spring-boot application
Documentation will be available in HTML format, using the official swagger-ui jars
The Swagger UI page will then be available at
http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs
Customize
In Java add following annotation in class containing main method
@OpenAPIDefinition(
info = @Info(
title = "XXXXX",
version = "0.0.1",
description = "API for XXXXX XXXXX XXXXX <br>XXXXX XXXXXXXXXXXXXXXXXXXXXXXXX..<br>.",
contact = @Contact(
name = "XXXXX XXXXX",
email = "XXXXX@XXXXXt.com"
)
)
)
Operations Documentation’s
Using library to document services. On top of methods adds annotation
@io.swagger.v3.oas.annotations.Operation(summary = "My summary ", description = "Service description ",
responses = {
@ApiResponse(responseCode = "200", description = "Describe results", content = @Content(schema = @Schema(implementation = List.class))),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = String.class)))
}
)
References
Spring web page Spring Doc Open Api
Esto es todo