Categorygithub.com/Red-Sock/go-swagger-ui
modulepackage
0.0.2
Repository: https://github.com/red-sock/go-swagger-ui.git
Documentation: pkg.go.dev

# README

go-swagger-ui

go-swagger-ui provides a simple way to serve Swagger UI in your Go web application. It embeds Swagger UI and provides a customizable http.Handler to serve it.

Features

  • Provides a customizable HTTP Handler to serve Swagger UI.
  • Supports many of Swagger UI's configuration options.
  • Supports dynamic UI configuration in your Go application.
  • Provides a CLI application to open OpenAPI specification files in a Swagger UI instance (browser window).

Installation

To install the go-swagger-ui package, use the following command:

go get github.com/Red-Sock/go-swagger-ui

Usage

package main

import (
	"fmt"
	swaggerui "github.com/Red-Sock/go-swagger-ui"
	"log"
	"net/http"
)

func main() {
	http.HandleFunc("/", swaggerui.NewHandler(
		swaggerui.WithHTMLTitle("My Example Petstore API"),
		swaggerui.WithSpecURL("https://petstore.swagger.io/v2/swagger.json"),
		swaggerui.WithTryItOutEnabled(true),
		swaggerui.WithPersistAuthorization(true),
	))

	fmt.Println("Starting server at port 8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal(err)
	}
}

CLI Usage

Install the CLI application:

go install github.com/Red-Sock/go-swagger-ui/cmd/swui@latest

You can then use the CLI tool to serve OpenAPI spec files in a separate Swagger UI instance in a browser window.

swui /path/to/openapi-spec.yaml

swui also allows you to reload the browser window to see changes made to the spec file.

Roadmap

  • Embed Swagger UI
  • Provide simple but powerful http.Handler that is compatible with major web libraries
  • Allow to change the majority of configuration parameters from within a Go application
  • Make it possible to configure multiple spec file urls
  • Provide a CLI tool to view OpenAPI spec files locally in a browser
  • Add OAuth2 configuration possibilities (https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/oauth2.md)
  • Make plugins configurable
  • Make presets configurable
  • Allow using CDN instead of embedding Swagger UI

License

go-swagger-ui is free software: you can use it under the terms of the Apache License 2.0 license.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This library includes Swagger UI as static resources. Swagger UI is a product of SmartBear Software Inc. and is made available under the Apache License 2.0. For complete details of the license, please refer to the official license text available at this link. It's important to note that as per the requirements of the Apache-2.0 license, this documentation serves as an attribution to SmartBear Software Inc., acknowledging their development of Swagger UI. Users of this library are advised to ensure they are in compliance with the Apache-2.0 license terms when utilizing Swagger UI as part of this library.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
WithBasePath sets the path prefix Swagger UI is provided on the server For example, if Swagger UI is provided under https://example.com/my-service/swagger-ui, the base path would be "/my-service/swagger-ui").
WithConfigURL sets the URL to fetch external configuration document from.
WithCredentials enables passing credentials, as defined in the Fetch standard, in CORS requests that are sent by the browser.
WithDeepLinking enables deep linking.
WithDefaultModelExpandDepth sets the default expansion depth for the model on the model-example section.
WithDefaultModelRendering controls how the model is shown when the API is first rendered.
WithDefaultModelsExpandDepth sets the default expansion depth for models (set to -1 completely hide the models).
WithDisplayOperation controls the display of operationId in operations list.
WithDisplayRequestDuration controls the display of the request duration (in milliseconds) for "Try it out" requests.
WithDocExpansion controls the default expansion setting for the operations and tags.
WithFilter enables filtering.
WithHTMLTitle sets the index HTML page TtmlTitle.
WithLayout sets the name of a component available via the plugin system to use as the top-level layout for Swagger UI.
WithMaxDisplayedTags limits the number of tagged operations displayed to at most this many.
WithOauth2RedirectUrl sets the OAuth redirect URL.
WithPersistAuthorization configures Swagger UI to persist authorization data, so that it is not lost on browser close/refresh.
WithPlugins adds swagger plugins to final build.
WithPresets sets the list of presets to use in Swagger UI.
WithQueryConfigEnabled enables overriding configuration parameters via URL search params.
WithShowCommonExtensions controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters.
WithShowExtensions controls the display of vendor extension (x-) fields and values for Operations, Parameters, Responses, and Schema.
WithShowMutatedRequest configures Swagger UI to use 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.
WithSpec sets an OpenAPI specification document content.
WithSpecFilePath sets a file path to read from the OS file system.
WithSpecURL sets the URL pointing to API definition (normally swagger.json or swagger.yaml).
WithSpecURLs sets the URLs array to multiple API definitions that are used by Topbar plugin.
WithSupportedSubmitMethods sets a list of HTTP methods that have the "Try it out" feature enabled.
WithTryItOutEnabled controls whether the "Try it out" section should be enabled by default.
WithValidatorURL sets the validator URL to use to validate specification files.

# Constants

No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author

# Type aliases

Option is a function that takes a pointer to config.UiConfig and modifies it.