Skip to content

Commit fc5ec3d

Browse files
committed
feat: add defaultModelsExpandDepth for SwaggerUIBundle
1 parent aa92a0a commit fc5ec3d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ func main() {
195195
}
196196
```
197197

198-
| Option | Type | Default | Description |
199-
| ------------------------ | ------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200-
| URL | string | "doc.json" | URL pointing to API definition |
201-
| 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). |
202-
| DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. |
198+
| Option | Type | Default | Description |
199+
| ----------------------- | ------ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
200+
| URL | string | "doc.json" | URL pointing to API definition |
201+
| 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). |
202+
| DeepLinking | bool | true | If set to true, enables deep linking for tags and operations. See the Deep Linking documentation for more information. |
203203
| DefaultModelsExpandDepth | int | 1 | Default expansion depth for models (set to -1 completely hide the models). |
204-
| 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_). |
205-
| PersistAuthorization | bool | false | If set to true, it persists authorization data and it would not be lost on browser close/refresh. |
206-
| Oauth2DefaultClientID | string | "" | If set, it's used to prepopulate the _client_id_ field of the OAuth2 Authorization dialog. |
204+
| DefaultModelExpandDepth | int | 1 | The default expansion depth for the model on the model-example section. |
205+
| 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_). |
206+
| PersistAuthorization | bool | false | If set to true, it persists authorization data and it would not be lost on browser close/refresh. |
207+
| Oauth2DefaultClientID | string | "" | If set, it's used to prepopulate the _client_id_ field of the OAuth2 Authorization dialog. |

swagger.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type swaggerConfig struct {
2121
Title string
2222
Oauth2RedirectURL htmlTemplate.JS
2323
DefaultModelsExpandDepth int
24+
DefaultModelExpandDepth int
2425
DeepLinking bool
2526
PersistAuthorization bool
2627
Oauth2DefaultClientID string
@@ -34,6 +35,7 @@ type Config struct {
3435
InstanceName string
3536
Title string
3637
DefaultModelsExpandDepth int
38+
DefaultModelExpandDepth int
3739
DeepLinking bool
3840
PersistAuthorization bool
3941
Oauth2DefaultClientID string
@@ -45,6 +47,7 @@ func (config Config) toSwaggerConfig() swaggerConfig {
4547
DeepLinking: config.DeepLinking,
4648
DocExpansion: config.DocExpansion,
4749
DefaultModelsExpandDepth: config.DefaultModelsExpandDepth,
50+
DefaultModelExpandDepth: config.DefaultModelExpandDepth,
4851
Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" +
4952
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
5053
"/oauth2-redirect.html`",
@@ -83,6 +86,13 @@ func DefaultModelsExpandDepth(depth int) func(*Config) {
8386
}
8487
}
8588

89+
// DefaultModelExpandDepth set the default expansion depth for the model on the model-example section
90+
func DefaultModelExpandDepth(depth int) func(*Config) {
91+
return func(c *Config) {
92+
c.DefaultModelExpandDepth = depth
93+
}
94+
}
95+
8696
// InstanceName set the instance name that was used to generate the swagger documents
8797
// Defaults to swag.Name ("swagger").
8898
func InstanceName(name string) func(*Config) {
@@ -114,6 +124,7 @@ func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerF
114124
InstanceName: swag.Name,
115125
Title: "Swagger UI",
116126
DefaultModelsExpandDepth: 1,
127+
DefaultModelExpandDepth: 1,
117128
DeepLinking: true,
118129
PersistAuthorization: false,
119130
Oauth2DefaultClientID: "",
@@ -267,7 +278,8 @@ window.onload = function() {
267278
layout: "StandaloneLayout",
268279
docExpansion: "{{.DocExpansion}}",
269280
deepLinking: {{.DeepLinking}},
270-
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
281+
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}},
282+
defaultModelExpandDepth: {{.DefaultModelExpandDepth}}
271283
})
272284
273285
const defaultClientId = "{{.Oauth2DefaultClientID}}";

0 commit comments

Comments
 (0)