当前位置:网站首页>焕然一新,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"))
}

边栏推荐
猜你喜欢
![[typescript] learn typescript object types in depth](/img/87/a9fd2f177331863e06fcf14559eeed.png)
[typescript] learn typescript object types in depth

HCIA-R&S自用笔记(25)NAT技术背景、NAT类型及配置

第三课threejs全景预览房间案例

shell基本操作(上)
![[JS question solution] questions 1-10 in JS of niuke.com](/img/9d/4bae4a9a048e4e5412f157ec632c94.png)
[JS question solution] questions 1-10 in JS of niuke.com

【JS题解】牛客网JS篇1-10题

eggjs 创建应用知识点

Introduction to C language array to proficiency (array elaboration)

如何 Pr 一个开源composer项目

Clickhouse learning (IV) SQL operation
随机推荐
用sql-client.sh生成的job在cancle过后 如何实现断点续传?
Day 2
Basic use of redis
js简单代码判断打开页面的设备是电脑PC端或手机H5端或微信端
Set the background color of a cell in the table
shell基本操作(下)
Playwright实战案例之爬取js加密数据
What is sqlmap and how to use it
[C language series] - storage of deep anatomical data in memory (I) opening of summer vacation
Realize simple database query (incomplete)
Wapiti是什么以及使用教程
【TypeScript】深入学习TypeScript对象类型
link与@import导入外部样式的区别
HCIA-R&S自用笔记(24)ACL
ClickHouse学习(九)clickhouse整合mysql
Record the SQL injection vulnerability of XX company
Common characteristic engineering operations
Clickhouse learning (VI) grammar optimization
Hcia-r & s self use notes (27) comprehensive experiment
ClickHouse学习(六)语法优化
