在宝塔下使用apidoc

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

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

 

2.在命令行下安装apidoc:

1
npm install apidoc -g

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

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

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

1
2
3
4
5
6
7
{
  "name": "My Project",
  "title": "My API",
  "description":"API接口文档",
  "url" : "http://api.demo.com",
  "version": "0.1.0"
}

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * @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.使用命令生成文档:

1
apidoc -c apidoc.json

 

去doc目录下查看:

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

最终效果:

 

posted @   童年的回忆  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
如果本博客解决了您的问题,可以微信支付宝打赏鼓励一下作者哦,在此表示感谢
点击右上角即可分享
微信分享提示