当前位置:网站首页>Refresh, swagger UI theme changes
Refresh, swagger UI theme changes
2022-07-29 05:47:00 【Liaoshengping】
swagger UI What makes people headache is that after the project is large , Interfaces are hard to find . I came across a UI The library is still good , Can search interface name , And the whole layout is relatively humanized
Can be integrated into your own swagger In the project , With Golang For example :
Replace the rendering method :
//r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // Comment out the previous rendering method , Just visit
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":
// load swag Generated 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":
// This index.html We have to start from ReDoc Of github Get it on the homepage
// spec-url yes swagger.json Of URL, To change to the current project
const redocIndexHTML = `<!DOCTYPE html> <html> <head> <title>ReDoc Skin change successful </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"))
}

边栏推荐
- Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
- “山东大学移动互联网开发技术教学网站建设”项目实训日志二
- 华为2020校招笔试编程题 看这篇就够了(上)
- 第五空间智能安全⼤赛真题----------PNG图⽚转换器
- The Platonic metauniverse advocated by musk has long been verified by platofarm
- Starfish OS: create a new paradigm of the meta universe with reality as the link
- 超简单集成HMS ML Kit 实现parental control
- DeFi 2.0的LaaS协议,重振DeFi赛道发展的关键
- 裸金属云FASS高性能弹性块存储解决方案
- Thinkphp6管道模式Pipeline使用
猜你喜欢

php写一个购买全网最低价的纸尿裤

实现table某个单元格背景色设置

Sqlmap是什么以及使用方法

Installation steps and environment configuration of vs Code

山寨币SHIB 在 ETH 鲸鱼的投资组合中拥有 5.486 亿美元的股份——交易者应提防……

Wechat applet - component parameter transmission, state management

Common prompt pop-up box of uniapp

DAO赛道异军突起,M-DAO的优势在哪里?

如何 Pr 一个开源composer项目

与多家机构战略合作,背后彰显PlatoFarm元宇宙龙头的实力
随机推荐
Detailed steps of JDBC connection to database
“山东大学移动互联网开发技术教学网站建设”项目实训日志一
DAY13:文件上传漏洞
Go|Gin 快速使用Swagger
突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘
Seay源代码审计系统
OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程
php写一个购买全网最低价的纸尿裤
Wechat applet - component parameter transmission, state management
Wapiti是什么以及使用教程
Elastic box flex
Move protocol global health declaration, carry out the health campaign to the end
Crypto giants all in metauniverse, and platofarm may break through
Win10 搭建MSYS2环境
The bear market is slow, and bit.store provides stable stacking products to help you get through the bull and bear market
Wechat applet change attribute value -setdata- bidirectional binding -model
加密资产熊市之下,PlatoFarm的策略玩法依旧能获得稳定收益
Qt设置背景图片方法
DAY5:PHP 简单语法与使用
Detailed explanation of typical application code of C language array - master enters by mistake (step-by-step code explanation)
