fix: serve doc.json via swag.ReadDoc in SwaggerHandler
Some checks failed
CI / Build & Test (push) Has been cancelled
Some checks failed
CI / Build & Test (push) Has been cancelled
The custom SwaggerHandler was missing doc.json, causing Swagger UI to fail loading the API specification.
This commit is contained in:
parent
ec352306f1
commit
f44fcbafa7
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
"github.com/swaggo/swag"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -24,6 +25,16 @@ func SwaggerHandler() gin.HandlerFunc {
|
||||
|
||||
isCSS := strings.HasSuffix(relPath, "swagger-ui.css")
|
||||
isInitializer := strings.HasSuffix(relPath, "swagger-initializer.js")
|
||||
isDocJSON := strings.HasSuffix(relPath, "doc.json")
|
||||
|
||||
if isDocJSON {
|
||||
doc := swag.ReadDoc()
|
||||
c.Header("Content-Type", "application/json; charset=utf-8")
|
||||
c.Writer.WriteHeader(200)
|
||||
c.Writer.Write([]byte(doc))
|
||||
c.Request.URL.Path = rawPath
|
||||
return
|
||||
}
|
||||
|
||||
if isInitializer {
|
||||
c.Header("Content-Type", "application/javascript; charset=utf-8")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user