Skip to content

Commit b3b2d1f

Browse files
authored
Add support for swagger-ui persist-authorization (#2)
1 parent e66b861 commit b3b2d1f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

swagger.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616
// Config stores echoSwagger configuration variables.
1717
type Config struct {
1818
// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `mockedSwag.json`.
19-
URL string
20-
DeepLinking bool
21-
DocExpansion string
22-
DomID string
19+
URL string
20+
DeepLinking bool
21+
DocExpansion string
22+
DomID string
23+
PersistAuthorization bool
2324
}
2425

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

54+
// If set to true, it persists authorization data and it would not be lost on browser close/refresh
55+
// Defaults to false
56+
func PersistAuthorization(persistAuthorization bool) func(c *Config) {
57+
return func(c *Config) {
58+
c.PersistAuthorization = persistAuthorization
59+
}
60+
}
61+
5362
// WrapHandler wraps swaggerFiles.Handler and returns echo.HandlerFunc
5463
var WrapHandler = FiberWrapHandler()
5564

@@ -196,6 +205,7 @@ window.onload = function() {
196205
deepLinking: {{.DeepLinking}},
197206
docExpansion: "{{.DocExpansion}}",
198207
dom_id: "{{.DomID}}",
208+
persistAuthorization: {{.PersistAuthorization}},
199209
validatorUrl: null,
200210
presets: [
201211
SwaggerUIBundle.presets.apis,

swagger_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,11 @@ func TestDomID(t *testing.T) {
307307
configFunc(&cfg)
308308
assert.Equal(t, expected, cfg.DomID)
309309
}
310+
311+
func TestPersistAuthorization(t *testing.T) {
312+
expected := true
313+
cfg := Config{}
314+
configFunc := PersistAuthorization(expected)
315+
configFunc(&cfg)
316+
assert.Equal(t, expected, cfg.PersistAuthorization)
317+
}

0 commit comments

Comments
 (0)