swaggerui

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

SwaggerUI

Provide http.Handler with SwaggerUI embed, and configurable.

Example

package main

import (
    "gopkg.org/swaggerui"
)

const (
    swaggerURL = "https://petstore.swagger.io/v2/swagger.json"
)

func main() {
	http.Handle("/doc/", http.StripPrefix("/doc/", swaggerui.Handler(swaggerURL)))
	if err := http.ListenAndServe(":8888", nil); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const Version = "5.9.0"

Variables

This section is empty.

Functions

func Handler

func Handler(swaggerURL string) http.Handler

func HandlerWithConfig

func HandlerWithConfig(config Config) http.Handler

func HandlerWithInitializer

func HandlerWithInitializer(initializer []byte) http.Handler

Types

type Config

type Config struct {

	// URL to fetch external configuration document from.
	ConfigURL string `cfg:"configUrl"`

	// The ID of a DOM element inside which SwaggerUI will put its user interface.
	DomID string `cfg:"dom_id"`

	// The HTML DOM element inside which SwaggerUI will put its user interface. Overrides dom_id.
	DomNode string `cfg:"domNode"`

	// A JavaScript object describing the OpenAPI definition.
	// When used, the url parameter will not be parsed.
	// This is useful for testing manually-generated definitions without hosting them.
	Spec Object `cfg:"spec"`

	// The URL pointing to API definition (normally swagger.json or swagger.yaml).
	// Will be ignored if urls or spec is used.
	URL string `cfg:"url"`

	// An array of API definition objects ([{url: "<url1>", name: "<name1>"},{url: "<url2>", name: "<name2>"}])
	// used by Topbar plugin. When used and Topbar plugin is enabled, the url parameter will not be parsed.
	// Names and URLs must be unique among all items in this array, since they're used as identifiers.
	URLS []URL `cfg:"urls"`

	// Enables overriding configuration parameters via URL search params.
	QueryConfigEnabled *bool `cfg:"queryConfigEnabled"`

	// The name of a component available via the plugin system to use as the top-level layout for Swagger UI.
	Layout string `cfg:"layout"`

	// A Javascript object to configure plugin integration and behaviors (see below).
	PluginsOptions Object `cfg:"pluginsOptions"`

	// An array of plugin functions to use in Swagger UI.
	Plugins []Item `cfg:"plugins"`

	// An array of presets to use in Swagger UI. Usually, you'll want to include ApisPreset if you use this option.
	Presets []Item `cfg:"presets"`

	// Control behavior of plugins when targeting the same component with wrapComponent.
	// - legacy (default) : last plugin takes precedence over the others
	// - chain : chain wrapComponents when targeting the same core component, allowing multiple
	//           plugins to wrap the same component
	// @Available: ["legacy", "chain"]
	PluginLoadType string `cfg:"pluginLoadType"`

	// If set to true, enables deep linking for tags and operations.
	// See the Deep Linking documentation for more information.
	// @URL: https://swagger.io/docs/usage/deep-linking.md
	DeepLinking *bool `cfg:"deepLinking"`

	// Controls the display of operationId in operations list. The default is false.
	DisplayOperationID *bool `cfg:"displayOperationId"`

	// The default expansion depth for Models (set to -1 completely hide the Models).
	DefaultModelsExpandDepth *int `cfg:"defaultModelsExpandDepth"`

	// The default expansion depth for the model on the model-example section.
	DefaultModelExpandDepth *int `cfg:"defaultModelExpandDepth"`

	// Controls how the model is shown when the API is first rendered. (The user can always switch the rendering
	// for a given model by clicking the 'Model' and 'Example Value' links.)
	// @Available: ["example", "model"]
	DefaultModelRendering string `cfg:"defaultModelRendering"`

	// Controls the display of the request duration (in milliseconds) for "Try it out" requests.
	DisplayRequestDuration *bool `cfg:"displayRequestDuration"`

	// 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).
	// @Available: ["list", "full", "none"]
	DocExpansion string `cfg:"docExpansion"`

	// If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged
	// operations that are shown. Can be Boolean to enable or disable, or a string, in which case filtering will
	// be enabled using that string as the filter expression. Filtering is case sensitive matching the filter
	// expression anywhere inside the tag
	Filter string `cfg:"filter"`

	// If set, limits the number of tagged operations displayed to at most this many.
	// The default is to show all operations.
	MaxDisplayedTags *int `cfg:"maxDisplayedTags"`

	// Controls the display of vendor extension (x-) fields and values for Operations, Parameters,
	// Responses, and Schema.
	ShowExtensions *bool `cfg:"showExtensions"`

	// Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values
	// for Parameters.
	ShowCommonExtensions *bool `cfg:"showCommonExtensions"`

	// Deprecated: This parameter is Deprecated and will be removed in 4.0.0.
	// When enabled, sanitizer will leave style, class and data-* attributes untouched on all HTML Elements
	// declared inside markdown strings. This parameter is Deprecated and will be removed in 4.0.0.
	UseUnsafeMarkdown *bool `cfg:"useUnsafeMarkdown"`

	// Set to false to deactivate syntax highlighting of payloads and cURL command, can be otherwise an object
	// with the activate and theme properties.
	SyntaxHighlight SyntaxHighlight `cfg:"syntaxHighlight"`

	// Controls whether the "Try it out" section should be enabled by default.
	TryItOutEnabled *bool `cfg:"tryItOutEnabled"`

	// Enables the request snippet section. When disabled, the legacy curl snippet will be used.
	RequestSnippetsEnabled *bool `cfg:"requestSnippetsEnabled"`

	// OAuth redirect URL.
	Oauth2RedirectURL string `cfg:"oauth2RedirectUrl"`

	// If set, MUST be an array of command line options available to the curl command.
	// This can be set on the mutated request in the requestInterceptor function.
	// For example request.curlOptions = ["-g", "--limit-rate 20k"]
	RequestCurlOptions []string `cfg:"request.curlOptions"`

	// If set to true, uses the mutated request returned from a requestInterceptor to produce the curl command
	// in the UI, otherwise the request before the requestInterceptor was applied is used.
	ShowMutatedRequest *bool `cfg:"showMutatedRequest"`

	// List of HTTP methods that have the "Try it out" feature enabled. An empty array disables "Try it out" for
	// all operations. This does not filter the operations from the display.
	// @Available: ["get", "put", "post", "delete", "options", "head", "patch", "trace"]
	SupportedSubmitMethods []string `cfg:"supportedSubmitMethods"`

	// By default, Swagger UI attempts to validate specs against swagger.io's online validator.
	// You can use this parameter to set a different validator URL, for example for locally deployed validators
	// (Validator Badge). Setting it to either none, 127.0.0.1 or localhost will disable validation.
	// @URL: https://github.com/swagger-api/validator-badge
	ValidatorURL string `cfg:"validatorUrl"`

	// If set to true, enables passing credentials, as defined in the Fetch standard, in CORS requests that are
	// sent by the browser. Note that Swagger UI cannot currently set cookies cross-domain (see swagger-js#1163) -
	// as a result, you will have to rely on browser-supplied cookies (which this setting enables sending)
	// that Swagger UI cannot control.
	WithCredentials *bool `cfg:"withCredentials"`

	// If set to true, it persists authorization data and it would not be lost on browser close/refresh.
	PersistAuthorization *bool `cfg:"persistAuthorization"`
}

func (Config) Encode

func (c Config) Encode() []byte

type Item

type Item string

type Object

type Object map[string]any

type SyntaxHighlight

type SyntaxHighlight struct {
	// Whether syntax highlighting should be activated or not.
	Activate *bool `cfg:"activate"`

	// Highlight.js syntax coloring theme to use. (Only these 6 styles are available.)
	// @URL: https://highlightjs.org/static/demo/
	// @Available: ["agate", "arta", "monokai", "nord", "obsidian", "tomorrow-night"]
	Theme string `cfg:"theme"`
}

type URL

type URL struct {
	URL  string `cfg:"url"`
	Name string `cfg:"name"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL