diff --git a/swagger.go b/swagger.go index 988b1d7..293f291 100644 --- a/swagger.go +++ b/swagger.go @@ -18,6 +18,7 @@ type Config struct { //The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`. SpecFileName string SwaggerBase string + DeepLinking bool } // SwaggerBase sets the subpath of swagger router. Default is `swagger/`. @@ -34,11 +35,19 @@ func SpecFileName(specFileName 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{ SpecFileName: "doc.json", SwaggerBase: "swagger/", + DeepLinking: true, } for _, c := range confs { @@ -67,6 +76,7 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc { type swaggerUIBundle struct { URL string Oauth2RedirectURL string + DeepLinking bool } var matches []string @@ -94,6 +104,7 @@ func CustomWrapHandler(config *Config, h *webdav.Handler) gin.HandlerFunc { index.Execute(c.Writer, &swaggerUIBundle{ URL: filepath.Join(config.SwaggerBase, specFileName), Oauth2RedirectURL: filepath.Join(config.SwaggerBase, "oauth2-redirect.html"), + DeepLinking: config.DeepLinking, }) case specFileName: doc, err := swag.ReadDoc() @@ -215,8 +226,8 @@ window.onload = function() { const ui = SwaggerUIBundle({ url: "{{.URL}}", dom_id: '#swagger-ui', - validatorUrl: null, - oauth2RedirectUrl: "{{.Oauth2RedirectURL}}", + validatorUrl: null, + oauth2RedirectUrl: "{{.Oauth2RedirectURL}}", presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset @@ -224,7 +235,8 @@ window.onload = function() { plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], - layout: "StandaloneLayout" + layout: "StandaloneLayout", + deepLinking: {{.DeepLinking}} }) window.ui = ui