Skip to content

Commit

Permalink
Add support for swagger-ui persist-authorization (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuklyy authored Feb 6, 2022
1 parent e66b861 commit b3b2d1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 14 additions & 4 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
// Config stores echoSwagger configuration variables.
type Config struct {
// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `mockedSwag.json`.
URL string
DeepLinking bool
DocExpansion string
DomID string
URL string
DeepLinking bool
DocExpansion string
DomID string
PersistAuthorization bool
}

// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
Expand Down Expand Up @@ -50,6 +51,14 @@ func DomID(domID string) func(c *Config) {
}
}

// If set to true, it persists authorization data and it would not be lost on browser close/refresh
// Defaults to false
func PersistAuthorization(persistAuthorization bool) func(c *Config) {
return func(c *Config) {
c.PersistAuthorization = persistAuthorization
}
}

// WrapHandler wraps swaggerFiles.Handler and returns echo.HandlerFunc
var WrapHandler = FiberWrapHandler()

Expand Down Expand Up @@ -196,6 +205,7 @@ window.onload = function() {
deepLinking: {{.DeepLinking}},
docExpansion: "{{.DocExpansion}}",
dom_id: "{{.DomID}}",
persistAuthorization: {{.PersistAuthorization}},
validatorUrl: null,
presets: [
SwaggerUIBundle.presets.apis,
Expand Down
8 changes: 8 additions & 0 deletions swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,11 @@ func TestDomID(t *testing.T) {
configFunc(&cfg)
assert.Equal(t, expected, cfg.DomID)
}

func TestPersistAuthorization(t *testing.T) {
expected := true
cfg := Config{}
configFunc := PersistAuthorization(expected)
configFunc(&cfg)
assert.Equal(t, expected, cfg.PersistAuthorization)
}

0 comments on commit b3b2d1f

Please sign in to comment.