//@desn:apidoc linux環境 windows環境使用
//@desn:碼字不宜,轉載請注明出處
//@author:張慧源 <turing_zhy@163.com>
//@date:2018/5/6
正文:
windows版安裝:
1.安裝nodejs (nodejs環境)
32 位安裝包下載地址 : https://nodejs.org/dist/v4.4.3/node-v4.4.3-x86.msi
64 位安裝包下載地址 : https://nodejs.org/dist/v4.4.3/node-v4.4.3-x64.msi
2.安裝apidoc,
npm install -g apidoc
使用第一個命令版 運行上面的命令安裝
linux版安裝(ubuntu)
1、更新ubuntu軟件源
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
2、安裝nodejs
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm
3、更新npm包鏡像源
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list
4、全局安裝n管理器(用於管理nodejs版本)
sudo npm install n -g
5、安裝最新的nodejs(stable版本)
sudo n stable
sudo node -v (查看版本)
6、安裝apidoc
sudo npm install apidoc -g
使用:以TP框架為例
在網站根目錄放上模板 .json
內容:
{
"name": "example",
"version": "0.1.0",
"description": "A basic apiDoc example"
}
這里上個我代碼里的注釋(apidoc就是把注釋轉換為接口文檔)
/**
* @api {POST} http://aaa.com/index/Index/add_needs 添加用戶需求
* @apiVersion 1.0.0
* @apiGroup NEED
*
* @apiParam {String} need_name 需求者名稱-非空
* @apiParam {String} e_mail 用戶郵箱-非空郵箱格式
* @apiParam {String} phone 用戶電話-非空
* @apiParam {String} company_name 需求公司名稱-非空
* @apiParam {String} needs_desc 需求描述-非空
*
* @apiSuccess {Object} code 返回碼
* @apiSuccess {Object} reason 中文解釋
* @apiSuccess {String[]} data 返回數據
*
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "code":0,
* "reason":"需求已經提交了,我們的工作人員會在2個工作日內和您取得聯系!",
* "data":[]
* }
*/
注釋參考:http://apidocjs.com (apidoc官網)
以TP為參考的重點:生成的docapi放在public下
命令:apidoc -i ./ -o ./public/apidoc 注:-i 應用目錄 -o 輸出apidoc位置 另命令要cd到應用根目錄下運行
效果展示: