[IntelliJ IDEA] springdoc-openapi automatically generates OpenAPI (Swagger) documentation in JSON/YAML and HTML format APIs in Spring Boot
springdoc-openapi
springdoc-openapi java library helps automating the generation of API documentation using spring boot projects. springdoc-openapi works by examining an application at runtime to infer API semantics based on spring configurations, class structure and various annotations.
Swagger is a simplify API development for users, teams, and enterprises with the Swagger open source and professional toolset. Find out how Swagger can help you design and document your APIs at scale API Documentation & Design Tools for Teams | Swagger - https://swagger.io/tools/.
Features
springdoc-openapi automatically generates documentation in JSON/YAML and HTML format APIs. This documentation can be completed by comments using swagger-api annotations.
This library supports:
-
OpenAPI 3
-
Spring-boot (v1 and v2)
-
JSR-303, specifically for @NotNull, @Min, @Max, and @Size.
-
Swagger-ui
-
OAuth 2
-
GraalVM native images
Gradle
Create or update gradle.files/springdoc-openapi-ui.gradle
file.
1 | // gradle.files/springdoc-openapi-ui.gradle |
Apply gradle.files/springdoc-openapi-ui.gradle
file in bundle.gradle
file.
1 | // bundle.gradle |
Maven
1 | <!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui --> |
Getting Started
This will automatically deploy swagger-ui to a spring-boot application:
-
Documentation will be available in HTML format, using the official swagger-ui jars - https://github.com/swagger-api/swagger-ui.
-
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
For custom path of the swagger documentation in HTML format, add a custom springdoc property, in your spring-boot configuration file: .
1 | # src/main/resources/application.properties |
For custom path of the OpenAPI documentation in Json format, add a custom springdoc property, in your spring-boot configuration file:
1 | # src/main/resources/application.properties |
-
server: The server name or IP
-
port: The server port
-
context-path: The context path of the application
Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml
Advance
Spring security support
For a project that uses spring-security, you should add the following dependency, together with the springdoc-openapi-ui dependency: This dependency helps ignoring @AuthenticationPrincipal in case its used on REST Controllers.
Gradle
1 | dependencies { |
Maven
1 | <!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-security --> |
Disabling the springdoc-openapi endpoints
In order to disable the springdoc-openapi endpoint (/v3/api-docs
by default) use the following property:
1 | # src/main/resources/application.properties |
Disabling the swagger-ui
In order to disable the swagger-ui, use the following property:
1 | # src/main/resources/application.properties |
References
[2] OpenAPI 3 Library for spring-boot - https://springdoc.org/
[5] Springdoc-openapi Properties - https://springdoc.org/#properties
[7] API Documentation & Design Tools for Teams | Swagger - https://swagger.io/