Skip to content

Commit

Permalink
feat: add defaultModelsExpandDepth for SwaggerUIBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
lzw9935 committed Apr 30, 2024
1 parent aa92a0a commit fc5ec3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
14 changes: 13 additions & 1 deletion swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type swaggerConfig struct {
Title string
Oauth2RedirectURL htmlTemplate.JS
DefaultModelsExpandDepth int
DefaultModelExpandDepth int
DeepLinking bool
PersistAuthorization bool
Oauth2DefaultClientID string
Expand All @@ -34,6 +35,7 @@ type Config struct {
InstanceName string
Title string
DefaultModelsExpandDepth int
DefaultModelExpandDepth int
DeepLinking bool
PersistAuthorization bool
Oauth2DefaultClientID string
Expand All @@ -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`",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -267,7 +278,8 @@ window.onload = function() {
layout: "StandaloneLayout",
docExpansion: "{{.DocExpansion}}",
deepLinking: {{.DeepLinking}},
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}},
defaultModelExpandDepth: {{.DefaultModelExpandDepth}}
})
const defaultClientId = "{{.Oauth2DefaultClientID}}";
Expand Down

0 comments on commit fc5ec3d

Please sign in to comment.