swaggerui

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package swaggerui provides a Swagger UI for stdocs.

Swagger UI is the classic OpenAPI viewer, loaded from a CDN. To use it, import this sub-package and pass swaggerui.WithUI() to stdocs.New or stdocs.DocsHandler:

import (
    "github.com/FumingPower3925/stdocs"
    "github.com/FumingPower3925/stdocs/ui/swaggerui"
)

mux := stdocs.New(stdocs.WithTitle("My API"), swaggerui.WithUI())
mux.HandleFunc("GET /x", h)
mux.Mount()

This sub-package adds the Swagger UI HTML to the docs handler. The Swagger UI JavaScript and CSS are loaded from cdn.jsdelivr.net at page load time, so an internet connection is required.

The CDN URLs are pinned to a specific version (5.32.6, the current latest 5.x). Integrity hashes are pre-computed (sha384) and pinned in the <link>/<script> tags. Bumping the pinned version requires re-computing the hashes (the recipe is inlined above the hash constants below). For an air-gapped build, use the ui/swaggeruiemb sub-package instead — it vendors the bundle in-repo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithUI

func WithUI(opts ...UIOption) stdocs.Option

WithUI returns a stdocs.Option that replaces the default docs page with Swagger UI. Pass WithConfiguration to forward Swagger UI-native options; they override the CSP-safe defaults.

Types

type UIOption added in v0.7.0

type UIOption = uiopt.Option

UIOption configures the Swagger UI installed by WithUI.

func WithConfiguration added in v0.7.0

func WithConfiguration(cfg map[string]any) UIOption

WithConfiguration passes Swagger UI configuration to the docs page. The map is merged over Swagger UI's SwaggerUIBundle({...}) options, so its keys are Swagger UI's parameters — for example "docExpansion", "filter", "defaultModelsExpandDepth", "tryItOutEnabled", or "displayRequestDuration". The "url" and "dom_id" are set by stdocs and always win. See the Swagger UI configuration reference: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/

Jump to

Keyboard shortcuts

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