11

JApiDocs is a SpringBoot interface document generation tool that does not require additional annotations and is used out of the box.

Writing and maintaining API documentation is an annoying but compelling thing for back-end programmers. We don’t like to write documentation, but unless the front-end and back-end code of the project is written by ourselves, API documentation It will be an indispensable communication interface in front-end collaboration. Since it is unavoidable, think of a way to get a wheel. Life is short, and you must be lazy.

No picture, no truth, the effect of generating documents is as follows:

image.png
Compared with Swagger, which needs to write a bunch of annotations, Spring RestDocs needs to write test cases to generate API documentation. JApiDocs has a painless integration feature, you only need to spend a few minutes to know how to use it.

Quick start

To make JApiDcos work correctly, the code you write should look like the following:

/**
 * 用户接口
 */
@RequestMapping("/api/user/")
@RestController
public class UserController {
    /**
     * 用户列表
     * @param listForm
     */
    @RequestMapping(path = "list", method = {RequestMethod.GET,  RequestMethod.POST}  )
    public ApiResult<PageResult<UserVO>> list(UserListForm listForm){
        return null;
    }

    /**
     * 保存用户
     * @param userForm
     */
    @PostMapping(path = "save")
    public ApiResult<UserVO> saveUser(@RequestBody UserForm userForm){
        return null;
    }
}

We add necessary annotations to the Controller class and methods, and return the relevant object types to the interface methods. Yes, so that JApiDocs can parse the relevant interface information, which is similar to the code we usually write, but please note that you have to tell the JApiDocs interface parameters through @param, but with the help of the IDE, this Work will be easy and enjoyable:

Then you execute the following code in any main entry method to generate the document:

DocsConfig config = new DocsConfig();
config.setProjectPath("your springboot project path"); // 项目根目录
config.setProjectName("ProjectName"); // 项目名称
config.setApiVersion("V1.0");       // 声明该API的版本
config.setDocsPath("your api docs path"); // 生成API 文档所在目录
config.setAutoGenerate(Boolean.TRUE);  // 配置自动生成
Docs.buildHtmlDocs(config); // 执行生成文档

Next, just write the code well, and the job of generating Api documents can be handed over to JApiDocs. You don't need to worry about writing and maintaining additional documents.

Features

1. Code is document

JApiDocs works by directly parsing SpringBoot's source code syntax, so as long as the Controller's syntax conforms to a certain code specification and has reasonable comments, you can directly export the document.

2. Support for exporting HTML

Convenient navigation and interface viewing interface; it can be previewed locally or deployed to an HTTP server. It is recommended to deploy to the server to facilitate front-end and back-end collaboration.

3. Export the client Model code synchronously

Support to export Java on Android and Object C Model code on iOS, reducing the repetitive coding work of front-end programmers.

4. More features

Support interface search; support different versions and English documents; custom extensions, etc.

Concise documentation

No matter how easy it is, if there is no documentation, others will not be able to start. In order to let everyone get started as soon as possible, JApiDocs has prepared a minimalist documentation to ensure that you can use JApiDocs in a few minutes. It takes less than 5 minutes to get to know a tool that improves work efficiency, allowing you to spend more time on more valuable things. Are you sure if you don’t take a look?


民工哥
26.4k 声望56.7k 粉丝

10多年IT职场老司机的经验分享,坚持自学一路从技术小白成长为互联网企业信息技术部门的负责人。2019/2020/2021年度 思否Top Writer