Swagger UI是什么

簡介

Swagger UI是目前最流行的RestFul接口API文檔和測(cè)試工具。

編譯和測(cè)試方式

1.選擇操作環(huán)境

本文選用華為鯤鵬云服務(wù)ECS KC1實(shí)例做測(cè)試

2.配置編譯環(huán)境

1)Swagger UI依賴于nodejs,因此先安裝nodejs。

cd /usr/local/src

wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-arm64.tar.xz

tar -xvf node-v10.16.0-linux-arm64.tar.xz

ln -s /usr/local/src/node-v10.16.0-linux-arm64/bin/node /usr/local/bin/node

ln -s /usr/local/src/node-v10.16.0-linux-arm64/bin/npm /usr/local/bin/npm

2)Swagger UI需要由http-server啟動(dòng)運(yùn)行,因此需要安裝http-server。

npm install -g http-server

ln -s  /usr/local/src/node-v10.16.0-linux-arm64/bin/http-server /usr/local/bin/http-server

3)下載和安裝Swagger UI,選用的驗(yàn)證Swagger UI版本為“2.0.24”。

cd /usr/local/src

wget https://github.com/swagger-api/swagger-ui/archive/v2.0.24.tar.gz

tar -xvf v2.0.24.tar.gz

3.測(cè)試已完成編譯的軟件

進(jìn)入Swagger UI軟件解壓的目錄,執(zhí)行http-server運(yùn)行。

cd /usr/local/src/swagger-ui-2.0.24/

http-server

回顯內(nèi)容如下:

Starting up http-server, serving ./

Available on:

  http://127.0.0.1:8081

  http://192.168.1.140:8081

已知問題匯總

問題描述:

安裝http-server過程中提示如下錯(cuò)誤:

npm ERR! Unexpected end of JSON input while parsing near '...ect.js":"*","mocha":"'

npm ERR! A complete log of this run can be found in:

npm ERR!     /root/.npm/_logs/2019-07-04T02_59_09_022Z-debug.log

問題原因:解析其中一個(gè)json格式的緩存文件時(shí)發(fā)生錯(cuò)誤。

解決方法:

清除緩存,重新設(shè)置npm倉庫。

npm cache clean --force

npm set registry https://registry.npmjs.org/