feat: implement deeplinking (#86)
This commit is contained in:
+13
-1
@@ -16,6 +16,7 @@ import (
|
||||
type Config struct {
|
||||
//The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
|
||||
URL string
|
||||
DeepLinking bool
|
||||
}
|
||||
|
||||
// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
|
||||
@@ -25,10 +26,18 @@ func URL(url string) func(c *Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// DeepLinking set the swagger deeplinking configuration
|
||||
func DeepLinking(deepLinking bool) func(c *Config) {
|
||||
return func(c *Config) {
|
||||
c.DeepLinking = deepLinking
|
||||
}
|
||||
}
|
||||
|
||||
// WrapHandler wraps `http.Handler` into `gin.HandlerFunc`.
|
||||
func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
||||
defaultConfig := &Config{
|
||||
URL: "doc.json",
|
||||
DeepLinking: true,
|
||||
}
|
||||
|
||||
for _, c := range confs {
|
||||
@@ -50,6 +59,7 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc {
|
||||
|
||||
type swaggerUIBundle struct {
|
||||
URL string
|
||||
DeepLinking bool
|
||||
}
|
||||
|
||||
var matches []string
|
||||
@@ -76,6 +86,7 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc {
|
||||
case "index.html":
|
||||
index.Execute(c.Writer, &swaggerUIBundle{
|
||||
URL: config.URL,
|
||||
DeepLinking: config.DeepLinking,
|
||||
})
|
||||
case "doc.json":
|
||||
doc, err := swag.ReadDoc()
|
||||
@@ -205,7 +216,8 @@ window.onload = function() {
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
layout: "StandaloneLayout",
|
||||
deepLinking: {{.DeepLinking}}
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
|
||||
Reference in New Issue
Block a user