Swagger is a very popular API document generation tool, I believe many guys use it! If you use it too much, you might find it ugly and weak. Today, I would like to recommend Torna, which can be used with Swagger to build a beautiful interface and powerful API document website. I hope it will be helpful to you!

Torna profile

Torna is an enterprise-class interface documentation solution that works with Swagger. It has the following functions:

  • Document management: support interface document adding, deleting, modifying and searching, interface debugging, dictionary management and import and export functions;
  • Permission management: Supports the permission management of interface documents, including visitors, developers, and administrators.
  • Dual mode: original dual mode,Management modeCan be used to edit the contents of a document,Browse modePure document access, no other interface elements.

Torna Project architecture

Torna is a front end separation project, the back end using SpringBoot+MyBatis to achieve, the front end using Vue+ElementUI to achieve, technology stack is very mainstream! Not only can it build API documentation sites, but it’s also a great learning project. Let’s take a look at its project architecture first.

  • First we need to download the source of Torna at gitee.com/durcframewo…

  • After downloading successfully, import the code into IDEA, and the project structure is as follows;

PS: Thank you for your patience in reading, I think it is good to double click like ha, and give you a list of computer classic books, for computer students and programmers, reading computer classic books is always the most cost-effective thing in growth.

Link: * * * *Computer Classics required reading list (including download methods)

Java to master the interview with the most complete information package (including download methods)

  • Let’s look at it againserverModule structure, a very standard SpringBoot project;

  • Look at thefrontModule structure, a very standard Vue project, worth learning!

The installation

Let’s get Torna up and running to see what it can do. It’s available for Windows and Linux installation.

Windows

Here’s how to install Torna on Windows, if you want to learn more about Torna.

The back-end running

  • Start by creating a databasetorna, and then import into the projectmysql.sqlAfter the script is imported successfully, the table structure is as follows.

  • Modify the configuration files of the project server/boot/SRC/main/resources/application properties, modify the corresponding database connection configuration;

    Server port

    server.port=7700

    MySQL host

    mysql.host=localhost:3306

    Schema name

    mysql.schema=torna

    Insure the account can run CREATE/ALTER sql.

    Mysql. Username =root mysql. Password =root Copy code

  • Then run the main method of the project startup class TornaApplication. The console prints the following information to indicate successful startup.

The front running

  • Go to the front-end project directoryfrontRun,npm installCommand install dependencies;

  • If node-sass cannot be installed, run the following command to install it.

    NPM I node – sass — sass_binary_site=npm.taobao.org/mirrors/nod… Copy the code

  • After the dependency installation is complete, run the NPM run dev command to start the project. After the project is successfully started, visit http://localhost:9530/

  • Experience the account password[email protected]:123456Access to Torna services, the interface is good!

Linux

Installing Torna using Docker under Linux is very simple, if you only want Torna for API documentation services.

  • First, we need to download the Docker image of Torna;

    Docker pull TangHC2020 / Torna: Latest copy code

  • After downloading the application. Properties configuration file, copy it to /mydata/torna/config and modify the database configuration.

    Server port

    server.port=7700

    MySQL host

    Mysql. Host = 192.168.3.101:3306

    Schema name

    mysql.schema=torna

    Insure the account can run CREATE/ALTER sql.

    Mysql. Username =root mysql. Password =root Copy code

  • Then run the following command to run the Torna service:

    Docker run – p – 7700-7700 the name torna – v/mydata/torna/config: / torna/config – d tanghc2020 / torna: latest copy code

  • Due to direct the image containing the front-end and back-end projects, so can be used directly, access to the address: http://192.168.3.101:7700

use

Torna supports the import of interface documents from various tools, including Swagger, Smart-Doc, OpenAPI, Postman, etc. Let’s check it out!

Use in combination with Swagger

Torna can greatly enhance the function of Swagger, and the interface is beautiful enough, let’s experience it below!

  • Before using it, we need to configure it in Torna. First we need to configure an open user and create a new onemacroAccount number, rememberAppKeyandSecret;

  • Then create a projectmall-tiny-trona;

  • Next create a module and open itOpenAPITag, getRequest pathandtoken;

  • Then integrate Torna into projects that use Swagger, very simple, add the following dependencies;

    Cn. Torna Swagger – Plugin 1.2.6 test Copy code

  • Add the torna.json configuration file to the resources directory.

    {// enable push “enable”: true, // scan package, multiple uses; Separated by “basePackage” : “com. Macro. Mall. Tiny. The controller”, / / push URL, IP port corresponding Torna server “URL” : “http://localhost:7700/api”, // appKey “appKey”: “20211103905498418195988480”, // secret “secret”: ” #ZS ! // module token” token”: “74365 d40038d4f648ae65a077d956836”, / / debugging environment, format: name of the environment, debugging paths, multiple use “|” separated “debugEnv” : Test, “http://localhost:8088”, “author” : / / push people “macro”, / / open the debug: true/false “debug” : True, // Whether to replace the document, true: replace, false: do not replace (append). Default: true “isReplace”: true} Copy code

  • Then push the interface document to Torna by calling pushDoc of the SwaggerPlugin;

    @RunWith(SpringRunner.class) @SpringBootTest public class MallTinyApplicationTests {

    @test public void pushDoc(){// Torna.json swagplugin. pushDoc(){// Torna.json swaggerPlugin. pushDoc(); }Copy the code

    } Duplicate code

  • After the push succeeds, the following interface information is displayed in the interface list.

  • View the details of the interface, or very comprehensive, interface is also good!

  • Run our project, you can directly in the above interface debugging, call login interface try;

  • If we want to set a common request header, such as one for login authenticationAuthorizationHead, can be inThe module configurationTo configure;

  • Until the back-end interface is complete, we can use Mock functionality if we need Mock data.

  • Here we Mock the login interface. You can also use a Mock script. Once the interface is defined, the front end can use the Mock data.

Use in combination with smart-doc

Smart-doc is a non-annotated API document generation tool. Please refer to the Smart-Doc Tutorial to see how to use it in conjunction with Torna.

  • First modify smart-doc configuration file smart-doc.json of the mall-tiny-smart-doc project and add the following configuration about Torna.

    {/ / torna docking platform appKey “appKey” : “20211103905498418195988480”, / / torna platform appToken “appToken” : “/ / torna platform secret b6c50f442eb348f48867d85f4ef2eaea”, “secret” : “# ZS! // Torna platform address, fill in your private deployment address “openUrl”: “Http://localhost:7700/api”, / / test program interface environment “debugEnvName” : “test”, / / test program interface address “debugEnvUrl” : “http://localhost:8088”} copy code

  • Since smart-Doc’s Maven plugin already has the ability to push documents to Torna, we just need to double click the Smart-Doc: Torna-rest button.

  • Next in Torna, we can see the relevant interface documentation, very convenient!

conclusion

When a tool becomes more popular, but some functional requirements are not met, there are often some enhancement tools, Torna for Swagger is such a tool. Torna document interface and debugging functions are obviously much higher than Swagger, but also increased the authority management function, document security greatly enhanced, we feel good if you can try it!

I myself liver six copies of PDF < about Java entry to god >, the whole network spread more than 10W +, search “code farmers attack” after paying attention to the public number, in the background reply PDF, get all PDF

Six PDF links

The resources

Official document: torna.cn/

Project source code address

Github.com/macrozheng/…

In this paper, making github.com/macrozheng/… Already included, welcome everyone Star!