Unified · Split
| @@ -168,5 +168,6 @@ func main() { · 167 unmodified lines | ||
| 168 | 168 | | DocExpansion | 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). | |
| 169 | 169 | | DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. | |
| 170 | 170 | | DefaultModelsExpandDepth | int | 1 | Default expansion depth for models (set to -1 completely hide the models). | |
| 171 | −| 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_). | |
| 172 | −| PersistAuthotization | bool | false | If set to true, it persists authorization data and it would not be lost on browser close/refresh. | | |
| 171 | +| 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_). | | |
| 172 | +| PersistAuthorization | bool | false | If set to true, it persists authorization data and it would not be lost on browser close/refresh. | | |
| 173 | +| Oauth2DefaultClientID | string | "" | If set, it's used to prepopulate the *client_id* field of the OAuth2 Authorization dialog. | | |
| @@ -22,6 +22,7 @@ type swaggerConfig struct { · 21 unmodified lines | ||
| 22 | 22 | DefaultModelsExpandDepth int |
| 23 | 23 | DeepLinking bool |
| 24 | 24 | PersistAuthorization bool |
| 25 | + Oauth2DefaultClientID string | |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | // Config stores ginSwagger configuration variables. |
| @@ -34,6 +35,7 @@ type Config struct { · 6 unmodified lines | ||
| 34 | 35 | DefaultModelsExpandDepth int |
| 35 | 36 | DeepLinking bool |
| 36 | 37 | PersistAuthorization bool |
| 38 | + Oauth2DefaultClientID string | |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | func (config Config) toSwaggerConfig() swaggerConfig { |
| @@ -45,8 +47,9 @@ func (config Config) toSwaggerConfig() swaggerConfig { · 5 unmodified lines | ||
| 45 | 47 | Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" + |
| 46 | 48 | "{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" + |
| 47 | 49 | "/oauth2-redirect.html`", |
| 48 | − Title: config.Title, | |
| 49 | − PersistAuthorization: config.PersistAuthorization, | |
| 50 | + Title: config.Title, | |
| 51 | + PersistAuthorization: config.PersistAuthorization, | |
| 52 | + Oauth2DefaultClientID: config.Oauth2DefaultClientID, | |
| 50 | 53 | } |
| 51 | 54 | } |
| 52 | 55 | |
| @@ -95,6 +98,13 @@ func PersistAuthorization(persistAuthorization bool) func(*Config) { · 42 unmodified lines | ||
| 95 | 98 | } |
| 96 | 99 | } |
| 97 | 100 | |
| 101 | +// Oauth2DefaultClientID set the default client ID used for OAuth2 | |
| 102 | +func Oauth2DefaultClientID(oauth2DefaultClientID string) func(*Config) { | |
| 103 | + return func(c *Config) { | |
| 104 | + c.Oauth2DefaultClientID = oauth2DefaultClientID | |
| 105 | + } | |
| 106 | +} | |
| 107 | + | |
| 98 | 108 | // WrapHandler wraps `http.Handler` into `gin.HandlerFunc`. |
| 99 | 109 | func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerFunc { |
| 100 | 110 | var config = Config{ |
| @@ -105,6 +115,7 @@ func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerF · 4 unmodified lines | ||
| 105 | 115 | DefaultModelsExpandDepth: 1, |
| 106 | 116 | DeepLinking: true, |
| 107 | 117 | PersistAuthorization: false, |
| 118 | + Oauth2DefaultClientID: "", | |
| 108 | 119 | } |
| 109 | 120 | |
| 110 | 121 | for _, c := range options { |
| @@ -303,6 +314,13 @@ window.onload = function() { · 192 unmodified lines | ||
| 303 | 314 | defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}} |
| 304 | 315 | }) |
| 305 | 316 | |
| 317 | + const defaultClientId = "{{.Oauth2DefaultClientID}}"; | |
| 318 | + if (defaultClientId) { | |
| 319 | + ui.initOAuth({ | |
| 320 | + clientId: defaultClientId | |
| 321 | + }) | |
| 322 | + } | |
| 323 | + | |
| 306 | 324 | window.ui = ui |
| 307 | 325 | } |
| 308 | 326 | </script> |
| @@ -233,3 +233,16 @@ func TestPersistAuthorization(t *testing.T) { · 232 unmodified lines | ||
| 233 | 233 | configFunc(&cfg) |
| 234 | 234 | assert.Equal(t, false, cfg.PersistAuthorization) |
| 235 | 235 | } |
| 236 | + | |
| 237 | +func TestOauth2DefaultClientID(t *testing.T) { | |
| 238 | + var cfg Config | |
| 239 | + assert.Equal(t, "", cfg.Oauth2DefaultClientID) | |
| 240 | + | |
| 241 | + configFunc := Oauth2DefaultClientID("default_client_id") | |
| 242 | + configFunc(&cfg) | |
| 243 | + assert.Equal(t, "default_client_id", cfg.Oauth2DefaultClientID) | |
| 244 | + | |
| 245 | + configFunc = Oauth2DefaultClientID("") | |
| 246 | + configFunc(&cfg) | |
| 247 | + assert.Equal(t, "", cfg.Oauth2DefaultClientID) | |
| 248 | +} | |