Merge pull request #4 from Canecat/bugfix/oauth2RedirectUrl-param-added

Bugfix/oauth2 redirect url param added
This commit is contained in:
Canecat 2019-11-28 14:29:03 +02:00 committed by GitHub
commit c7f15266cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -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