Added swagger themes

This commit is contained in:
2022-11-30 16:46:55 +01:00
parent b6e8d037a0
commit 0ff1188c3d
10 changed files with 11878 additions and 12 deletions

View File

@@ -62,7 +62,8 @@ func (r *Router) Init(e *gin.Engine) {
{ {
docs.GET("/swagger", ginext.RedirectTemporary("/documentation/swagger/")) docs.GET("/swagger", ginext.RedirectTemporary("/documentation/swagger/"))
docs.GET("/swagger/", ginresp.Wrap(swagger.Handle)) docs.GET("/swagger/", ginresp.Wrap(swagger.Handle))
docs.GET("/swagger/:fn", ginresp.Wrap(swagger.Handle)) docs.GET("/swagger/:fn1", ginresp.Wrap(swagger.Handle))
docs.GET("/swagger/:fn1/:fn2", ginresp.Wrap(swagger.Handle))
} }
// ================ Website ================ // ================ Website ================

View File

@@ -5,6 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>API Documentation</title> <title>API Documentation</title>
<link rel="stylesheet" href="swagger-ui.css" /> <link rel="stylesheet" href="swagger-ui.css" />
<!-- <link rel="stylesheet" href="themes/theme-feeling-blue.css" /> -->
<!-- <link rel="stylesheet" href="themes/theme-flattop.css" /> -->
<!-- <link rel="stylesheet" href="themes/theme-material.css" /> -->
<!-- <link rel="stylesheet" href="themes/theme-monokai.css" /> -->
<!-- <link rel="stylesheet" href="themes/theme-muted.css" /> -->
<!-- <link rel="stylesheet" href="themes/theme-newspaper.css" /> -->
<!-- <link rel="stylesheet" href="themes/theme-outline.css" /> -->
</head> </head>
<body> <body>
<div id="swagger-ui"></div> <div id="swagger-ui"></div>
@@ -19,7 +26,8 @@
SwaggerUIBundle.presets.apis, SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset SwaggerUIStandalonePreset
], ],
layout: "StandaloneLayout" layout: "StandaloneLayout",
defaultModelsExpandDepth: 0,
}); });
}; };
</script> </script>

View File

@@ -9,12 +9,12 @@ import (
"strings" "strings"
) )
//go:embed index.html //go:embed *.html
//go:embed swagger.json //go:embed *.json
//go:embed swagger.yaml //go:embed *.yaml
//go:embed swagger-ui-bundle.js //go:embed *.js
//go:embed swagger-ui.css //go:embed *.css
//go:embed swagger-ui-standalone-preset.js //go:embed themes/*
var assets embed.FS var assets embed.FS
func getAsset(fn string) ([]byte, string, bool) { func getAsset(fn string) ([]byte, string, bool) {
@@ -47,7 +47,8 @@ func getAsset(fn string) ([]byte, string, bool) {
func Handle(g *gin.Context) ginresp.HTTPResponse { func Handle(g *gin.Context) ginresp.HTTPResponse {
type uri struct { type uri struct {
Filename string `uri:"fn"` Filename1 string `uri:"fn1"`
Filename2 *string `uri:"fn2"`
} }
var u uri var u uri
@@ -55,14 +56,19 @@ func Handle(g *gin.Context) ginresp.HTTPResponse {
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
} }
if u.Filename == "" { filename := u.Filename1
if u.Filename2 != nil {
filename = filename + "/" + *u.Filename2
}
if filename == "" {
index, _, _ := getAsset("index.html") index, _, _ := getAsset("index.html")
return ginresp.Data(http.StatusOK, "text/html", index) return ginresp.Data(http.StatusOK, "text/html", index)
} }
if data, mime, ok := getAsset(u.Filename); ok { if data, mime, ok := getAsset(filename); ok {
return ginresp.Data(http.StatusOK, mime, data) return ginresp.Data(http.StatusOK, mime, data)
} }
return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": u.Filename}) return ginresp.JSON(http.StatusNotFound, gin.H{"error": "AssetNotFound", "filename": filename, "filename1": u.Filename1, "filename2": u.Filename2})
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff