当前位置:网站首页>Swagger UI教程 API 文档神器
Swagger UI教程 API 文档神器
2022-07-06 12:45:00 【51CTO】
目录
[TOC]
前言
在一些接口项目中,API的使用很频繁,所以一款API在线文档生成和测试工具非常有必要。而Swagger UI就是这么一款很实用的在线工具
本博客介绍如何在公司或者自己的电脑上按照Swagger UI,注意因为公司的测试服务器是Linux系统的,所以本博客也只介绍基于Linux系统的Swagger环境搭建过程
服务器环境安装##
NodeJS下载部署###
首先需要下载NodeJS,到nodejs官网 http://nodejs.org/dist/v0.10.26,下载node-v0.10.26-linux-x64.tar.gz,因为这个是已经编译好的,所以我们先使用软件将文件上传到Linux服务器,可以使用WinSCP
然后用Linux的cd命令进入到你nodejs压缩文件的位置
解压命令如下:
然后进入文件
执行
设置node全局
设置npm全局
检测nodejs和npm是否安装成功
可以看到版本号,什么安装成功
express下载部署####
安装好NodeJS和NPM之后,我们就可以安装express了
以下几个重要的模块是需要与 express 框架一起安装的:
body-parser - node.js 中间件,用于处理 JSON, Raw, Text 和 URL 编码的数据。
cookie-parser - 这就是一个解析Cookie的工具。通过req.cookies可以取到传过来的cookie,并把它们转成对象。
multer - node.js 中间件,用于处理 enctype="multipart/form-data"(设置表单的MIME编码)的表单数据。
检测是否安装成功
NodeJS开机启动####
然后设置NodeJS开机启动
安装forever
设置
Swagger UI安装部署##
github上clone: https://github.com/swagger-api/swagger-ui 如果有下载Git,就是用git下载,获取访问github,直接下载
之后可以根据公司需要,在Linux上mkdir,我是先在root路径,创建一个node_app文件
进入node_app
环境配置
下面的提示可以根据自己需要填写
VI编辑器使用:
加入代码
启用服务器
访问,输入http://公司服务器IP:3000
可以看到Helloworld,当然我们是要部署Swagger
在node_app下面创建一个public文件夹
然后将下载到的swagger ui里的dist文件夹里的文件复制到public文件夹里
修改index.js
然后输入 http://ip:3000/swapper,是可以看到类似page

这里写图片描述
Swagger Editor使用##
Swagger Editor是Swagger UI的在线编辑器,我们可以自己搭建一个,也可以使用官方的,下面给出官方的URL: http://editor.swagger.io/#/
github上Clone: https://github.com/swagger-api/swagger-editor 之后将swagger editor文件放在公司Linux服务器上
Http server安装###
启动该项目http-server swagger-editor,默认为8080端口
设置port并启动swagger editor
输入 http://ip:2017/#/可以访问到自己搭建的Swagger Editor编辑器
参考教程
http://www.linuxidc.com/Linux/2014-07/104489.htm
http://www.linuxidc.com/Linux/2014-06/103372.htm
边栏推荐
- 什么是RDB和AOF
- 新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
- SAP UI5 框架的 manifest.json
- [weekly pit] calculate the sum of primes within 100 + [answer] output triangle
- R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
- Can novices speculate in stocks for 200 yuan? Is the securities account given by qiniu safe?
- Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
- SQL injection 2
- (work record) March 11, 2020 to March 15, 2021
- [asp.net core] set the format of Web API response data -- formatfilter feature
猜你喜欢

逻辑是个好东西

15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient

Performance test process and plan

I've seen many tutorials, but I still can't write a program well. How can I break it?

Use of OLED screen

Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
![[weekly pit] output triangle](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[weekly pit] output triangle

What programming do children learn?

Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)

【每周一坑】信息加密 +【解答】正整数分解质因数
随机推荐
[DSP] [Part 2] understand c6678 and create project
Rhcsa Road
2022 nurse (primary) examination questions and new nurse (primary) examination questions
Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
OSPF多区域配置
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
02 basic introduction - data package expansion
"Penalty kick" games
【微信小程序】运行机制和更新机制
What are RDB and AOF
PHP online examination system version 4.0 source code computer + mobile terminal
Function optimization and arrow function of ES6
B-jiege's tree (pressed tree DP)
In line elements are transformed into block level elements, and display transformation and implicit transformation
Leetcode hot topic Hot 100 day 32: "minimum coverage substring"
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
Spiral square PTA
Web开发小妙招:巧用ThreadLocal规避层层传值