当前位置:网站首页>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
边栏推荐
- Detailed explanation of knowledge map construction process steps
- Function optimization and arrow function of ES6
- Maximum likelihood estimation and cross entropy loss
- 1500萬員工輕松管理,雲原生數據庫GaussDB讓HR辦公更高效
- Basic knowledge of lists
- 2022 Guangdong Provincial Safety Officer C certificate third batch (full-time safety production management personnel) simulation examination and Guangdong Provincial Safety Officer C certificate third
- 小孩子學什麼編程?
- C language games - minesweeping
- 基于STM32单片机设计的红外测温仪(带人脸检测)
- Web security - payload
猜你喜欢
Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
Web security - payload
1_ Introduction to go language
【微信小程序】運行機制和更新機制
C language operators
OLED屏幕的使用
Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
【DSP】【第一篇】开始DSP学习
Event center parameter transfer, peer component value transfer method, brother component value transfer
[DSP] [Part 1] start DSP learning
随机推荐
[DIY]如何制作一款個性的收音機
Redis insert data garbled solution
Quel genre de programmation les enfants apprennent - ils?
Xcode6 error: "no matching provisioning profiles found for application"
[weekly pit] output triangle
Leetcode question 283 Move zero
Gui Gui programming (XIII) - event handling
Function optimization and arrow function of ES6
“罚点球”小游戏
Web开发小妙招:巧用ThreadLocal规避层层传值
C language games - three chess
正则表达式收集
Rhcsa Road
Value of APS application in food industry
Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
Trends of "software" in robotics Engineering
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
PG basics -- Logical Structure Management (transaction)
User defined current limiting annotation
自定义限流注解