feat: add options to Config

add DefaultModelExpandDepth and DefaultModelRendering
see https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
This commit is contained in:
tholok 2025-11-06 12:17:15 +01:00
parent 2b8554dea5
commit 36b13ec9ce
2 changed files with 13 additions and 1 deletions

View File

@ -201,6 +201,8 @@ func main() {
| 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). | | 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. | | 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). | | DefaultModelsExpandDepth | int | 1 | Default expansion depth for models (set to -1 completely hide the models). |
| DefaultModelExpandDepth | int | 1 | Default expansion depth for the model on the model-example section. |
| DefaultModelRendering | string | "example" | Controls how the model is shown when the API is first rendered. "example" or "model". (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links.) |
| 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_). | | 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. | | 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. | | Oauth2DefaultClientID | string | "" | If set, it's used to prepopulate the _client_id_ field of the OAuth2 Authorization dialog. |

View File

@ -21,6 +21,8 @@ type swaggerConfig struct {
Title string Title string
Oauth2RedirectURL htmlTemplate.JS Oauth2RedirectURL htmlTemplate.JS
DefaultModelsExpandDepth int DefaultModelsExpandDepth int
DefaultModelExpandDepth int
DefaultModelRendering string
DeepLinking bool DeepLinking bool
PersistAuthorization bool PersistAuthorization bool
Oauth2DefaultClientID string Oauth2DefaultClientID string
@ -35,6 +37,8 @@ type Config struct {
InstanceName string InstanceName string
Title string Title string
DefaultModelsExpandDepth int DefaultModelsExpandDepth int
DefaultModelExpandDepth int
DefaultModelRendering string
DeepLinking bool DeepLinking bool
PersistAuthorization bool PersistAuthorization bool
Oauth2DefaultClientID string Oauth2DefaultClientID string
@ -47,6 +51,8 @@ func (config Config) toSwaggerConfig() swaggerConfig {
DeepLinking: config.DeepLinking, DeepLinking: config.DeepLinking,
DocExpansion: config.DocExpansion, DocExpansion: config.DocExpansion,
DefaultModelsExpandDepth: config.DefaultModelsExpandDepth, DefaultModelsExpandDepth: config.DefaultModelsExpandDepth,
DefaultModelExpandDepth: config.DefaultModelExpandDepth,
DefaultModelRendering: config.DefaultModelRendering,
Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" + Oauth2RedirectURL: "`${window.location.protocol}//${window.location.host}$" +
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" + "{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
"/oauth2-redirect.html`", "/oauth2-redirect.html`",
@ -126,6 +132,8 @@ func WrapHandler(handler *webdav.Handler, options ...func(*Config)) gin.HandlerF
InstanceName: swag.Name, InstanceName: swag.Name,
Title: "Swagger UI", Title: "Swagger UI",
DefaultModelsExpandDepth: 1, DefaultModelsExpandDepth: 1,
DefaultModelExpandDepth: 1,
DefaultModelRendering: "example",
DeepLinking: true, DeepLinking: true,
PersistAuthorization: false, PersistAuthorization: false,
Oauth2DefaultClientID: "", Oauth2DefaultClientID: "",
@ -280,7 +288,9 @@ window.onload = function() {
layout: "StandaloneLayout", layout: "StandaloneLayout",
docExpansion: "{{.DocExpansion}}", docExpansion: "{{.DocExpansion}}",
deepLinking: {{.DeepLinking}}, deepLinking: {{.DeepLinking}},
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}} defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}},
defaultModelExpandDepth: {{.DefaultModelExpandDepth}},
defaultModelRendering: "{{.DefaultModelRendering}}"
}) })
const defaultClientId = "{{.Oauth2DefaultClientID}}"; const defaultClientId = "{{.Oauth2DefaultClientID}}";