Java development, according to the code automatically generate API interface document tool, support RESTful style, today we will learn about the generation of apI-doc

Author: Internet programming. Welcome to contribute, together with communication technology, www.jianshu.com/u/4ea0af17f…

preview

Online Preview address

lovepeng.gitee.io/apidoc

The development principle

This tool is a typical front and back end separation development project, want to know the front and back end separation development students can also download this project to learn.

The project backend is Java code and the front end is Angular development. In Java development, annotations are used to annotate document-related information in class methods, and tools automatically scan code annotations to generate JSON data that is sent to the front end, where Angular parses and generates pages

This project comes with a spring-boot framework based demo (here using the spring-boot demo is just for convenience, essentially as long as the project is written in Java can use this tool), The front end makes a nice interface in Angular (the front end is eventually compiled into HTML, so if you’re not familiar with the front end, you can skip it). Here, angular development is just my favorite. You can use any front-end framework you like or just write a nice interface in HTML.

Back-end project open source address: github.com/liepeng328/…

Front-end open source address: github.com/liepeng328/…

Quick start

To use it as a utility class, download this project, copy the com.apidoc code to your system, and then copy the front-end HTML page from static.apidoc to your resources file. When ready to use, the background provides two interfaces, directory document interface and a function of the detailed interface

// generate directory interface ApiDoc ApiDoc = new GeneratorApiDoc().setinfo (// set the basic information of the document new ApiDocInfo().settitle (" some system background management document ") SetVersion (" 1.0 "). SetDescription (" ")). The generator (packageName); System.err. Println (jsonutil.tostring (detail)); // ApiDocAction detail = new GeneratorApiDoc() Negligible.setDriver(driver).seturl (URL).setUsername (userName).setPassword(password).setDatabasename (dataBaseName) .getApiOfMethod(methodUUID); System.err.println(JsonUtil.toString(detail));Copy the code

A detailed example

A detailed example of this code is shown below. Here is the SpringBoot/SpringMVC Controller example (showing two documents, front end interface and back end interface) referring to the code of the class UserController.java

Notes detailed introduction

There are 6 annotations, annotating the entire document (why I’m so detailed and verbose, and why I didn’t jar the project directly for others to use, is because the document generation most likely requires special customization, make sure you get the code to personalize the functionality and modify it as you please).

  • Api Annotation document function module
  • ApiAction annotates a function
  • ApiReqAparams request parameters
  • ApiResqAparams response parameter
  • ApiParam parameters, used to compose the request and response parameters
  • Table is used to annotate the relationship between entity classes (such as beans) and database tables, automatically reading relevant information from the database without writing a lot of ApiReqAparams and ApiResqAparams

Details are as follows

Api: Written on a class to indicate a functional module. Properties:

  • Name Module name
  • The mapping url mapping

ApiAction: Written on a method to indicate a function point property:

  • Name Function name of the method
  • The mapping url mapping
  • The description described
  • Method Request method (GET, POST, PUT, delete)

ApiReqParams: Request parameter properties:

  • Type: indicates the parameter type
  • Header is in the request header
  • The URL is spliced after the URL
  • Form data
  • Json json format
  • ApiParam: Parameter list
  • Value: class. This class is added to automatically read database information and avoid writing multiple attributes
  • Remove: Used with value to remove unnecessary attributes, such as id, from the class
  • DataType: dataType (string string, number, file, date, object, array array, Boolean type)
  • Descrption: describe
  • DefaultValue: indicates the defaultValue
  • Required: Is it necessary
  • Object: belongTo an object (request or response parameters may belongTo nested objects in the object. BelongTo: belongTo: belongTo object: belongTo object: belongTo an object (request or response parameters may belongTo nested objects in the object, belongTo: belongTo)
  • BelognTo: The default value of object is “0” and the string is 0

ApiRespParams: Response parameter properties:

  • ApiParam: This parameter is equivalent to the ApiParam in the request parameters, as described above

Download this project and run it

To configure jdK8 or later, download the code and run the main method of ApidocApplication. Then visit the address http://localhost:8080/index.html

Thank you for the list

This project is maven project. For reference, please see Pum.xml. Thanks to Spring-boot

Like the article partners can point a like oh ~, finally, as usual, amway wave of our public number: “Terminal RESEARCH and development department”, attention will send 5T programmer development tutorial, at present every day will recommend a high-quality technology-related article, mainly share Java related technology and interview skills, learning Java not lost.