Skip to content

Commit

Permalink
feat: add support for swagger-ui persist-authorization (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuklyy authored Feb 6, 2022
1 parent 61746eb commit 0adeab6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 15 additions & 5 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ 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
InstanceName string
URL string
DeepLinking bool
DocExpansion string
DomID string
InstanceName string
PersistAuthorization bool
}

// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
Expand Down Expand Up @@ -58,6 +59,14 @@ func InstanceName(instanceName 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 = EchoWrapHandler()

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

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

0 comments on commit 0adeab6

Please sign in to comment.