mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
Swagger UI updates
This commit is contained in:
@ -11,8 +11,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
swaggerUIDefaultURL = `https://petstore.swagger.io/v2/swagger.json`
|
||||
swaggerUITemplate = `
|
||||
swaggerUIDocName = `redoc.standalone.js`
|
||||
swaggerUIDocNamePlaceHolder = `{SwaggerUIDocName}`
|
||||
swaggerUIDocURLPlaceHolder = `{SwaggerUIDocUrl}`
|
||||
swaggerUITemplate = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@ -27,8 +29,8 @@ const (
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<redoc spec-url="https://petstore.swagger.io/v2/swagger.json"></redoc>
|
||||
<script src="redoc.standalone.js"> </script>
|
||||
<redoc spec-url="{SwaggerUIDocUrl}"></redoc>
|
||||
<script src="{SwaggerUIDocName}"> </script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
@ -41,11 +43,11 @@ func (s *Server) swaggerUI(r *Request) {
|
||||
return
|
||||
}
|
||||
if r.StaticFile != nil && r.StaticFile.File != nil && r.StaticFile.IsDir {
|
||||
r.Response.Write(gstr.Replace(
|
||||
swaggerUITemplate,
|
||||
swaggerUIDefaultURL,
|
||||
s.config.OpenApiPath,
|
||||
))
|
||||
content := gstr.ReplaceByMap(swaggerUITemplate, map[string]string{
|
||||
swaggerUIDocURLPlaceHolder: s.config.OpenApiPath,
|
||||
swaggerUIDocNamePlaceHolder: gstr.TrimRight(r.GetUrl(), "/") + "/" + swaggerUIDocName,
|
||||
})
|
||||
r.Response.Write(content)
|
||||
r.ExitAll()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user