feat: add support for swagger-ui persist-authorization (#195)
This commit is contained in:
@@ -165,4 +165,5 @@ func main() {
|
|||||||
| DocExpantion | string | "list" | Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). |
|
| DocExpantion | string | "list" | Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing). |
|
||||||
| DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. |
|
| DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. |
|
||||||
| DefaultModelsExpandDepth | int | 1 | Default expansion depth for models (set to -1 completely hide the models). |
|
| DefaultModelsExpandDepth | int | 1 | Default expansion depth for models (set to -1 completely hide the models). |
|
||||||
| InstanceName | string | "swagger" | The instance name of the swagger document. If multiple different swagger instances should be deployed on one gin router, ensure that each instance has a unique name (use the _--instanceName_ parameter to generate swagger documents with _swag init_). |
|
| InstanceName | string | "swagger" | The instance name of the swagger document. If multiple different swagger instances should be deployed on one gin router, ensure that each instance has a unique name (use the _--instanceName_ parameter to generate swagger documents with _swag init_).
|
||||||
|
| PersistAuthotization | bool | false | If set to true, it persists authorization data and it would not be lost on browser close/refresh. |
|
||||||
|
|||||||
+13
-1
@@ -21,6 +21,7 @@ type swaggerConfig struct {
|
|||||||
DefaultModelsExpandDepth int
|
DefaultModelsExpandDepth int
|
||||||
Oauth2RedirectURL template.JS
|
Oauth2RedirectURL template.JS
|
||||||
Title string
|
Title string
|
||||||
|
PersistAuthorization bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config stores ginSwagger configuration variables.
|
// Config stores ginSwagger configuration variables.
|
||||||
@@ -32,6 +33,7 @@ type Config struct {
|
|||||||
DefaultModelsExpandDepth int
|
DefaultModelsExpandDepth int
|
||||||
InstanceName string
|
InstanceName string
|
||||||
Title string
|
Title string
|
||||||
|
PersistAuthorization bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the config to a swagger one in order to fill unexposed template values.
|
// Convert the config to a swagger one in order to fill unexposed template values.
|
||||||
@@ -46,7 +48,8 @@ func (c Config) ToSwaggerConfig() swaggerConfig {
|
|||||||
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
|
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
|
||||||
"/oauth2-redirect.html`",
|
"/oauth2-redirect.html`",
|
||||||
),
|
),
|
||||||
Title: c.Title,
|
Title: c.Title,
|
||||||
|
PersistAuthorization: c.PersistAuthorization,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +90,14 @@ func InstanceName(name 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 `http.Handler` into `gin.HandlerFunc`.
|
// WrapHandler wraps `http.Handler` into `gin.HandlerFunc`.
|
||||||
func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
||||||
defaultConfig := &Config{
|
defaultConfig := &Config{
|
||||||
@@ -275,6 +286,7 @@ window.onload = function() {
|
|||||||
dom_id: '#swagger-ui',
|
dom_id: '#swagger-ui',
|
||||||
validatorUrl: null,
|
validatorUrl: null,
|
||||||
oauth2RedirectUrl: {{.Oauth2RedirectURL}},
|
oauth2RedirectUrl: {{.Oauth2RedirectURL}},
|
||||||
|
persistAuthorization: {{.PersistAuthorization}},
|
||||||
presets: [
|
presets: [
|
||||||
SwaggerUIBundle.presets.apis,
|
SwaggerUIBundle.presets.apis,
|
||||||
SwaggerUIStandalonePreset
|
SwaggerUIStandalonePreset
|
||||||
|
|||||||
@@ -226,3 +226,16 @@ func TestInstanceName(t *testing.T) {
|
|||||||
configFunc(&cfg)
|
configFunc(&cfg)
|
||||||
assert.Equal(t, expected, cfg.InstanceName)
|
assert.Equal(t, expected, cfg.InstanceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPersistAuthorization(t *testing.T) {
|
||||||
|
var cfg Config
|
||||||
|
assert.Equal(t, false, cfg.PersistAuthorization)
|
||||||
|
|
||||||
|
configFunc := PersistAuthorization(true)
|
||||||
|
configFunc(&cfg)
|
||||||
|
assert.Equal(t, true, cfg.PersistAuthorization)
|
||||||
|
|
||||||
|
configFunc = PersistAuthorization(false)
|
||||||
|
configFunc(&cfg)
|
||||||
|
assert.Equal(t, false, cfg.PersistAuthorization)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user