Skip to content

Support for persistAuthorization swagger ui #192

@kuklyy

Description

@kuklyy

For now apiKey (or any other authorization method) is lost after browser reload, so I have to provide it again.

Swagger UI provides an out of the box solution to this problem (documentation reference). I will provide code samples for gin-swagger. Similar changes should be introduced for other frameworks.
There is a quick solution for the project.
ginSwagger.Config and ginSwagger.ToSwaggerConfig should accept another parameter


// Config stores ginSwagger configuration variables.
type Config struct {
	//The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
	URL                      string
	DeepLinking              bool
	DocExpansion             string
	DefaultModelsExpandDepth int
	InstanceName             string
	Title                    string
	PersistAuthorization     bool
}

So lib can pass this value to SwaggerUIBundle


window.onload = function() {
  // Build a system
  const ui = SwaggerUIBundle({
    url: "{{.URL}}",
    persistAuthorization: {{.PersistAuthorization}},
    dom_id: '#swagger-ui',
    validatorUrl: null,
    oauth2RedirectUrl: {{.Oauth2RedirectURL}},
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout",
    docExpansion: "{{.DocExpansion}}",
    deepLinking: {{.DeepLinking}},
    defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
  })

  window.ui = ui
}

I can provide pull request if you found this feature should be available in your library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions