springdoc-openapi
is on Open Collective. If you ❤️ this project consider becoming
a sponsor.
IMPORTANT:
- For Spring Boot 2.x and 1.x.
springdoc-openapi v1.8.0
is the latest Open Source release supporting- springdoc-openapi v1
- Full documentation
- Introduction
- Getting Started
- Library for springdoc-openapi integration with spring-boot and swagger-ui
- Spring-boot with OpenAPI Demo applications.
- Integration of the library in a Spring Boot 3.x project without the swagger-ui:
- Error Handling for REST using @ControllerAdvice
- Adding API Information and Security documentation
- spring-webflux support with Annotated Controllers
- Acknowledgements
-
:= Java library /
- based on Spring Boot projects -- automate the generation of -- API documentation in format
- JSON/YAML
- HTML
- how does it work?
- infer API semantics -- based on -- examine an application at runtime
- Spring configurations
- ❌NOT ❌in placing OpenAPI specificaton in the classpath -- Example --
- class structure
- various annotations
- Spring configurations
- +
swagger-api
annotations
- infer API semantics -- based on -- examine an application at runtime
- based on Spring Boot projects -- automate the generation of -- API documentation in format
-
Supports:
- OpenAPI 3
- Spring-boot v3 (Java 17 & Jakarta EE 9)
- JSR-303, specifically for @NotNull, @Min, @Max, and @Size.
- Swagger-ui
- OAuth 2
- GraalVM native images
-
- introductory video
-
For spring-boot v3 support -> use springdoc-openapi v2
-
community-based project / NOT maintained by the Spring Framework Contributors (Pivotal)
- Swagger-ui
- -- is automatically deployed to -- a Spring Boot 3.x application
- page at "http://server:port/context-path/swagger-ui.html"
server
: server name or IPport
: server portcontext-path
: context path of the application
- Documentation -- using the official swagger-ui jars -- is available in
- HTML format
- .yaml at "http://server:port/context-path/v3/api-docs.yaml"
- OpenAPI description (.json) at "http://server:port/context-path/v3/api-docs"
- How to set up?
- Add the
springdoc-openapi-ui
library to the list of your project dependencies<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>last-release-version</version> </dependency>
- if you want to customize the path of the swagger documentation in HTML format -> , add in your spring-boot configuration file
# swagger-ui custom path springdoc.swagger-ui.path=/swagger-ui.html
- Add the
- Source Code for Demo Applications.
- Demo Spring Boot 3 Web MVC with OpenAPI 3.
- Demo Spring Boot 3 WebFlux with OpenAPI 3.
- Demo Spring Boot 3 WebFlux with Functional endpoints OpenAPI 3.
- Demo Spring Boot 3 and Spring Cloud Function Web MVC.
- Demo Spring Boot 3 and Spring Cloud Function WebFlux.
- Demo Spring Boot 3 and Spring Cloud Gateway.
- Documentation
- at json format: "http://server:port/context-path/v3/api-docs"
server
: The server name or IPport
: The server portcontext-path
: The context path of the application
- at yaml format: "http://server:port/context-path/v3/api-docs.yaml"
- at json format: "http://server:port/context-path/v3/api-docs"
- How to set up?
- add to your project dependencies
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-api</artifactId> <version>last-release-version</version> </dependency>
- if you want to customize the path of the OpenAPI documentation in Json format -> add in your spring-boot configuration file
# /api-docs endpoint custom path springdoc.api-docs.path=/api-docs
- if you want to disable
springdoc-openapi
endpoints -> add in yourspring-boot
configuration file:# disable api-docs springdoc.api-docs.enabled=false
- add to your project dependencies
- Requirements to generate the documentation
- 👁️ ALL the methods must declare the HTTP Code responses -- via --
@ResponseStatus
👁️
- 👁️ ALL the methods must declare the HTTP Code responses -- via --
- Declare within a 👁️ Spring managed bean 👁️,
- the annotations
@OpenAPIDefinition
@SecurityScheme
- Reason: 🧠 scan the spring-boot application auto-configured packages, looking for beans 🧠
- OpenAPIDefinition
- Info
- the annotations
- Documentation available in
- yaml format at "http://server:port/context-path/v3/api-docs.yaml"
- How to set up?
- add the library
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webflux-ui</artifactId> <version>last-release-version</version> </dependency>
- if you want to customize path of the swagger documentation in HTML format -> add in your spring-boot configuration file
# swagger-ui custom path springdoc.swagger-ui.path=/swagger-ui.html
- add the library