Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Swagger enhanced artifact: what are the functions of Knife4j

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "Swagger enhancement artifact: what is the role of Knife4j", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "Swagger enhanced artifact: what are the functions of Knife4j"?

Wagger is one of the most commonly used frameworks in development, but Swagger itself has many imperfections, such as querying a certain interface among many interfaces, or exporting all interfaces to Word format, which can not be implemented in Swagger.

One might ask: why import the interface to Word format? This kind of scenario is quite common, for example, when the interface needs to be open to external companies, or the network of the development environment cannot be opened to the outside (for example, direct connect is pulled by many hospitals), and when the Swagger of the production environment is closed, you can only rely on offline documents to call the API, and the most commonly used format of offline documents is Word.

So in order to solve these problems of Swagger, we need to use an enhanced tool of Swagger, and this extension tool is the Knife4j that we are going to focus on today, so what does Knife4j look like? Let's look at it together, as shown in the following figure:

As can be seen from this home page, Knife4j will display the summary information (Docket) set in Swagger on the welcome page. The settings of Docket can be seen in my previous article, and Knife4j also provides a function to count all interfaces. At the bottom of the welcome page, we can clearly see the number of current POST interfaces and the number of GET interfaces.

PS:Knife4j supports both Chinese and English language presentation, which is very readable for domestic partners (because they are all in Chinese).

Introduction to Knife4j function

1. Search function

I think one of the most useful features of Knife4j is "interface search". Through this function, we can easily find the interfaces we need, as shown in the following figure:

two。 Offline document download

Knife4j provides offline document downloads in four formats: Markdown, Html, Word, OpenAPI, and so on, as shown below:

3. Interface filtering

You can filter certain types of interfaces through Knife4j, such as GET or POST interfaces, as shown in the following figure:

4. Global parameter setting

If there are common request parameters, we can easily fix them through Knife4j, as shown in the following figure:

5. More friendly interface debugging

Using Knife4j can be more friendly to implement interface debugging, because when using Knife4j, the required parameters are displayed with a red border, so we can visually distinguish between required parameters and non-required parameters, as shown in the following figure:

Knife4j usage configuration

From the above, we can see that the function of knife4j is very powerful, but I am even more surprised that its configuration is extremely simple. We only need to add the dependency of Swagger in the project that has successfully configured Knife4j. The configuration information is as follows:

Com.github.xiaoymin knife4j-spring-boot-starter 3.0.2

After the above simple dependency addition, we can successfully use Knife4j without configuring anything.

Visit Knife4j

We can access Knife4j's home page through http://localhost:8080/doc.html, as shown in the following figure:

At this point, I believe that you have a deeper understanding of the "Swagger enhanced artifact: what is the role of Knife4j", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report