Detailed explanation of how springboot automatically generates API documents

Time:2021-9-17

preface

When doing a project, if the project is separated from the front and back, the back end must interface with the front end or the mobile end. Then the problem comes. Should the interface be written to them? Generally, it will be written in Excel or word, and the advanced ones will be manually entered on the API management platform. A project has tens of thousands of interfaces. God, what a workload, Interface maintenance is more painful. In order to solve such problems, we can usejapi This project is used to complete the automatic generation of restful documents. It is completely generated based on comments. More detailed configurations can be viewed https://github.com/dounine/japi 。

instructions

Clone project down


git clone https://github.com/dounine/japi.git

Compile package


cd japi/java
gradle install -xtest

Run japi background management


cd japi/java
gradle bootRun

Run the japi document interface


cd japi/node
node app.js

Generate restful documents

Maven project


<dependency>
    <groupId>com.dounine.japi</groupId>
    <artifactId>client</artifactId>
    <version>1.0</version>
</dependency>

Gradle project


compile group: 'com.dounine.japi', name: 'client', version: '1.0'

Edit the resources / japi.properties configuration file


japi.name=test
japi.uuid=43a600877430438596de3d330e4bd06e
japi.version=1.0.0
japi.author=lake
japi.url=http://192.168.0.123:8080
japi.description=this is project description.
japi.createTime=2017-02-23 10:44:44
japi.icon=/home/lake/github/japi/html/img/logo.png
japi.server=http://192.168.0.179:7778
japi.server.username=japi
japi.server.password=japi123

Write an action

/**
 *Get user list
 *@ param user user information
 * @return class User
 * @version v2
 */
@GetMapping(value = "v2/list")
public Result hots(@Validated({User.UserDEL.class}) User user) throws RuntimeException {

    return null;
}

Write an API generation class

JapiCreateTest.java

@Test
    public void testCreate(){
        JapiClient.setPrefixPath("/home/lake/github/test-japi/java/");// Project path prefix
        JapiClient.setpostfixPath("/src/main/java");// Project path suffix

        JapiClient.setProjectJavaPath("client");// Main project site
        JapiClient.setActionReletivePath("com/dounine/test-japi/action");// The path relative to the action package of the main project
        //JapiClient.setIncludeProjectJavaPath(new String[]{"api"});// Other package paths associated with the main project
        JapiClient.setIncludePackages(new String[]{"com.dounine.test-japi"});// Associated packages for accurate and fast search
        JapiClient.saveHistory(true);// Keep local historical version
        JapiClient.setFlushServer(false);// Force synchronization of all local and server versions (the previous historical version of the server will be deleted first)

        IProject project = ProjectImpl.init();
        JapiClientStorage japiClientStorage = JapiClientStorage.getInstance();
        japiClientStorage.setProject(project);
        japiClientStorage.autoSaveToDisk();// Automatically use to local disk = = > user directory /. Japi client/
        new JapiClientTransfer().autoTransfer(japiClientStorage);// Transfer files to the master server
    }

Finally, visit the browser http://localhost:7777

You can see the restful document login

Log in with your own account and you can see all the items

Enter the project to see the restful interface in detail

Usage scenario

Japi is most suitable for distributed multi module projects such as spring cloud. It has built-in powerful regular expressions, which will make code comments more standardized. Unlike swigger, which uses intrusive annotations to generate documents, japi is completely generated based on standard annotations and supports strong jsr303 or custom annotations.

Open source spirit

Welcome interested students to join the japi project team to transform it better.

summary

This is the end of this article on how springboot automatically generates API documents. For more information on how springboot automatically generates API documents, please search for previous articles on developeppaer or continue to browse the following articles. I hope you will support developeppaer in the future!

Recommended Today

Detailed steps for installing Perl and Komodo IDE for windows

Perl official website: https://www.perl.org/Perl document: https://perldoc.perl.org/Download address: https://www.perl.org/get.html The installation package of Perl Windows version is divided into activestate Perl and strawberry Perl. For the difference between the two, see: http://www.zzvips.com/article/202134.htm Note: the download speed of activestate Perl is slow. You may need KX to surf the Internet I have uploaded all the versions of […]