fix: strip /swagger prefix for swaggerFiles.Handler path resolution
Some checks failed
CI / Build & Test (push) Failing after 42s

This commit is contained in:
MengStack Dev 2026-10-03 04:09:25 +08:00
parent 98256f1f54
commit d26f5962ed

View File

@ -16,7 +16,15 @@ import (
// branding CSS injected into swagger-ui.css.
func SwaggerHandler() gin.HandlerFunc {
return func(c *gin.Context) {
isCSS := strings.HasSuffix(c.Request.URL.Path, "swagger-ui.css")
rawPath := c.Request.URL.Path
relPath := strings.TrimPrefix(rawPath, "/swagger")
if relPath == "" || relPath == "/" {
relPath = "/index.html"
}
c.Request.URL.Path = relPath
defer func() { c.Request.URL.Path = rawPath }()
isCSS := strings.HasSuffix(relPath, "swagger-ui.css")
underlying := c.Writer
crw := &captureResponseWriter{