Skip to main content

Stoplight Elements

Stoplight Elements provides a beautiful three-column "Stripe-esque" layout with a sidebar, content area, and interactive "Try It" panel. It's the default UI used by the spec framework adapters.

Installation

go get github.com/oaswrap/spec-ui/stoplight

Usage

import (
specui "github.com/oaswrap/spec-ui"
"github.com/oaswrap/spec-ui/stoplight"
)

handler := specui.NewHandler(
specui.WithTitle("My API"),
specui.WithSpecFile("openapi.yaml"),
stoplight.WithUI(),
)

With Configuration

import (
"github.com/oaswrap/spec-ui/config"
"github.com/oaswrap/spec-ui/stoplight"
)

handler := specui.NewHandler(
specui.WithTitle("My API"),
specui.WithSpecFile("openapi.yaml"),
stoplight.WithUI(config.StoplightElements{
HideExport: false,
HideSchemas: false,
HideTryIt: false,
HideTryItPanel: false,
Layout: "sidebar",
Logo: "/assets/logo.png",
Router: "hash",
}),
)

Configuration Reference

FieldTypeDefaultDescription
HideExportboolfalseHide the "Export" button
HideSchemasboolfalseHide schemas in the Table of Contents
HideTryItboolfalseHide the "Try It" interactive feature
HideTryItPanelboolfalseHide the "Try It" panel
Layoutstring"sidebar"Layout: "sidebar", "responsive", or "stacked"
Logostring""URL to a logo image
Routerstring"hash"Router type: "hash", "history", "memory", or "static"

Embedded Mode

Use stoplightemb for air-gapped deployments:

import "github.com/oaswrap/spec-ui/stoplightemb"

handler := specui.NewHandler(
specui.WithSpecFile("openapi.yaml"),
stoplightemb.WithUI(),
)

// Register the assets route
if handler.AssetsEnabled() {
r.Get(handler.AssetsPath()+"/*", handler.Assets().ServeHTTP)
}