apidoc是一个轻量级的在线REST接口文档生成系统,支持多种主流语言,包括Java、C、C#、PHP和Javascript等。使用者按照要求书写相关注释,就能够生成可读性好、界面美观的在线接口文档。html
这里了解更多node
快速开始git
利用npm进行安装github
npm install apidoc -g
安装速度和网速有关,最多1到2分钟,npm
apidoc -v 能够查看版本信息
安装好后在json
C:\Users\admin\AppData\Roaming\npm\node_modules\apidoc
可以看到以下文件api
打开example文件夹apidoc.json为配置文件,修改参数为本身的项目信息。安全
{ "name": "apidoc-example", "version": "0.3.0", "description": "apidoc example project", "title": "Custom apiDoc browser title", "url" : "https://api.github.com/v1", "sampleUrl": "https://api.github.com/v1", "header": { "title": "My own header title", "filename": "header.md" }, "footer": { "title": "My own footer title", "filename": "footer.md" }, "template": { "withCompare": true, "withGenerator": true } }
将 apidoc.json 拷贝到须要生成文档的目录下测试
而后按照文档说明作代码注释url
/** * @api {get} /sguoshan_api/Logon 获取用户信息 * @apiVersion 1.0.0 * @apiName Logon * @apiGroup User * @apiPermission 全部已注册用户 * @apiPrivate * @apiDescription 与0.9.0相比安全性提升 * * @apiParam {String} username 用户名称/邮箱/会员号 * @apiParam {Number} password 用户密码 * @apiExample 使用示例: * http://api.guoshanchina.com/sguoshan_api/Logon?username=911117&password=123456 * * @apiSuccess {Number} id The Users-ID. * @apiSuccess {Date} registered Registration Date. * @apiSuccess {Date} name Fullname of the User. * @apiSuccess {String[]} nicknames List of Users nicknames (Array of Strings). * @apiSuccess {Object} profile Profile data (example for an Object) * @apiSuccess {Number} profile.age Users age. * @apiSuccess {String} profile.image Avatar-Image. * @apiSuccess {Object[]} options List of Users options (Array of Objects). * @apiSuccess {String} options.name Option Name. * @apiSuccess {String} options.value Option Value. * * @apiSuccessExample 成功 return (): { "msg": "获取成功", "status":"200", "data":{ "id":"123", "name":"shmily" } } * @apiError NoAccessRight 只用登录成功才能访问. * @apiError UserNotFound 用户 <code>id</code> 错误. * @apiErrorExample 失败 return (): * HTTP/1.1 401 Not Authenticated * { * "msg": "没有权限","status":"401" * } */ function getUser() { return; }
在命令行中
切换到项目apidoc.json的上一级(api目录) d: cd www/shop/Web apidoc -i api/ -o apidoc/
运行后在api的同级目录可以看到生成了apidoc的文件夹。双击文件夹下的index.html,就能看到文档了。