当前位置:网站首页>Kill the swagger UI. This artifact is better and more efficient!

Kill the swagger UI. This artifact is better and more efficient!

2022-06-11 15:57:00 JAVA Chinese community

Here's the thing : Today, the back end of our company said that he had finished writing the interface , And shared an interface document with me . It's used Swagger UI The interface document generated automatically , Like this :

a9b023d8dfb97b84910f4e68bf4455ad.png

such Swagger UI Every time I look at the document, my head grows bigger , Lots of problems

  • When viewing a multi-level model, you need to click open one level at a time

  • It is very difficult to use when the number of interfaces increases , There is not even a category menu

  • The submission parameters are JSON Cannot format when

  • It is troublesome to find out when the parameter is wrong

  • The returned results cannot be collapsed , Too long to see

Time is urgent , I will follow the parameters and response data in the document he gave , Written on my front page , After a simple self-test on the front end, it went online in a hurry .

It blew up the night after the launch ..

2c4f5425acc512eeaaa1073c9d783efe.gif

Various interfaces on the page report errors :

  • Parameter does not exist

  • Wrong parameter type

  • Interface does not exist ( Because the interface is written incorrectly )

The boss will come to us right away , But the front and the back have their own words :

  • front end : I'll hang you , How can you share so many errors in the interface ?

  • Back end : I'll hang you , You can't test whether the interface is normal before you use it ?

  • front end : Why should I test ? The interface you developed , Your own misfortune ?

  • Back end : How do I know what kind of data you want to use ! If you test the interface a little , There are so many things ?

71c5220135ab194bcac941f48145d802.png

In the final analysis, it is a question of cost

At this time, the boss is very calm , Stopped our quarrel .

791186ebfdcb0ade1dadaf44eb674d52.png

The boss analyzed the main cause of the accident :

  • 1、 The back end is sloppy , Some interfaces are not written correctly , Also forgot to debug

  • 2、 Time is tight , The front end did not have time to fully test the interface

Then the boss said , This is, in the final analysis, a cost problem . If The front and rear end test interfaces are particularly simple and convenient , Your problem will not exist !

The online interface documentation you use now , The function is almost zero . You should choose a more powerful online interface documentation tool , You can adjust the interface directly online , Would you not have these problems .

This tool should have the following functions :

  • Debugging function , The front end can easily debug interface data

  • Code generation function , In this way, the front end can write less code , Improve efficiency and accuracy

  • Interface synchronization function , The interface document must be the latest code information

We all nodded , Yeah, yeah .

8714def66e861b836fc9c328285124af.png

The eldest son said , I recently tried a tool , Can Zero cost To solve your problems !

Then he showed us a fairy document .

This is this. !!️️️

ce9ed7ae62cb39a57899c6d59f865381.png

Why is it called immortal ? Because it is full of the characteristics of being pushed to the limit by cattle , More than usual API The document doesn't know how high it is .

502c98cf4e487c996dd7ef936e6814dc.png

Online debugging

This document is written in Apifox It's done , I have tried this tool before , Completely free and unlimited , I didn't expect that so many powerful new functions have come out recently .

Click... In the upper right corner of the document function Button , Will appear “ The online operation ” Module

a2b3824b1650cead1fb7bf8a7d8af128.png

You can directly debug the interface on this interface ! direct 1. Fill in the parameters ,2. Select environment ,3. Point send , The interface request is sent out ! Here is the return result ! There is no need for Postman! Not to mention API Copy it again !

d72bcd51302e08047ae4f9a8de53f0b2.png

I thought. , If before the launch , It's using Apifox Words , There is simply no accident :

  • Parameter does not exist ? I got the data after online debugging , By comparison, I know which parameter does not exist

  • Wrong parameter type ? alike , After online commissioning , By comparison , I know which parameter has the wrong type

  • Interface does not exist ( Because the interface is written incorrectly )? When debugging, it will be reported that the interface does not exist , Find the back end at the first time ~

fb2c873c4ddf20b7f2b9f61a27287457.png

Automatic generation

I told the boss , This function looks very powerful . But if the online time is tight , Who has the time to get such an interface document , Configuration should be very troublesome ?

The eldest evil spirit smiled .

07e53824df1809b165c23f940e86265d.png

He said , This document , yes since ! dynamic ! raw ! become ! Of !

Just put Swagger Of URL Fill in Apifox Go inside ,Apifox It will automatically import API Definition , Then you can generate this useful document !

The back end changes the code randomly , The front end can be debugged online at any time !

41d8b3ff2a30a38110f6c535c62d914c.png

and , You can also import from multiple sources Swagger! A set of interface documents from different back-end projects is no problem !

038681c63a040b5ffe67c021178fa03a.png

Generate request code

The back end says , It is an online debugging interface , Not to the point of immortality .

The eldest son said , You're still too young .

e4429a5453d58c8189cf1747ebe05821.png

On this online documentation page , There is also a familiar line icon. What is this ?

c7943e9e6470ea4b2f833bca7fdf494b.png

since ! dynamic ! raw ! become ! generation ! code !

Click on the corresponding language , You can directly generate the requested code !???

I chose JavaScript after , It also provides Fetch、Axios、Jquery And so on ???

4598f0da3775f951683fe42e509fe11b.png

I'm directly copy Code , Stick it into the code and you can use it ???

An online document , Roll it up like this. As for ???

30dc4396b0805f88aeea2ec30e6279f9.png

Generate model code

The eldest son said , Don't worry. , It's not over yet. .

64ab1a26edb537c4472f1b49cc0e586a.png

API Documents , There will be one “ Return response ” Module , This is to tell you what type and length of data the backend spits out . The front end writes a data structure to connect these data , Then put it on the page .

In this immortal document ,“ Return response ” There's one in there, too “ The generated code ”.

e09f677975dbb925149f3f5bd5fe2d1d.png

I ordered , This box pops up :

a759ca2cb994502bfced017780096b9c.png

You can also select the configuration of your generated code on the left , Include : programing language 、 Naming style 、 Verification on wait .

I looked at ,Java,C,C++,JS,Swift,Go,Python,TypeScript…… Basically all the languages I know are .

What's going on ? There is no need to write the code to return the data structure ? Just copy it and paste it ?

I silently rummaged through the automatically generated code , Closed again .

I feel like I wrote it myself Java The code is not as well written as it is automatically generated .

7db79a51c66cec062111e29a8040e3d5.png

Cloud Mock

I said boss , Oh, I see . I'm going to download it now Apifox, I will use this online document for the next iteration . Oh no , In the next iteration, I will force the backend to use this online document .

The eldest son said , What's the hurry . When I finish . You know, Cloud Mock Do you ?

I said, , Cloud , All immortals want to ride the clouds , This is normal .

The boss said you should be normal . Cloud Mock, Is in the API It is directly implemented on the document page Mock service , A virtual server comes out .

I :???

8636ab2e2ab6a30a076a41a64e49bd43.png

The eldest son said , such as , We need to ask a bank for API, The bank certainly won't let you ask casually , The number of times to verify the identity limit . Use this Apifox Well , You can request directly on the interface document Mock Data. , It doesn't limit your number of times , I won't charge you any money .

I said boss , Are we jumping a little fast . I can't keep up with you .

The boss said no , We are talking about the features of this online document . You see , Here is the test environment 、 Formal environment and cloud Mock Environmental Science , You just switch to the cloud Mock Environmental Science , The request will be sent to Mock The server , It is the same as the formal environment debugging .

21c724f4516e4484ca09c1803c4d1a11.png

I :!!!!!

It can be like this ??

The boss opened this again with a browser URL(https://mock.apifox.cn/m1/1035644-0-default/users/2), Say you see , Direct access URL You can get Mock Data. , Does your front end work well ?

e2689999d2abdbd27b1aaeb262bcc75a.png

I nodded .

c1aeb5820fc7913a1165ccc84e37b843.png

This is the time , The back end says , Is it right that we directly put the commonly used third parties API All of them can be made into the cloud Mock Of API file , Then the development can directly debug the third-party interface ? even Mock Servers don't need shelves ?

I :

1e4c34f7d5d4d5cd7355148a7c532a8b.png

API Hub

The eldest son said , You guys ,too young too simple,sometimes naive.

Let me show you something .

4701277aff179b5184db508ef0800bf0.png

This , be called API Hub.

bdceb33ba06d723464c10b3b19d32067.png

stay Apifox Inside , These are the most commonly used third parties API It's all done ! Instant messaging , E-commerce , Check the express , Project management , All have ! Each one can The online operation The generated code ! You can also clone it into your own project , And then use Cloud Mock

ca70806e6b11394585fd78094dc2e33e.png
Enterprise wechat API file , It can run online

The eldest son said , People have made the interface documents public , You should also learn from the interface design of other manufacturers . oh , If our company has an interface to open , You can also publish to this API Hub.

d992206b240cbe2e29da569da3b7ca40.png

The eldest son said , Okay , I had said . Do you all understand ?

I said, , I see , Tomorrow, I will go to the back-end line .

e5455f6d98aebdf85ce318f362556d69.png

The back end says , Wait for what tomorrow ! I'm going to !

Apifox

Last , The boss said in earnest , Young people , We should learn more advanced technologies and tools .

Apifox = Postman + Swagger + Mock + JMeter. Set interface documentation tool 、 Interface Mock Tools 、 Interface automation testing tools 、 Interface debugging tools in one , promote 10 Times R & D efficiency .

7f98c4a311883b3a6e770f7b4873fea2.png

Beyond these core functions ,Apifox It also provides a lot of innovation around API Extended features of , It is suitable for development teams of all sizes .

c531678d685e79545a1a6ee7ccae0b5a.png

And I think they have an official notice , Later, more powerful document functions will be supported , Include Custom domain name 、 Custom navigation 、 Multi theme style selection 、 Customize css、 Custom page Etc., etc. , You should all pay attention to .

If there is a problem in the process of use , You can also join Apifox User group questioning and learning .

990816d8e06c3a446a05fabd62a33ab1.png

Click now “ Read the original ” Go download it

Download link :http://apifox.cn/a1jzwsq1

perhaps , Copy the link above , Go to the official website to download

7c12e090aa8d2fcb387544a6bd49c057.png
原网站

版权声明
本文为[JAVA Chinese community]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111541030122.html