在宝塔下使用apidoc

1.先安装ndoe版本管理器 安装node的v14版本

如果回到系统命令行下输入node命令无法使用,则需要选择命令行版本

 

2.在命令行下安装apidoc:

npm install apidoc -g 

安装完后如果发现apidoc命令无法使用,则需要建立软连接:

ln -s /www/server/nodejs/v14.17.6/bin/apidoc /usr/bin/apidoc

3.创建api.json配置文件:

{
  "name": "My Project",
  "title": "My API",
  "description":"API接口文档",
  "url" : "http://api.demo.com",
  "version": "0.1.0"
}

4.新建目录src,创建api文档demo:

/**
 * @api {get} /shop/getList/:id 通过商家id获取店铺列表
 * @apiGroup Shop
 *
 * @apiParam (params) {int} id      商家id
 * @apiParamExample 请求参数Demo:
 *      {
 *        "id": 2,
 *       }
 *
 * @apiSuccess {Array} article 返回相应id的文章信息
 *
 * @apiSuccessExample Success-Response:
 *    HTTP/1.1 200 OK
 *      {
 *        "tile": "文章标题2",
 *        "date": 1483941498230,
 *        "author": "classlfz",
 *        "content": "文章的详细内容"
 *       }
 *
 * @apiSampleRequest http://51.133.54.142
 */

/**
 * @api {post} /shop/add 新增商家
 * @apiGroup Shop
 *
 * @apiBody {String} name      商家名
 * @apiBody {String} address      商家地址
 *
 * @apiSuccessExample Success-Response:
 *    HTTP/1.1 200 OK
 *      {
 *        "tile": "文章标题2",
 *        "date": 1483941498230,
 *        "author": "classlfz",
 *        "content": "文章的详细内容"
 *       }
 *
 * @apiSampleRequest http://51.133.54.142
 */

5.新建文档输出目录:doc

现在的目录结构是这样的:

 6.使用命令生成文档:

apidoc -c apidoc.json

 

去doc目录下查看:

 代表生成成功,如果没生成成功,则需要检查src目录下的php文件,检查生成文档。

最终效果:

 

posted @ 2024-09-01 11:50  童年的回忆  阅读(2)  评论(0编辑  收藏  举报
如果本博客解决了您的问题,可以微信支付宝打赏鼓励一下作者哦,在此表示感谢