apidoc

1、安装node 

http://nodejs.cn/download/

 下载二进制包,解压,配置环境

export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH

node -v 检查

2、修改node默认镜像

npm config ls -l 查看配置项

npm config set registry "http://registry.npm.taobao.org"

3、全局安装apidoc

npm install apidoc -g

4、新建文件夹demo

5、创建apidoc.json文件和test.PHP文件

apidoc.json:

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

test.php文件

<?php
/**
 *
 * @api {get} /user/{id}
 * @apiDescription 获取用户信息接口描述
* @apiGroup User
 * @apiName getUserInfo
 * @apiParam {Number} id 用户ID
 * @apiVersion 0.1.0
 *
 *
 * @apiExample {curl} 访问示例:
* curl -i http://api.demo.com/user/4711
*
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */
function GetUser($id){}

6、进入demo目录,运行命令

apidoc

如果自定义文件后缀名:md,可用命令:apidoc -f  ".*.md$"

7、在该目录下会生成doc目录,直接访问即可

脚本:

echo "build api_rest API DOC ..."

cd /opt/git/api_rest
git fetch
git checkout $1
git pull

apidoc -i /opt/git/api_rest/ -o /opt/appdocs/api/

rm -rf /opt/tomcat/webapps/api
mv /opt/appdocs/api /opt/tomcat/webapps

echo "gen api_rest doc end ..."

原文地址:https://www.cnblogs.com/hujihon/p/6258998.html