Help us shape the future of Go! Take the 2026 Go Developer Survey

openapi

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package openapi describes an app's HTTP routes as an OpenAPI 3.1 document.

Install New in InstalledApps to serve the document; nothing is served unless you do. Every route included in the registry is listed with its method, path, path parameters and name. A route can add detail with tango.Doc.

Index

Constants

View Source
const EnvVar = "TANGO_OPENAPI"

EnvVar is the environment variable Dev reads. Set it to a true value ("1", "true") to serve the document and the UI.

View Source
const Version = "3.1.0"

Version is the OpenAPI version of the documents this package writes.

Variables

This section is empty.

Functions

func Dev

func Dev(opts Options) tango.App

Dev is New for development: it serves the document and the UI only when the TANGO_OPENAPI environment variable is true, so a production process that does not set it exposes neither. `tango openapi` and `tango check` work either way, because they read the route table and serve nothing.

func Document

func Document(routes []tango.DescribedRoute, opts Options) (map[string]any, error)

Document builds the OpenAPI document for routes. It is deterministic: the same routes and options give the same bytes once marshalled.

func New

func New(opts Options) tango.App

New returns an App that serves the OpenAPI document of every route in the registry at Options.Path. Nothing is served unless it is installed; wrap the route with your own middleware if the document should not be public.

Types

type Options

type Options struct {
	// Title is the API's name. Default "API".
	Title string
	// Version is the API's own version, not the OpenAPI version. Default "0.0.0".
	Version string
	// Description is shown under the title.
	Description string
	// Servers are base URLs such as "https://api.example.com".
	Servers []string
	// Path is where the JSON document is served. Default "/openapi.json".
	Path string
	// UI serves a browsable page for the document, such as swaggerui.New().
	// Nil serves none.
	UI UI
	// UIPath is where the UI is served. Default "/docs/".
	UIPath string
	// ExcludePrefixes leaves out every route whose path starts with one of
	// them, such as "/admin/" for pages that are not part of the API.
	ExcludePrefixes []string
}

Options configures New and Document. The zero value is usable.

type UI

type UI interface {
	Routes(base, specPath string) []tango.Route
}

UI is a page that renders the document. The swaggerui package provides one. Routes returns the routes serving it under base (a path ending in "/") for the document at specPath.

Directories

Path Synopsis
Package swaggerui serves Swagger UI, embedded in the binary, for the openapi package:
Package swaggerui serves Swagger UI, embedded in the binary, for the openapi package:

Jump to

Keyboard shortcuts

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