华为云计算 云知识 Swagger UI是什么
Swagger UI是什么

简介

Swagger UI是目前最流行的RestFul接口API文档和测试工具。

编译和测试方式

1.选择操作环境

本文选用华为鲲鹏云服务ECS KC1实例做测试

2.配置编译环境

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启动运行,因此需要安装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,选用的验证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.测试已完成编译的软件

进入Swagger UI软件解压的目录,执行http-server运行。

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

http-server

回显内容如下:

Starting up http-server, serving ./

Available on:

  http://127.0.0.1:8081

  http://192.168.1.140:8081

已知问题汇总

问题描述:

安装http-server过程中提示如下错误:

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

问题原因:解析其中一个json格式的缓存文件时发生错误。

解决方法:

清除缓存,重新设置npm仓库。

npm cache clean --force

npm set registry https://registry.npmjs.org/
上一篇:Docker Compose是什么 下一篇:Web应用面临的安全挑战有哪些?

云测 CloudTest

面向软件开发者提供的一站式云端测试平台,覆盖测试管理、接口测试,融入DevOps敏捷测试理念,帮助您高效管理测试活动,保障产品高质量交付