diff --git a/gateway/main.go b/gateway/main.go index 138cc56..180a08a 100644 --- a/gateway/main.go +++ b/gateway/main.go @@ -8,16 +8,21 @@ import ( "context" "crypto/ecdsa" "crypto/sha256" + "embed" "encoding/base64" "encoding/hex" "encoding/json" "errors" "fmt" + "html/template" "io" "log" "net/http" "os" + + "regexp" "runtime" + "strconv" "strings" "sync" @@ -30,6 +35,23 @@ import ( "github.com/joho/godotenv" ) +//go:embed templates/swagger.html +var swaggerTemplateFS embed.FS + +var swaggerTmpl = template.Must( + template.ParseFS(swaggerTemplateFS, "templates/swagger.html"), +) + +var swaggerVersionRe = regexp.MustCompile(`^\d+\.\d+\.\d+$`) + +func getSwaggerUIVersion() string { + v := os.Getenv("SWAGGER_UI_VERSION") + if swaggerVersionRe.MatchString(v) { + return v + } + return "5.11.0" +} + type PaymentContext struct { Recipient string `json:"recipient"` Token string `json:"token"` @@ -123,26 +145,18 @@ func main() { r.StaticFile("/openapi.yaml", "openapi.yaml") r.GET("/docs", func(c *gin.Context) { - c.Header("Content-Type", "text/html") - c.String(200, ` - - - - MicroAI Paygate Docs - - - -
- - - - -`) + data := struct { + Version string + }{ + Version: getSwaggerUIVersion(), + } + + c.Header("Content-Type", "text/html; charset=utf-8") + + if err := swaggerTmpl.Execute(c.Writer, data); err != nil { + c.String(500, "failed to render swagger ui") + return + } }) r.Use(cors.New(cors.Config{ diff --git a/gateway/templates/swagger.html b/gateway/templates/swagger.html new file mode 100644 index 0000000..98293fa --- /dev/null +++ b/gateway/templates/swagger.html @@ -0,0 +1,18 @@ + + + + MicroAI Paygate API Docs + + + +
+ + + + +