swagger to build and use
The first-hand good cooking IT workers concerned
2018.03.28 16:39:31 142 read 1,490 words
swagger: easy to testers and developers to understand the client API
1. The first step to build the official swagger ui
1.1 Download
git clone https://github.com/swagger-api/swagger-ui.git
1.2 to create a separate folder - used to publish
mkdir swagger
1.3 Installation express in the published folder below
cd swagger
npm init
npm install express --save
1.4 Create a directory public, and just down the clone all files under Swagger UI in dist directory copy the entire directory to the public
cp -r ../swagger-ui/dist/ ./public
1.5 Creating express the main program
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 Start Service
node swagger.js
# 用pm2启动
pm2 start swagger.js
1.8 Access
http://192.168.185.231:8005/static/index.html
2. Replace the official API
Installation swagger-edit 2.1
git clone https://github.com/swagger-api/swagger-editor.git
npm init
2.2 Starting 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 Quiet Boot
nohup http-server swagger-editor >> /home/miao/workspace/swagger-editor.log 2>&1 &