diff --git a/README.md b/README.md index 9c20ddd..8047730 100644 --- a/README.md +++ b/README.md @@ -195,12 +195,13 @@ func main() { } ``` -| Option | Type | Default | Description | -| ------------------------ | ------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| URL | string | "doc.json" | URL pointing to API definition | -| 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). | -| DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. | +| Option | Type | Default | Description | +| ----------------------- | ------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| URL | string | "doc.json" | URL pointing to API definition | +| 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). | +| 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). | -| 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. | +| DefaultModelExpandDepth | int | 1 | The default expansion depth for the model on the model-example section. | +| 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. | diff --git a/swagger.go b/swagger.go index 9206c78..b67ba99 100644 --- a/swagger.go +++ b/swagger.go @@ -21,6 +21,7 @@ type swaggerConfig struct { Title string Oauth2RedirectURL htmlTemplate.JS DefaultModelsExpandDepth int + DefaultModelExpandDepth int DeepLinking bool PersistAuthorization bool Oauth2DefaultClientID string @@ -34,6 +35,7 @@ type Config struct { InstanceName string Title string DefaultModelsExpandDepth int + DefaultModelExpandDepth int DeepLinking bool PersistAuthorization bool Oauth2DefaultClientID string @@ -45,6 +47,7 @@ func (config Config) toSwaggerConfig() swaggerConfig { DeepLinking: config.DeepLinking, DocExpansion: config.DocExpansion, DefaultModelsExpandDepth: config.DefaultModelsExpandDepth, + DefaultModelExpandDepth: config.DefaultModelExpandDepth, Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" + "{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" + "/oauth2-redirect.html`", @@ -83,6 +86,13 @@ func DefaultModelsExpandDepth(depth int) func(*Config) { } } +// DefaultModelExpandDepth set the default expansion depth for the model on the model-example section +func DefaultModelExpandDepth(depth int) func(*Config) { + return func(c *Config) { + c.DefaultModelExpandDepth = depth + } +} + // InstanceName set the instance name that was used to generate the swagger documents // Defaults to swag.Name ("swagger"). func InstanceName(name string) func(*Config) { @@ -114,6 +124,7 @@ func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerF InstanceName: swag.Name, Title: "Swagger UI", DefaultModelsExpandDepth: 1, + DefaultModelExpandDepth: 1, DeepLinking: true, PersistAuthorization: false, Oauth2DefaultClientID: "", @@ -267,7 +278,8 @@ window.onload = function() { layout: "StandaloneLayout", docExpansion: "{{.DocExpansion}}", deepLinking: {{.DeepLinking}}, - defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}} + defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}, + defaultModelExpandDepth: {{.DefaultModelExpandDepth}} }) const defaultClientId = "{{.Oauth2DefaultClientID}}";