A introduction

JApiDocs is an Api document generation tool that conforms to Java programming conventions. To make the most of Java’s syntaxic features, you just design the interface carefully, add the necessary annotations, and JApiDocs will help you export a beautiful Html document and generate the relevant Java and Object-C data model code. Android and IOS students will be able to type a lot less code, and you won’t need to maintain interface document changes, just maintain your code.

Some people hate to use Swagger to use a lot of annotations, when the project is large, the annotation takes a lot of time to write, then JApiDocs can use Java native code to replace it;

Official GIee address: gitee.com/yeguozhong/…

Ii Introduction

2.1 Importing Dependencies

<dependency>
    <groupId>io.github.yedaxia</groupId>
    <artifactId>japidocs</artifactId>
    <version>1.4.4</version>
</dependency>
Copy the code

2.2 Java annotations on VO

/ * * *@AuthorLSC * < P > Test entity </p> */
public class TestVo  {

    /** Test name **/
    private String testName;

    /** Test age **/
    private Long testAge;

    /** Test time **/
    private LocalDateTime testTime;

    // omit set get
}
Copy the code

2.3 Control layer with Java annotations

/ * * *@AuthorLSC * < P > Tests </p> */
@RestController
public class TestController {

   /** * test get *@param testVo
    */
    @GetMapping(value = "info")
    public ResponseEntity<TestVo> testGet(TestVo testVo){
        return ResponseEntity.ok().body(testVo);
    }

    /** * Test the get argument *@param id
     */
    @GetMapping(value = "info/test")
    public ResponseEntity<Long> test(@RequestParam Long id){
        return ResponseEntity.ok().body(id);
    }

    /** * Test post *@param testVo
     */
    @PostMapping(value = "info")
    public ResponseEntity<Long> testPost(@RequestBody TestVo testVo){
        return ResponseEntity.ok().body(1L);
    }

    /** * test delete *@param id
     */
    @DeleteMapping(value = "info/{id}")
    public ResponseEntity<Long> testPost(@PathVariable Long id){
        return ResponseEntity.ok().body(1L); }}Copy the code

2.4 Generating Documents

 public static void main(String[] args) {
        // 1. Create the configuration to generate the document
        DocsConfig config = new DocsConfig();
        // Project directory
        config.setProjectPath("C:/java/zszxz/studys-pringboot/springboot-JApiDocs");
        // The target directory to generate HTML interface documents
        config.setDocsPath("C:/mydata/generator/japi");
        // Automatically generated
        config.setAutoGenerate(Boolean.TRUE);
        / / project name
        config.setProjectName("Japi Test Project");
        // API version number
        config.setApiVersion("V1.0");
        // Use the MD plugin to generate additional interface documents in MD format
        config.addPlugin(new MarkdownDocPlugin());
        // 2. Execute to generate HTML interface document
        Docs.buildHtmlDocs(config);

    }
Copy the code

The generated document directory is as follows

Visit the Index page

Iii Advanced Usage

We don’t even use advanced ones.

3.1 @ ApiDoc

By default, JApiDocs only exports apis that declare @apidoc. We removed this restriction earlier by setting config.setautogenerate (Boolea.true).

If you don’t want to export all the apis, you can turn off autoGenerate and add @apidoc to the Controller class or API method to determine which apis need to be exported.

Let’s see how @apidoc works on API methods:

Url: Request URL, extended field, used to support non-SpringBoot items. Method: Request method, extended field, used to support non-SpringBoot items

The sample

@ApiDoc(result = AdminVO.class, url = "/api/v1/admin/login2", method = "post")
Copy the code

Putting @apidoc on non-Springboot projects is a good choice

3.2 @ Ignore

You can use the @ignore annotation if you don’t want to export a field on an entity

The sample

public class TestVo  {

    /** Test name **/
    @Ignore
    private String testName;
}    
Copy the code

3.3 export Markdown

Add the following line of code to the configuration to generate the Markdown file

config.addPlugin(new MarkdownDocPlugin());
Copy the code

The last

About this tutorial sample source code incorporated in the SpringBoot series tutorial source code: github.com/zszxz/study…

Knowledge Seeker’s open source rights management system: github.com/zszxz/zboot

I hope you can give me a start!!

Welcome to my public account: Knowledge seeker;