stoplight

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 stoplight provides a Stoplight Elements UI for stdocs.

Stoplight Elements is a modern OpenAPI viewer that supports OpenAPI 3.0.x and 3.1.x, loaded from a CDN. To use it, import this sub-package and pass stoplight.WithUI() to stdocs.New or stdocs.DocsHandler:

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

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

This sub-package adds the Stoplight HTML to the docs handler. The Stoplight web components and stylesheet 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 (9.0.22) and point at the verbatim web-components.min.js and styles.min.css files from the npm package, so their bytes are deterministic and the sha384 SRI hashes below are pinned in the <script>/<link> tags. Bumping the pinned version requires re-computing the hashes. For an air-gapped build, use the ui/stoplightemb 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 Stoplight Elements. Pass WithConfiguration to forward Stoplight-native options as element attributes.

Types

type UIOption added in v0.7.0

type UIOption = uiopt.Option

UIOption configures the Stoplight Elements UI installed by WithUI.

func WithConfiguration added in v0.7.0

func WithConfiguration(cfg map[string]any) UIOption

WithConfiguration passes Stoplight Elements configuration to the docs page. Stoplight Elements has no JSON configuration object — it is configured through attributes on its <elements-api> element — so the map's keys are rendered as element attributes and its values must be strings, booleans, or numbers. Keys are Stoplight attribute names, for example "hideTryItPanel", "hideSchemas", "tryItCredentialsPolicy", or "logo". apiDescriptionUrl, router, and layout are set by stdocs and cannot be overridden. See the Stoplight Elements configuration reference: https://github.com/stoplightio/elements/blob/main/docs/getting-started/elements/elements-options.md

Jump to

Keyboard shortcuts

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