当前位置:网站首页>焕然一新,swagger UI 主题更改
焕然一新,swagger UI 主题更改
2022-07-29 05:19:00 【廖圣平】
swagger UI 比较让人头疼的就是项目大了之后,接口很难找到。偶然看到了一个UI库还是不错,能搜索接口名,而且整个布局也相对比较人性化
可以集成到自己的swagger项目中,以Golang为例:
替换一下渲染的方法即可:
//r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) //注释掉之前的渲染方式,访问即可
r.GET("/swagger/*any", handleReDoc)
func handleReDoc(ctx *gin.Context) {
i := strings.LastIndex(ctx.Request.URL.Path, "/")
if i == -1 {
return
}
suffix := ctx.Request.URL.Path[i+1:]
switch suffix {
case "doc.json":
// 载入swag生成的 docs/swagger.json
data, err := ioutil.ReadFile("docs/swagger.json")
if err != nil {
panic("cannot open docs/swagger.json")
}
_, _ = ctx.Writer.Write(data)
return
case "index.html":
// 这个index.html咱们得从ReDoc的github主页上拿
// spec-url是swagger.json的URL,要改为当前项目的
const redocIndexHTML = `<!DOCTYPE html> <html> <head> <title>ReDoc换皮成功</title> <!-- needed for adaptive design --> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet"> <!-- ReDoc doesn't change outer page styles --> <style> body { margin: 0; padding: 0; } </style> </head> <body> <redoc spec-url='http://127.0.0.1:8080/swagger/doc.json'></redoc> <script src="https://cdn.jsdelivr.net/npm/[email protected]/bundles/redoc.standalone.js"> </script> </body> </html>`
fmt.Println("ererer")
_, _ = ctx.Writer.Write([]byte(redocIndexHTML))
return
default:
_ = ctx.AbortWithError(http.StatusNotFound, errors.New("page not found"))
}

边栏推荐
- Wapiti是什么以及使用教程
- HCIA-R&S自用笔记(24)ACL
- Merge the same items in the same column in table
- Basic use of redis
- Detailed explanation of typical application code of C language array - master enters by mistake (step-by-step code explanation)
- 相对定位和绝对定位
- QT layout management -- Part stretch principle and sizepolicy
- Thrift安装手册
- AR虚拟增强与现实
- 实现table某个单元格背景色设置
猜你喜欢

Clickhouse learning (V) cluster operation

QT layout management -- Part stretch principle and sizepolicy

Clickhouse learning (x) monitoring operation indicators

DAY6:利用 PHP 编写文件上传页面

WIN10 编译ffmpeg(包含ffplay)

使用Qss设置窗体样式

DAY14:Upload-labs 通关教程

虚拟增强与现实第二篇 (我是一只火鸟)

ClickHouse学习(十)监控运行指标

Hcia-r & s self use notes (24) ACL
随机推荐
记xx公司SQL注入漏洞
Hcia-r & s self use notes (26) PPP
What is sqlmap and how to use it
Fvuln automated web vulnerability detection tool
Selenium实战案例之爬取js加密数据
What is wapiti and how to use it
[C language series] - print prime numbers between 100 and 200
Talking about Servlet
Relative positioning and absolute positioning
link与@import导入外部样式的区别
Character type conversion
[JS question solution] questions 1-10 in JS of niuke.com
DAY15:文件包含漏洞靶场手册(自用 file-include 靶场)
公众号不支持markdown格式文件编写怎么办?
Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction
Clickhouse learning (V) cluster operation
Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string
Wechat applet - screen height
Fvuln-自动化web漏洞检测工具
Record the SQL injection vulnerability of XX company
