schema

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package schema provides Go types for the OpenAPI 3.1 specification.

Only the subset of the specification needed by this project is implemented: top-level Spec, Info, Server, Paths, PathItem and Operation.

Reference: https://spec.openapis.org/oas/v3.1.1

Index

Constants

View Source
const (
	// Version is the OpenAPI specification version used by this package.
	Version = "3.1.1" // https://swagger.io/specification/
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Title       string `json:"title"` // Required.
	Summary     string `json:"summary,omitzero"`
	Description string `json:"description,omitzero"`
	Version     string `json:"version"` // Required.
}

Info provides metadata about the API.

type Operation

type Operation struct {
	Tags        []string `json:"tags,omitempty"`
	Summary     string   `json:"summary,omitzero"`
	Description string   `json:"description,omitzero"`
}

Operation describes a single API operation on a path.

type PathItem

type PathItem struct {
	Summary     string     `json:"summary,omitzero"`
	Description string     `json:"description,omitzero"`
	Get         *Operation `json:"get,omitempty"`
	Put         *Operation `json:"put,omitempty"`
	Post        *Operation `json:"post,omitempty"`
	Delete      *Operation `json:"delete,omitempty"`
	Options     *Operation `json:"options,omitempty"`
	Head        *Operation `json:"head,omitempty"`
	Patch       *Operation `json:"patch,omitempty"`
	Trace       *Operation `json:"trace,omitempty"`
}

PathItem describes the operations available on a single path.

type Paths

type Paths struct {
	MapOfPathItemValues map[string]PathItem `json:"-"` // Key must match pattern: `^/`.
}

Paths holds the relative paths to the individual endpoints and their operations. The map keys must begin with a forward slash.

func (Paths) MarshalJSON

func (p Paths) MarshalJSON() ([]byte, error)

MarshalJSON serialises Paths as a flat JSON object keyed by path.

func (*Paths) UnmarshalJSON

func (p *Paths) UnmarshalJSON(data []byte) error

UnmarshalJSON deserialises a flat JSON object into Paths.

type Server

type Server struct {
	URL         string `json:"url"` // Required. Format: uri-reference.
	Description string `json:"description,omitzero"`
}

Server represents a server that hosts the API.

type Spec

type Spec struct {
	Openapi           string   `json:"openapi"`
	Info              Info     `json:"info"`                       // Required.
	JSONSchemaDialect string   `json:"jsonSchemaDialect,omitzero"` // Format: uri.
	Servers           []Server `json:"servers,omitempty"`
	Paths             *Paths   `json:"paths,omitempty"`
}

Spec is the root object of an OpenAPI 3.1 document.

func NewSpec

func NewSpec(title, version string) *Spec

NewSpec returns a new Spec initialised with the given API title, version and the current OpenAPI Version.

func (*Spec) AddPath

func (s *Spec) AddPath(path string, item *PathItem)

AddPath registers a PathItem under the given path. If item is nil the call is a no-op. Adding a path that already exists replaces the previous entry.

func (*Spec) SetServers

func (s *Spec) SetServers(servers []Server)

SetServers replaces the servers list in the spec.

Jump to

Keyboard shortcuts

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