feat: implement deeplinking (#86)
This commit is contained in:
+17
-5
@@ -15,7 +15,8 @@ import (
|
|||||||
// Config stores ginSwagger configuration variables.
|
// Config stores ginSwagger configuration variables.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
//The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
|
//The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
|
||||||
URL string
|
URL string
|
||||||
|
DeepLinking bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
|
// 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`.
|
// WrapHandler wraps `http.Handler` into `gin.HandlerFunc`.
|
||||||
func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
||||||
defaultConfig := &Config{
|
defaultConfig := &Config{
|
||||||
URL: "doc.json",
|
URL: "doc.json",
|
||||||
|
DeepLinking: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range confs {
|
for _, c := range confs {
|
||||||
@@ -49,7 +58,8 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc {
|
|||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
type swaggerUIBundle struct {
|
type swaggerUIBundle struct {
|
||||||
URL string
|
URL string
|
||||||
|
DeepLinking bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var matches []string
|
var matches []string
|
||||||
@@ -75,7 +85,8 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc {
|
|||||||
switch path {
|
switch path {
|
||||||
case "index.html":
|
case "index.html":
|
||||||
index.Execute(c.Writer, &swaggerUIBundle{
|
index.Execute(c.Writer, &swaggerUIBundle{
|
||||||
URL: config.URL,
|
URL: config.URL,
|
||||||
|
DeepLinking: config.DeepLinking,
|
||||||
})
|
})
|
||||||
case "doc.json":
|
case "doc.json":
|
||||||
doc, err := swag.ReadDoc()
|
doc, err := swag.ReadDoc()
|
||||||
@@ -205,7 +216,8 @@ window.onload = function() {
|
|||||||
plugins: [
|
plugins: [
|
||||||
SwaggerUIBundle.plugins.DownloadUrl
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
],
|
],
|
||||||
layout: "StandaloneLayout"
|
layout: "StandaloneLayout",
|
||||||
|
deepLinking: {{.DeepLinking}}
|
||||||
})
|
})
|
||||||
|
|
||||||
window.ui = ui
|
window.ui = ui
|
||||||
|
|||||||
Reference in New Issue
Block a user