Swagger UI updates
@@ -11,7 +11,9 @@ import (
)
const (
- swaggerUIDefaultURL = `https://petstore.swagger.io/v2/swagger.json`
+ swaggerUIDocName = `redoc.standalone.js`
+ swaggerUIDocNamePlaceHolder = `{SwaggerUIDocName}`
+ swaggerUIDocURLPlaceHolder = `{SwaggerUIDocUrl}`
swaggerUITemplate = `
<!DOCTYPE html>
<html>
@@ -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()
}
}
