Knife4j integrates enhanced OpenAPI 2 and 3 API documentation into Java MVC and Spring Boot applications. It adds a richer doc UI, starters, and optional aggregation for microservices.
Overview
Knife4j is an enhancement layer for projects that already use Swagger or OpenAPI on Java web stacks. It grew from swagger-bootstrap-ui and separates backend integration from the documentation front end so teams can use it more flexibly in microservice layouts.
It supports OpenAPI 2.0 and 3.0 and works with Spring MVC, Spring Boot across several 2.x and 3.x lines, and Spring WebFlux. Starters hook into Springfox for Swagger 2 and springdoc-openapi for OAS3. The doc UI adds custom docs, dynamic parameter try-out, internationalization, interface ordering, and export options.
Published API docs are served at a stable doc.html address. Optional components include aggregation middleware for servlet stacks and Spring Cloud Gateway, a desktop aggregation tool, and documented Docker and Kubernetes approaches for combining OpenAPI from multiple services.
Teams add a Maven dependency and Swagger configuration, define controllers with annotations, start the app, and open the Knife4j URL in a browser to browse and exercise REST endpoints.
Key features
- OpenAPI 2 and 3 support
- Enhanced interactive API doc UI
- Spring Boot auto-configuration starters
- Springfox and springdoc integration
- Spring MVC and WebFlux compatibility
- Gateway OpenAPI aggregation options
- Custom docs and dynamic debugging
- Kubernetes and Docker aggregation docs
Use cases
- Spring Boot REST API documentation
- Microservice OpenAPI aggregation
- Trying endpoints from the browser
- Java team OpenAPI 3 adoption