This is the 19th day of my participation in the August Wenwen Challenge.More challenges in August

WangScaler: A writer with heart.

Declaration: uneducated, if there is a mistake, kindly correct.

Swagger is an interface document that can be used in both Java and Python development. It greatly reduces the workload of back-end programmers and reduces the amount of back-end bickering. To give you and me more peace, hahahahahaha.

The name of Swagger in Tornado is Swagger_tornado, which is not automatically generated in Java and requires us to write by ourselves. However, it is better to write the document while training the code than to write the development document separately. Tornado framework is very strong, but the number of users is not as big as Django and Flask, so there is a huge difference, which leads to the small number of Tornado wheels.

Swagger document tag,

The tag of the Swagger document is expanded by default, as shown in the second User expansion state below. But as we develop more and more interfaces, the front end will go crazy when it comes to looking for one. So you need to change the default expanded state to closed.So how do we get it into the first Data state? So the first thing I’m going to do is I’m going to say can I configure it in the code.

I went through the official documents first, and there wasn’t. Then looked at the source code and the experience of online predecessors, may really have no. If you do, let me know. How on earth can you solve the problem?

1. Modify the access address bar

Add? After the access address. DocExpansion = none, such as our original url is www.scalerwang.com/api/doc, so easily solve now address is www.scalerwang.com/api/doc?docExpansion=none. However, the user needs to splice, although feasible, but not the best solution, can be permanently modified by changing the source code.

2, modify the source code

Our Python dependencies are all installed through PIP, so find the location of python3’s virtual environment package. If this is the default python3 environment, not a virtual environment, modify files in/usr/local/python3 / lib/python3.7 / site – packages/tornado_swagger swagger_ui/UI HTML

Open the file and add to the file

docExpansion=none
Copy the code

It’s as simple as that.

Of course docExpansion has other parameters as well.

The other parameters

  • DocExpansion = None does not expand.
  • DocExpansion =list is expansion.
  • DocExpansion =full expands completely, including interface details.

Write in the last

Tornao if you know of other useful tools, you can recommend them to me in the comments section.

Come all come, click “like” and then go!

Follow WangScaler and wish you a promotion, a raise and no bucket!