openapi

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openapi builds an OpenAPI document from Go types. It has no dependency: a schema reflector over `json` struct tags and a builder that lays out paths, security and a shared error envelope. The output is deterministic (maps are marshalled sorted), so a committed copy of it is a reviewable diff.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(d Document) ([]byte, error)

Build renders d as indented OpenAPI 3.1 JSON.

Types

type Document

type Document struct {
	Title, Description, Version string
	// Error is the envelope type of every failure; ErrorCodes its machine codes.
	Error      reflect.Type
	ErrorCodes []string
	Ops        []Operation
}

Document describes the whole API.

type Event

type Event struct {
	Name string
	Type reflect.Type
}

Event is one named event of a stream.

type Operation

type Operation struct {
	ID, Path, Summary string
	// Stability is the tier name, emitted as x-stability.
	Stability string
	Params    []Param
	// Response is the type of the 200 body; nil is a free-form object.
	Response reflect.Type
	// Errors are the HTTP statuses answered with the error envelope.
	Errors []int
	// Public says no bearer token is needed.
	Public bool
	// Events makes the operation a server-sent event stream: the 200 body is
	// text/event-stream and each event's data has the given type.
	Events []Event
}

Operation is one GET operation.

type Param

type Param struct {
	Name, In, Description, Type string
	Required                    bool
}

Param is a path or query parameter. Type defaults to string.

type Reflector

type Reflector struct {
	// contains filtered or unexported fields
}

Reflector turns Go types into JSON schemas. A named struct becomes a component referenced by $ref, which also ends recursion.

func NewReflector

func NewReflector() *Reflector

NewReflector returns an empty reflector.

func (*Reflector) Schema

func (r *Reflector) Schema(t reflect.Type) schema

Schema returns the schema of t.

Directories

Path Synopsis
Command gen writes docs/openapi.json.
Command gen writes docs/openapi.json.

Jump to

Keyboard shortcuts

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