swagger:方便測試人員和客戶端開發(fā)了解API
1. 第一步搭建官方的swagger ui
1.1 下載
git clone https://github.com/swagger-api/swagger-ui.git
1.2 創(chuàng)建一個另外的文件夾--用來發(fā)布
mkdir swagger
1.3 在發(fā)布的文件夾下面安裝express
cd swagger
npm init
npm install express --save
1.4 創(chuàng)建目錄public,并將剛才clone下來的Swagger UI中dist目錄下的所有文件全部復(fù)制到public目錄下面
cp -r ../swagger-ui/dist/ ./public
1.5 創(chuàng)建express主程序
var express = require('express');
var app = express();
// 接口顯示頁面
app.use('/static', express.static('public'));
app.listen(8005, function () {
console.log('app listening on port 8005!');
});
1.6 啟動服務(wù)
node swagger.js
# 用pm2啟動
pm2 start swagger.js
1.8 訪問
http://192.168.185.231:8005/static/index.html
2. 替換官方的API
2.1 安裝swagger-edit
git clone https://github.com/swagger-api/swagger-editor.git
npm init
2.2 啟動swagger-edit
# 直接退回swagger-edit的父目錄,然后啟動便可
miao@miao-VirtualBox:~/workspace$ ls
sod swagger swagger-editor swagger-ui
miao@miao-VirtualBox:~/workspace$ http-server swagger-editor
Starting up http-server, serving swagger-editor
Available on:
http://127.0.0.1:8080
http://192.168.185.231:8080
Hit CTRL-C to stop the server
2.3 靜默啟動
nohup http-server swagger-editor >> /home/miao/workspace/swagger-editor.log 2>&1 &