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