spec

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package spec is the provider-neutral OpenAPI IR: ordered slices only, not changed after build.

Index

Constants

View Source
const (
	InPath        = "path"
	InQuery       = "query"
	InHeader      = "header"
	InCookie      = "cookie"
	InQueryString = "querystring"
)

Variables

View Source
var MethodOrder = []string{"GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE", "QUERY"}

MethodOrder is the order operations of one path item come in; 3.2 additional operations follow.

Functions

func DeriveOperationID

func DeriveOperationID(method, path string) string

DeriveOperationID names an operation without operationId: GET /users/{id} gives getUsersId.

func StatusCode

func StatusCode(status string) (int, bool)

StatusCode reads a status code from a response key: the key when it is a number, the first digit times 100 when it has three characters and starts with a digit, as a range such as 4XX does. It reads none from default or from another key.

Types

type Additional

type Additional struct {
	Mode   AdditionalMode
	Schema *Schema
}

type AdditionalMode

type AdditionalMode int
const (
	AdditionalUnset AdditionalMode = iota
	AdditionalAllowed
	AdditionalDenied
	AdditionalSchema
)

type Bound

type Bound struct {
	Value     json.Number
	Exclusive bool
}

type Callback

type Callback struct {
	Name       string
	Operations []*Operation
	Ref        *ComponentRef
}

Callback holds the operations of all its expressions; each operation's Path is its expression.

type ComponentRef

type ComponentRef struct {
	Pointer string
	Name    string
}

ComponentRef records the $ref an object came from; Name is set for a component target.

type Components

type Components struct {
	Schemas         []Named[*Schema]
	Responses       []Named[*Response]
	Parameters      []Named[*Parameter]
	RequestBodies   []Named[*RequestBody]
	Headers         []Named[*Header]
	SecuritySchemes []*SecurityScheme
}

Components lists every reusable object in source order. Usages elsewhere share these pointers.

type Discriminator

type Discriminator struct {
	Property string
	Mapping  []Mapping
	Default  *Ref
}

Discriminator has every mapping value resolved, bare names too; Default is 3.2 defaultMapping.

type Document

type Document struct {
	Version    Version
	Info       Info
	Servers    []Server
	Operations []*Operation
	Webhooks   []*Operation
	Components Components
	Security   []SecurityRequirement
	Extensions []Extension
}

Document is a parsed spec. Operations keep paths in source order and methods in MethodOrder.

type Encoding

type Encoding struct {
	Name          string
	ContentType   string
	Headers       []*Header
	Style         string
	Explode       *bool
	AllowReserved bool
}

type Extension

type Extension struct {
	Name  string
	Value Value
}

type Field

type Field struct {
	Name  string
	Value Value
}
type Header struct {
	Name        string
	Description string
	Required    bool
	Deprecated  bool
	Style       string
	Explode     bool
	Schema      *Schema
	Contents    []*MediaType
	Extensions  []Extension
	Ref         *ComponentRef
	Origin      Origin
}

type Info

type Info struct {
	Title       string
	Summary     string
	Description string
	Version     string
	Extensions  []Extension
}

type Limits

type Limits struct {
	Minimum       *Bound
	Maximum       *Bound
	MultipleOf    *json.Number
	MinLength     *int64
	MaxLength     *int64
	MinItems      *int64
	MaxItems      *int64
	MinProperties *int64
	MaxProperties *int64
	UniqueItems   bool
}

Limits keeps numbers as written; 3.0 boolean and 3.1 numeric exclusive bounds look the same.

type Mapping

type Mapping struct {
	Value string
	Ref   *Ref
}

type MediaType

type MediaType struct {
	Name       string
	Schema     *Schema
	ItemSchema *Schema
	Encodings  []*Encoding
	Extensions []Extension
	Origin     Origin
}

type Named

type Named[T any] struct {
	Name  string
	Value T
}

Named is a component with the key it has under components.

type OAuthFlow

type OAuthFlow struct {
	Kind             string
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           []Scope
}

OAuthFlow is one oauth2 flow; Kind is its key, such as implicit or clientCredentials.

type Operation

type Operation struct {
	ID          string
	IsIDDerived bool
	Method      string
	Path        string
	IsWebhook   bool
	Summary     string
	Description string
	Deprecated  bool
	Tags        []string
	// Path-level params come first; an operation param with the same in and name replaces one.
	Params    []*Parameter
	Body      *RequestBody
	Responses []*Response
	Callbacks []*Callback
	// Security is the effective list: the operation's own when it sets one, else the document's.
	Security   []SecurityRequirement
	Servers    []Server
	Extensions []Extension
	Origin     Origin
}

Operation is one method on a path, webhook or callback expression.

type Origin

type Origin struct {
	Pointer string
	File    string
	Line    int
	Col     int
}

Origin is an object's JSON pointer in the parsed document and its position in the source file.

type Parameter

type Parameter struct {
	Name            string
	In              string
	Description     string
	Required        bool
	Deprecated      bool
	AllowEmptyValue bool
	Style           string
	Explode         bool
	AllowReserved   bool
	Schema          *Schema
	Contents        []*MediaType
	Extensions      []Extension
	Ref             *ComponentRef
	Origin          Origin
}

Parameter has Style and Explode resolved to their defaults when the spec leaves them out.

type Property

type Property struct {
	Name     string
	Schema   *Schema
	Required bool
}

type Ref

type Ref struct {
	Pointer string
	Name    string
	Target  *Schema
}

Ref is a schema $ref; Name is set for a component target, and Target can close a cycle.

type RequestBody

type RequestBody struct {
	Description string
	Required    bool
	Contents    []*MediaType
	Extensions  []Extension
	Ref         *ComponentRef
	Origin      Origin
}

type RequiredScheme

type RequiredScheme struct {
	Name   string
	Scopes []string
}

type Response

type Response struct {
	Status      string
	Description string
	Headers     []*Header
	Contents    []*MediaType
	Extensions  []Extension
	Ref         *ComponentRef
	Origin      Origin
}

Response is one entry of an operation's responses. Status is empty on a component response.

type Schema

type Schema struct {
	Ref                  *Ref
	Types                TypeSet
	Nullable             bool
	Format               string
	Title                string
	Description          string
	Pattern              string
	ContentEncoding      string
	ContentMediaType     string
	Required             []string
	Properties           []*Property
	AdditionalProperties Additional
	PropertyNames        *Schema
	Items                *Schema
	PrefixItems          []*Schema
	AllOf                []*Schema
	OneOf                []*Schema
	AnyOf                []*Schema
	Not                  *Schema
	If                   *Schema
	Then                 *Schema
	Else                 *Schema
	Discriminator        *Discriminator
	Enum                 []Value
	Const                *Value
	Default              *Value
	Examples             []Value
	Limits               Limits
	ReadOnly             bool
	WriteOnly            bool
	Deprecated           bool
	Extensions           []Extension
	Origin               Origin
}

Schema is one schema; on a $ref usage Ref is set and keywords next to the $ref stay here.

type Scope

type Scope struct {
	Name        string
	Description string
}

type SecurityRequirement

type SecurityRequirement struct {
	Schemes []RequiredScheme
}

SecurityRequirement is one alternative: every scheme in it applies. No schemes means anonymous.

type SecurityScheme

type SecurityScheme struct {
	Name              string
	Type              string
	Description       string
	In                string
	ParamName         string
	Scheme            string
	BearerFormat      string
	OpenIDConnectURL  string
	OAuth2MetadataURL string
	Flows             []OAuthFlow
	Deprecated        bool
	Extensions        []Extension
	Origin            Origin
}

type Server

type Server struct {
	URL         string
	Name        string
	Description string
	Variables   []ServerVariable
}

type ServerVariable

type ServerVariable struct {
	Name        string
	Default     string
	Description string
	Enum        []string
}

type TypeSet

type TypeSet uint8

TypeSet holds the allowed JSON types; Null stays only when alone, else it becomes Nullable.

const (
	TypeString TypeSet = 1 << iota
	TypeNumber
	TypeInteger
	TypeBoolean
	TypeObject
	TypeArray
	TypeNull
)

func (TypeSet) Has

func (t TypeSet) Has(other TypeSet) bool

type Value

type Value struct {
	Kind   ValueKind
	Str    string
	Num    json.Number
	Bool   bool
	Items  []Value
	Fields []Field
}

Value is a JSON value; only the field for its Kind is set, and numbers keep their written form.

type ValueKind

type ValueKind int
const (
	KindNull ValueKind = iota
	KindString
	KindNumber
	KindBool
	KindArray
	KindObject
)

type Version

type Version int
const (
	V30 Version = iota + 1
	V31
	V32
)

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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