Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add defaultModelsExpandDepth for SwaggerUIBundle #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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