feat: implement deeplinking (#86)

This commit is contained in:
adibiarsotp
2019-11-28 12:27:09 +07:00
committed by Eason Lin
parent d488a69274
commit 3db8327ddb
+13 -1
View File
@@ -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