From 6300885f691553522e226f2008f78f46abe6e7cd Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Fri, 29 May 2026 20:53:01 +0530 Subject: [PATCH 1/2] refactor: moves swagger ui html code to a separate file and embeds it Signed-off-by: Amit Singh --- api/source-score.yaml | 1 + pkg/handlers/swagger-ui.html | 96 ++++++++++++++++++++++++++++++++++++ pkg/handlers/swagger.go | 55 +++------------------ 3 files changed, 103 insertions(+), 49 deletions(-) create mode 100644 pkg/handlers/swagger-ui.html diff --git a/api/source-score.yaml b/api/source-score.yaml index bbca590..23e8068 100644 --- a/api/source-score.yaml +++ b/api/source-score.yaml @@ -522,6 +522,7 @@ components: required: true schema: type: string + default: swagger-ui description: Client identifier for authentication schemas: diff --git a/pkg/handlers/swagger-ui.html b/pkg/handlers/swagger-ui.html new file mode 100644 index 0000000..36ef641 --- /dev/null +++ b/pkg/handlers/swagger-ui.html @@ -0,0 +1,96 @@ + + + + + Source Score API Documentation + + + + + +
+ + + + + \ No newline at end of file diff --git a/pkg/handlers/swagger.go b/pkg/handlers/swagger.go index 45e0f8c..30b40b6 100644 --- a/pkg/handlers/swagger.go +++ b/pkg/handlers/swagger.go @@ -1,6 +1,7 @@ package handlers import ( + _ "embed" "net/http" "github.com/gin-gonic/gin" @@ -10,6 +11,11 @@ type SwaggerHandler struct { specFile []byte } +var ( + //go:embed "swagger-ui.html" + html string +) + func NewSwaggerHandler(specFile []byte) *SwaggerHandler { return &SwaggerHandler{ specFile: specFile, @@ -21,54 +27,5 @@ func (h *SwaggerHandler) ServeSpec(c *gin.Context) { } func (h *SwaggerHandler) ServeUI(c *gin.Context) { - html := ` - - - - Source Score API Documentation - - - - -
- - - - -` c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(html)) } From 282e5bd8f02497db204d6a2f522fb44fe865f65a Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Fri, 29 May 2026 21:20:49 +0530 Subject: [PATCH 2/2] feat: improves swagger ui auth ux Signed-off-by: Amit Singh --- pkg/handlers/swagger-ui.html | 191 ++++++++++++++++++++++------------- 1 file changed, 121 insertions(+), 70 deletions(-) diff --git a/pkg/handlers/swagger-ui.html b/pkg/handlers/swagger-ui.html index 36ef641..0f8553a 100644 --- a/pkg/handlers/swagger-ui.html +++ b/pkg/handlers/swagger-ui.html @@ -1,96 +1,147 @@ + - + Source Score API Documentation - + + -
- - + + crossorigin="anonymous"> + + \ No newline at end of file