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 ¶
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 ¶
MarshalJSON serialises Paths as a flat JSON object keyed by path.
func (*Paths) UnmarshalJSON ¶
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 ¶
NewSpec returns a new Spec initialised with the given API title, version and the current OpenAPI Version.
func (*Spec) AddPath ¶
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 ¶
SetServers replaces the servers list in the spec.