Nodejs的apidoc操作


前言

apidoc的安装

npm install apidoc -g

-g参数表示全局安装,这样哪儿都能用了哦

Nodejs文件定义接口信息

/** 
 * @api {POST} http://127.0.0.1:8000/login/ 登录操作
 * @apiVersion 0.0.1
 * @apiName login
 * @apiGroup User
 * @apiDescription 这里可以描述一下这个函数的具体操作
 * 这一行也是可以描述的
 * 
 * @apiParam {String} name 姓名
 * @apiParam {String} password 密码
 * 
 * @apiSuccess {Object} status 状态码
 * @apiSuccess {Object} msg 简略描述
 * 
 * @apiSuccessExample Response-Success:
 *     HTTP 1.1/ 200K
 *     {
 *         'status': 0,
 *         'msg': 'success'
 *     }
 * @apiErrorExample Response-Fail:
 *     HTTP 1.1/ 404K
 *     {
 *         'status': 0,
 *         'msg': 'Fail'
 *     }
*/
function login(name, password) {
    console.log(name, password);
    return {
        'status': 0,
        'msg': 'success'
    };
};

apidoc.json文件

栗子1
{
  "name": "我的apidoc示例",
  "version": "0.0.1",
  "description": "这是一句描述,描述了api文档",
  "title": "API DOC EXAMPLE"
}
栗子2

这种栗子中需要在apidoc.json文件的当前路径下分别新建header.md和footer.md文件
apidoc.json

{
  "name": "example",
  "version": "0.1.0",
  "description": "apidoc test1",
  
  "header": {
    "title": "这不是头",
    "filename": "header.md"
  },
  "footer": {
    "title": "这不是尾",
    "filename": "footer.md"
  }
}

header.md

# Example text from header.md

This text is from file "header.md".

## <span id="api-example-for-a-submenu-entry">HowTo include</span>

In your projects "package.json" you can set "apidoc.header" with a title and a filename to include this file into your documentation.

This example attempts to integrate "header.md" and "footer.md".

    {
      "name": "example",
      "version": "0.3.0",
      "description": "apidoc example project.",
      "apidoc": {
        "header": {
          "title": "My own header title",
          "filename": "header.md"
        },
        "footer": {
          "title": "My own footer title",
          "filename": "footer.md"
        }
      }
    }

footer.md

# Example text from footer.md

This text is from file "footer.md".

## HowTo include

Watch header.md for further information.

生成apidoc网页文件

apidoc -i 代码所在路径 -o 生成文件的路径

此时会在指定的生成文件路径中生成一个apidoc的文件夹,里面的index.html文件就是啦啦啦啦~~~

转载于:https://www.cnblogs.com/yun1233/p/10387531.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值