Knife4j
The predecessor is swagger-bootstrap-ui
a tool that empowers Swagger interface documents
Document : https://xiaoym.gitee.io/knife4j/
Effect (old version) : http://swagger-bootstrap-ui.xiaominfo.com/doc.html
Effect (version 2.X) : http://knife4j.xiaominfo.com/doc.html
Gitee:https://gitee.com/xiaoym/knife4j
GitHub:https://github.com/xiaoymin/swagger-bootstrap-ui
Example : https://gitee.com/xiaoym/swagger-bootstrap-ui-demo
Features & optimization
1. When constructing the response curl, remove part of the header header custom added by Knife4j
2. Increase the enhanced configuration of the custom homepage. Developers can provide a Markdown document to customize the content displayed on the Home homepage Gitee #I24ZXI
knife4j : enable : true setting : # Whether to customize the display of the Home homepage, the default is false enableHomeCustom : true # The markdown document path of the custom homepage Home can only be set 1, if it is set as a directory, the first homeCustomLocation is taken by default : classpath : markdown/home.md
3. The OpenAPI open interface can display Gitee #I25273 through enhanced configuration
knife4j : enable : true setting : # Whether to display the Open tab in the document, the default is true enableOpenApi : false
4. The search box can display Gitee #I24ZYY through enhanced configuration
knife4j : enable : true setting : # Whether to display the search box in the document, the default is true, which means enableSearch : false
5. Whether the footerkey at the bottom of the document is displayed through enhanced configuration, and the display content can be customized Gitee #I24ZYD
knife4j : enable : true setting : # Whether to not display the Knife4j default footer, the default is true (display) enableFooter : false # Whether to customize the Footer, the default is false (non-custom) enableFooterCustom : true # Customize Footer content, support Markdown Grammar footerCustomContent : Copyright by China XXX Technology Co., Ltd.
6. Abandon the control parameter interface in springfox, and control /swagger-resources/configuration/ui
whether to open Debug debugging through the personalized enhanced configuration provided by Knife4j
knife4j : enable : true setting : # Whether to display the debugging Tab frame, the default is true (display) enableDebug : false
7. Solve the problem of losing basePath under the microservice architecture Gitee #I23NWM、Gitee #I23N6L、Gitee #I25ZTC、GitHub #286
8. Markdown for custom documents and custom Home pages supports Html syntax Gitee #I24ZZA
9. Remove the upper right corner of the document? The document number shows Gitee #I24ZYL
10. The enhanced configuration adds the configuration Gitee #I24EBO that enables dynamic request parameter configuration
knife4j : enable : true setting : # Enable dynamic request parameter debugging, the default is false (not enabled) enableDynamicParameter : true
11. If the current service has only one group, the developer can enableGroup
control the group display Gitee #I25MQG through the configuration items , the configuration is as follows:
knife4j : enable : true setting : # Ui interface does not display grouping elements enableGroup : false
The final rendering is as follows:
12. The basic types of request parameters and response parameters example show optimized Gitee #I24YKT
13, @ApiOperationSupport
and @DynamicParameters
issue notes can not be used simultaneously Gitee # I24JWV
14. Solve the problem of starter conflict in V3 version Gitee #I2420J
15. Optimize the component way of markdown rendering.
16. Offline document export removes the export PDF item. The export pdf function can be easily realized whether it is based on markdown or word, so Knife4j discards this function
17. In the OpenAPI3 structure, the scheme analysis in the support form type is displayed as json Gitee #I24PCZ
18. For the interface with the Authorize logo, the icon of adding the lock is reflected in the interface Gitee #I23W0S
19. Enhanced configuration of local cache update strategy
20. After the document management menu item is disabled, the display of the personalized menu in the upper right corner is synchronously disabled. Gitee #I262VN
21. Request the OpenAPI specification instance interface to send a language
header by default . If the server has configured i18n, it can dynamically return different language interpretations based on this header.
21. Solve the problem of conflicts with the enhanced configuration of the server when setting the interface i18n based on the path. If the developer sets the i18n display of the interface through the url path, the path in the default will prevail, otherwise, take the back-end enhanced configurationlanguage
22. An abnormal problem is displayed when the menu is contracted Gitee #I2646F
23, OpenAPI3 specification adaptation supports JSR303 support GitHub #283
24. Optimize when the data type of the request parameter is empty, and display the default valuestring
Instructions
Knife4j
There are currently some different version changes for Java development and use , mainly as follows:
1. If developers continue to use the OpenAPI2 specification structure and the underlying framework depends on springfox 2.10.5 version, then Knife4j
the 2.x version that can be considered
< dependency > < groupId > com.github.xiaoymin </ groupId > < artifactId > knife4j-spring-boot-starter </ artifactId > <!--Please search for the latest version number of 2.X in the maven central warehouse when referencing-- > < version > 2.0.8 </ version > </ dependency >
2. If the developer uses the structure of OpenAPI3, the underlying framework depends on springfox3.0.0, Knife4j
the 3.x version that can be considered
< dependency > < groupId > com.github.xiaoymin </ groupId > < artifactId > knife4j-spring-boot-starter </ artifactId > <!--Please search the maven central warehouse for the latest version number of 3.X when referencing-- > < version > 3.0.2 </ version > </ dependency >
3. If the developer uses the springdoc-openapi
framework at the bottom of the framework, you need to use Knife4j
the corresponding version provided. It should be noted that Knife4j
the enhanced function that this version does not provide is a pure UI.
< dependency > < groupId > com.github.xiaoymin </ groupId > < artifactId > knife4j-springdoc-ui </ artifactId > <!--Please search for the latest version number of 3.X in the maven central warehouse when referencing --> < version > 3.0.2 </ version > </ dependency >
Knife4jAggregation microservice aggregation middleware
Since the beginning of the 2.0.8
version, Knife4j provides a lightweight middleware that aggregates OpenAPI documents for microservices, which can aggregate documents in any Spring Boot service, the simplest, lightest, and most convenient aggregation component
< dependency > < groupId > com.github.xiaoymin </ groupId > < artifactId > knife4j-aggregation-spring-boot-starter </ artifactId > <!--Please search for the latest version number of Knife4jAggregation in the maven central warehouse when referencing-- > < version > 2.0.8 </ version > </ dependency >
This component provides 4 different modes for the aggregation of OpenAPI documents in different languages and modes
Four different ways:
For more detailed introduction and actual use method, please refer to the document
Features
-
Based on the documents built by Vue+Ant Design, more powerful and clear interface documentation description capabilities and interface debugging capabilities
-
Left and right layout, multi-document lookup style based on Tabs component
-
Support online export of offline documents in various formats such as Html, Markdown, Word, PDF, etc.
-
Interface sorting, support grouping and interface sorting function
-
Support interface global online search function
-
Provide Swagger resource protection strategy to protect document security
-
Interface debugging supports unlimited parameters, developers are very flexible in debugging, adding and deleting parameters dynamically
-
Debugging information is cached globally, it still exists after the page is refreshed, which is convenient for developers to debug
-
Show Swagger Models functions with a more user-friendly table tree component
-
Documents can display multiple interface documents in multiple tabs
-
Request parameter column request type, whether it must be filled in with color
-
Roughly count the number of different types of interfaces in the homepage
-
Support custom global parameter function, homepage includes header and query two types
-
JSR-303 annotations support
-
More personalized settings
interface
The interface document display interface is as follows:
The interface debugging interface is as follows:
Swagger Models function
It supports the export of offline Markdown and Html functions. Compared with the original version, the markdown table is displayed as a tree structure through reduction. Click Preview to export the offline Html effect . The effect diagram is as follows:
The PDF effect exported by third-party Markdown software is as follows:
At the same time, it provides the function of exporting offline Html. The interface style of Html function is almost the same as that of online. It is beautiful, generous and concise. Click to preview the effect online ,
The interface effect is as follows:
Star & Issue
Thank you all for your support, go to https://gitee.com/xiaoym/knife4j to order a Star~~ :)