From 0004bb6f6ca01d78009bde09d4fcdc1bd56bd592 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 3 Sep 2024 15:21:02 -0700 Subject: [PATCH] fix: use relative path for openapi handler (#2820) * fix: use relative path for openapi handler * discard error --- docs/openapi/openapi.go | 24 ++++++--------------- docs/openapi/{template.tpl => openapi.html} | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) rename docs/openapi/{template.tpl => openapi.html} (94%) diff --git a/docs/openapi/openapi.go b/docs/openapi/openapi.go index 187dbbe7ce..eba900acb5 100644 --- a/docs/openapi/openapi.go +++ b/docs/openapi/openapi.go @@ -2,22 +2,21 @@ package openapi import ( "embed" - "html/template" "net/http" "github.com/gorilla/mux" ) const ( - apiFile = "openapi.swagger.yaml" - templateFile = "template.tpl" + apiFile = "openapi.swagger.yaml" + htmlFile = "openapi.html" ) //go:embed openapi.swagger.yaml var staticFS embed.FS -//go:embed template.tpl -var templateFS embed.FS +//go:embed openapi.html +var html []byte func RegisterOpenAPIService(router *mux.Router) { router.Handle("/"+apiFile, http.FileServer(http.FS(staticFS))) @@ -25,19 +24,8 @@ func RegisterOpenAPIService(router *mux.Router) { } func openAPIHandler() http.HandlerFunc { - tmpl, err := template.ParseFS(templateFS, templateFile) - if err != nil { - panic(err) - } - return func(w http.ResponseWriter, _ *http.Request) { - err := tmpl.Execute(w, struct { - URL string - }{ - "/" + apiFile, - }) - if err != nil { - http.Error(w, "Failed to render template", http.StatusInternalServerError) - } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + _, _ = w.Write(html) } } diff --git a/docs/openapi/template.tpl b/docs/openapi/openapi.html similarity index 94% rename from docs/openapi/template.tpl rename to docs/openapi/openapi.html index 63b89df478..37fbfb2a16 100644 --- a/docs/openapi/template.tpl +++ b/docs/openapi/openapi.html @@ -20,7 +20,7 @@