Apidoc is a very useful code generation documentation tool with colorful (and garish) pages that are very friendly to the front-end docking API. So without further ado, let’s look at the demo

JS/TS + apidoc + VSCode

Step 1: Install apidOC globally

npm install -g apidoc
Copy the code

Step 2: Create apidoc.json

Create project -> Create apidoc.json in the root directory.

{
    "name": "demo"."version": "0.1.0 from"."description": "demo api documents"."url": "http://localhost:3000"
}
Copy the code

Examples are basic configuration, more configuration points here

Step 3: the VSCode plug-in ApiDoc Snippets

Search for ApiDoc Snippets in the vscode extension store and install.

Step 4: Type apiDocument in the function name

Tip: Typing in the API will prompt you for lists

Find the right completion. See here for an explanation of each field

Here is an example:

	/ * * *@api {GET} /api/users/:id getUserById
     * @apiName getUserById
     * @apiGroup User
     * 
     * @apiParam  {String} Id User ID * *@apiSuccess  {Number} Code returns 200 * * on success@apiParamExample  {Object} Request-Example:
     * {
     *      id: 1
     * }
     * 
     * @apiSuccessExample {type} Success-response: * {* id: 1, * name: "zhang3 ", * age: 25, * hobbies: [* {name:" chess", en_name: "chinese_chess", key: "Chess"}, {name: "basketball", en_name: "also," key: "also"}} *] * * * /

Copy the code

Step 5: Generate interface documents

The terminal enters apidoc -i sourceDir/ -o targetDir

SourceDir is the API to choose which directory to build, target is the directory to build to.

For example, apidoc -i controller/ -o public/apidoc/

Public /apidoc has a generated static file. Opening index.html is the final result. The generated document is usually stored on the server’s static server so that the front-end developer can access it directly.

Effect:

Ok, work together! More use, parameter description