安装
npm install apidoc -g
运行
apidoc -i (项目路径) -o (注释存储路径)
apidoc.json
项目根目录中的可选内容包括有关项目的常见信息,例如标题,简短描述,版本和配置选项
{
"name": "example", //项目名称
"version": "0.1.0", //项目版本
"description": "apiDoc basic example", //项目简介
"title": "Custom apiDoc browser title", /浏览器标题文本
"url" : "https://api.github.com/v1" //api路径的前缀
}
注释模板
/**
* @api {get} /user/:id Request User information
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "firstname": "John",
* "lastname": "Doe"
* }
*
* @apiError UserNotFound The id of the User was not found.
*
* @apiErrorExample Error-Response:
* HTTP/1.1 404 Not Found
* {
* "error": "UserNotFound"
* }
*/