首先声明下,apidoc是基于注释来生成文档的,它不基于任何框架,而且支持大多数编程语言,适用于java项目。跟已有的项目框架没有任何关系
通过命令安装:
npm install apidoc -g
运行apidoc -i chapter4/ -o apidoc/
就能自动生成项目api文档,避免写文档的麻烦
只要在项目api方法上面加上注释
/**
* @api {get} /user/:id 用户登录查询用户信息
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
* @apiParam {int} vip = 0 是否注册Vip身份 0 普通用户 1 Vip用户
* @apiParamExample {json} 请求样例:
* ?/user/:10061
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "firstname": "John",
* "lastname": "Doe"
* }
*
*/