feat: add ShowCommonExtensions option
This commit is contained in:
parent
aa92a0ac3f
commit
4672a89b2f
|
|
@ -204,3 +204,4 @@ func main() {
|
|||
| 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_). |
|
||||
| PersistAuthorization | bool | false | If set to true, it persists authorization data and it would not be lost on browser close/refresh. |
|
||||
| Oauth2DefaultClientID | string | "" | If set, it's used to prepopulate the _client_id_ field of the OAuth2 Authorization dialog. |
|
||||
| ShowCommonExtensions | bool | false | Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters. |
|
||||
14
swagger.go
14
swagger.go
|
|
@ -24,6 +24,7 @@ type swaggerConfig struct {
|
|||
DeepLinking bool
|
||||
PersistAuthorization bool
|
||||
Oauth2DefaultClientID string
|
||||
ShowCommonExtensions bool
|
||||
}
|
||||
|
||||
// Config stores ginSwagger configuration variables.
|
||||
|
|
@ -37,6 +38,7 @@ type Config struct {
|
|||
DeepLinking bool
|
||||
PersistAuthorization bool
|
||||
Oauth2DefaultClientID string
|
||||
ShowCommonExtensions bool
|
||||
}
|
||||
|
||||
func (config Config) toSwaggerConfig() swaggerConfig {
|
||||
|
|
@ -51,6 +53,7 @@ func (config Config) toSwaggerConfig() swaggerConfig {
|
|||
Title: config.Title,
|
||||
PersistAuthorization: config.PersistAuthorization,
|
||||
Oauth2DefaultClientID: config.Oauth2DefaultClientID,
|
||||
ShowCommonExtensions: config.ShowCommonExtensions,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +109,13 @@ func Oauth2DefaultClientID(oauth2DefaultClientID string) func(*Config) {
|
|||
}
|
||||
}
|
||||
|
||||
// ShowCommonExtensions set the swagger show common extensions configuration.
|
||||
func ShowCommonExtensions(showCommonExtensions bool) func(*Config) {
|
||||
return func(c *Config) {
|
||||
c.ShowCommonExtensions = showCommonExtensions
|
||||
}
|
||||
}
|
||||
|
||||
// WrapHandler wraps `http.Handler` into `gin.HandlerFunc`.
|
||||
func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerFunc {
|
||||
var config = Config{
|
||||
|
|
@ -117,6 +127,7 @@ func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerF
|
|||
DeepLinking: true,
|
||||
PersistAuthorization: false,
|
||||
Oauth2DefaultClientID: "",
|
||||
ShowCommonExtensions: false,
|
||||
}
|
||||
|
||||
for _, c := range options {
|
||||
|
|
@ -267,7 +278,8 @@ window.onload = function() {
|
|||
layout: "StandaloneLayout",
|
||||
docExpansion: "{{.DocExpansion}}",
|
||||
deepLinking: {{.DeepLinking}},
|
||||
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
|
||||
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}},
|
||||
showCommonExtensions: {{.ShowCommonExtensions}}
|
||||
})
|
||||
|
||||
const defaultClientId = "{{.Oauth2DefaultClientID}}";
|
||||
|
|
|
|||
|
|
@ -254,3 +254,17 @@ func TestOauth2DefaultClientID(t *testing.T) {
|
|||
configFunc(&cfg)
|
||||
assert.Equal(t, "", cfg.Oauth2DefaultClientID)
|
||||
}
|
||||
|
||||
func TestShowCommonExtensions(t *testing.T) {
|
||||
var cfg Config
|
||||
assert.Equal(t, false, cfg.ShowCommonExtensions)
|
||||
|
||||
configFunc := ShowCommonExtensions(true)
|
||||
configFunc(&cfg)
|
||||
assert.Equal(t, true, cfg.ShowCommonExtensions)
|
||||
|
||||
configFunc = ShowCommonExtensions(false)
|
||||
configFunc(&cfg)
|
||||
assert.Equal(t, false, cfg.ShowCommonExtensions)
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue