openapi

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 25 Imported by: 2

README

openapi - An OpenAPI 3.x library for go

Go Reference Latest Version Build Status

openapi is a library for parsing and validating OpenAPI 3.1, 3.0. The intent of the library is to offer building blocks for code and documentation generation.

⚠ This library is under active development; there may be breaking changes and bugs.

Features

  • $ref resolution
  • All keys retain their order from the markup using slices of key/values which aids in code generation.
  • Validation (see the validation section)
  • All non-primitive nodes have an absolute & relative location
  • Strings are text.Text which has case conversions and strings functions as methods.
  • Extensions, unknown JSON Schema keywords, examples, and a few other fields are instances of jsonx.RawMessage which comes with a few helper methods.
  • Supports both JSON and YAML

Usage

package main

import (
    "github.com/chanced/openapi"
    "github.com/chanced/uri"
    "github.com/santhosh-tekuri/jsonschema/v5"
    "embed"
    "io"
    "path/filepath"
    "log"
)

//go:embed spec
var specFiles embed.FS

func main() {
    ctx := context.Background()

    c, err := openapi.SetupCompiler(jsonschema.NewCompiler()) // adding schema files
    if err != nil {
        log.Fatal(err)
    }
    v, err := openapi.NewValidator(c)
    if err != nil {
        log.Fatal(err)
    }

    fn := func(_ context.Context, uri uri.URI, kind openapi.Kind) (openapi.Kind, []byte, error){
        f, err := specFiles.Open(fp)
        if err != nil {
            log.Fatal(err)
        }
        // you can return either JSON or YAML
        d, err := io.ReadAll(f)
        if err != nil{
            log.fatal(err)
        }
        // use the uri or the data to determine the Kind
        return openapi.KindDocument, d, nil
    }
    // you can Load either JSON or YAML
    // Load validates the Document as well.
    doc, err := openapi.Load(ctx, "spec/openapi.yaml", v, fn)
    if err != nil{
        log.Fatal(err)
    }
    _ = doc // *openapi.Document
}

Validation

The standard validator (StdValidator) currently validates OpenAPI documents with JSON Schema. Per OpenAPI's documentation, this may not be enough to properly encapsulate all the nuances of a specification. However, JSON Schema is able to successfully validate the current OpenAPI 3.1 Specification test suite.

Validation is an area that still needs work. If you do find cases where the current validator is not sufficient, please open an issue so that the library can be updated with proper coverage of that case.

Dependencies

Dependency Usage
github.com/santhosh-tekuri/jsonschema/v5 used in the StdValidator to validate OpenAPI documents & components
github.com/chanced/caps/text used for all string fields to provide case conversion and functions from strings as methods
github.com/chanced/jsonpointer relative locations of all non-scalar nodes
github.com/tidwall/gjson JSON parsing
github.com/chanced/jsonx raw JSON type and a toolkit for json type detection & parsing
github.com/chanced/maps small utility used to sort Extensions
github.com/chanced/transcode used to transform YAML into JSON and vice versa
github.com/chanced/uri used to represent URIs
github.com/Masterminds/semver openapi field and version detection of OpenAPI documents
gopkg.in/yaml.v3 needed to satisfy yaml.Marshaler and yaml.Unmarshaler
github.com/google/go-cmp testing purposes

Contributions

Please feel free to open up an issue or create a pull request if you find issues or if there are features you'd like to see added.

License

MIT

Documentation

Overview

Package openapi provides types, loading and validation for OpenAPI 3.1 and 3.0.

Index

Constants

View Source
const (
	MethodGet     = Text(http.MethodGet)
	MethodPut     = Text(http.MethodPut)
	MethodPost    = Text(http.MethodPost)
	MethodDelete  = Text(http.MethodDelete)
	MethodOptions = Text(http.MethodOptions)
	MethodHead    = Text(http.MethodHead)
	MethodPatch   = Text(http.MethodPatch)
	MethodTrace   = Text(http.MethodTrace)
)
View Source
const (
	// URI for OpenAPI 3.1 schema
	OPEN_API_3_1_SCHEMA = "https://spec.openapis.org/oas/3.1/schema/2022-02-27"
	// URI for OpenAPI 3.0 schema
	OPEN_API_3_0_SCHEMA = "https://spec.openapis.org/oas/3.0/schema/2021-09-28"
	// URI for JSON Schema 2020-12
	JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema"
	// URI for JSON Schema 2019-09
	JSON_SCHEMA_2019_09 = "https://json-schema.org/draft/2019-09/schema"
)

Variables

View Source
var (
	ErrEmptyRef      = errors.New("openapi: empty $ref")
	ErrNotFound      = fmt.Errorf("openapi: component not found")
	ErrNotResolvable = errors.New("openapi: pointer path not resolvable")

	ErrMissingOpenAPIVersion = errors.New("openapi: missing openapi version")

	// ErrInvalidSemVer is returned a version is found to be invalid when
	// being parsed.
	ErrInvalidSemVer = errors.New("invalid semantic version")

	// ErrInvalidMetadata is returned when the metadata of a semver is an invalid format
	ErrInvalidSemVerMetadata = errors.New("invalid semantic version metadata string")

	// ErrInvalidPrerelease is returned when the pre-release of a semver is an invalid format
	ErrInvalidSemVerPrerelease = errors.New("invalid semantic version prerelease string")

	ErrInvalidResolution = errors.New("openapi: invalid resolution")
)
View Source
var (
	// OpenAPI31Schema is the URI for the JSON Schema of OpenAPI 3.1
	OpenAPI31Schema = *uri.MustParse(OPEN_API_3_1_SCHEMA)
	// OpenAPI30Schema is the URI for the JSON Schema of OpenAPI 3.0
	OpenAPI30Schema = *uri.MustParse(OPEN_API_3_0_SCHEMA)
	// JSONSchema202012SchemaURI is the URI for JSON Schema 2020-12
	JSONSchemaDialect202012 = *uri.MustParse(JSON_SCHEMA_2020_12)
	// JSONSchemaDialect201909 is the URI for JSON Schema 2019-09
	JSONSchemaDialect201909 = *uri.MustParse(JSON_SCHEMA_2019_09)
	// VersionConstraints3_0 is a semantic versioning constraint for 3.0:
	//	>= 3.0.0, < 3.1.0
	VersionConstraints3_0 = mustParseConstraints(">= 3.0.0, < 3.1.0")
	// SemanticVersion3_0 is a semantic versioning constraint for 3.1:
	//	>= 3.1.0, < 3.2.0
	VersionConstraints3_1 = mustParseConstraints(">= 3.1.0, < 3.2.0")
	// SupportedVersions is a semantic versioning constraint for versions
	// supported by openapi
	//
	// This is currently:
	//	>= 3.0.0, < 3.2.0
	SupportedVersions = mustParseConstraints(">= 3.0.0, < 3.2.0")
	// Version3_1 is a semantic version for 3.1.x
	Version3_1 = *semver.MustParse("3.1")
	// Version3_0 is a semantic version for 3.0.x
	Version3_0 = *semver.MustParse("3.0")
)
View Source
var ErrNotReference = errors.New("openapi: data is not a Reference")

ErrNotReference indicates not a reference

Functions

func IsExtensionKey

func IsExtensionKey(key Text) bool

IsExtensionKey returns true if the key starts with "x-"

func IsRef added in v0.1.0

func IsRef(node Node) bool

IsRef returns true for the following types:

  • *Reference
  • *SchemaRef
  • *OperationRef

func NewError added in v0.1.0

func NewError(err error, resource uri.URI) error

func NewResolutionError added in v0.1.0

func NewResolutionError(r Ref, expected, actual Kind) error

func NewSemVerError added in v0.1.0

func NewSemVerError(err error, value string, uri uri.URI) error

func NewValidationError added in v0.1.0

func NewValidationError(err error, kind Kind, resource uri.URI) error

func SetupCompiler added in v0.1.0

func SetupCompiler(compiler *jsonschema.Compiler, resources ...fs.FS) (*jsonschema.Compiler, error)

SetupCompiler adds OpenAPI and JSON Schema resources to a Compiler.

Each fs.FS in resources will be walked and all files ending in .json will be be added to the compiler.

Defaults

func TryGetOpenAPIVersion added in v0.1.0

func TryGetOpenAPIVersion(data []byte) (string, bool)

TryGetOpenAPIVersion attempts to extract the OpenAPI version from raw JSON data and parse it as a semver.Version.

func TryGetSchemaDialect added in v0.1.0

func TryGetSchemaDialect(data []byte) (string, bool)

TryGetSchemaDialect attempts to extract the schema dialect from raw JSON data.

TryGetSchemaDialect will check the following fields in order:

  • $schema
  • jsonSchemaDialect

Types

type Anchor added in v0.1.0

type Anchor struct {
	Location
	In   *Schema
	Name Text
	Type AnchorType
}

type AnchorType added in v0.1.0

type AnchorType uint8
const (
	AnchorTypeUndefined AnchorType = iota
	AnchorTypeRegular              // $anchor
	AnchorTypeRecursive            // $recursiveAnchor
	AnchorTypeDynamic              // $dynamicAnchor
)

type Anchors added in v0.1.0

type Anchors struct {
	Standard  []Anchor // $anchor
	Recursive *Anchor  // $recursiveAnchor
	Dynamic   []Anchor // $dynamicAnchor
}

func (*Anchors) DynamicAnchor added in v0.2.0

func (a *Anchors) DynamicAnchor(name Text) *Anchor

func (*Anchors) StandardAnchor added in v0.2.0

func (a *Anchors) StandardAnchor(name Text) *Anchor

type BaseVisitor added in v0.1.0

type BaseVisitor struct{}

type Callbacks

type Callbacks struct {
	Extensions `json:"-"`
	PathItems  `json:"-"`
}

Callbacks is map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the path item object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.

To describe incoming requests from the API provider independent from another API call, use the webhooks field.

func (*Callbacks) Anchors added in v0.1.0

func (c *Callbacks) Anchors() (*Anchors, error)

func (*Callbacks) Kind added in v0.1.0

func (*Callbacks) Kind() Kind

kind returns KindCallback

func (Callbacks) MarshalJSON added in v0.1.0

func (c Callbacks) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Callbacks) MarshalYAML

func (c Callbacks) MarshalYAML() (interface{}, error)

func (*Callbacks) Nodes added in v0.1.0

func (c *Callbacks) Nodes() []Node

func (*Callbacks) Refs added in v0.1.0

func (c *Callbacks) Refs() []Ref

func (*Callbacks) UnmarshalJSON

func (c *Callbacks) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Callbacks) UnmarshalYAML

func (c *Callbacks) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type CallbacksMap added in v0.1.0

type CallbacksMap = ComponentMap[*Callbacks]

CallbacksMap is a map of reusable Callback Objects.

type CompiledSchema added in v0.1.0

type CompiledSchema interface {
	Validate(data interface{}) error
}

CompiledSchema is an interface satisfied by a JSON Schema implementation that validates primitive interface{} types.

github.com/santhosh-tekuri/jsonschema/v5 satisfies this interface.

type CompiledSchemas added in v0.1.0

type CompiledSchemas struct {
	OpenAPI    map[semver.Version]map[Kind]CompiledSchema
	JSONSchema map[uri.URI]CompiledSchema
}

CompiledSchemas are used in the the StdValidator

func CompileSchemas added in v0.1.0

func CompileSchemas(compiler *jsonschema.Compiler, openAPISchemas ...map[string]uri.URI) (CompiledSchemas, error)

CompileSchemas compiles the OpenAPI and JSON Schema resources using compiler.

openAPISchemas is a variadic map of OpenAPI versions to their respective schema ids. The keys must be valid semver versions; only the major and minor versions are used. The last value for a given major and minor will be used

Default openAPISchemas:

{ "3.1": "https://spec.openapis.org/oas/3.1/schema/2022-02-27)" }
{ "3.0": "https://spec.openapis.org/oas/3.0/schema/2021-09-28"  }

type Component added in v0.1.0

type Component[T refable] struct {
	Location
	Reference *Reference[T]
	Object    T
}

func (*Component[T]) Anchors added in v0.1.0

func (c *Component[T]) Anchors() (*Anchors, error)

func (*Component[T]) IsReference added in v0.1.0

func (c *Component[T]) IsReference() bool

IsReference returns true if this Component contains a Reference

func (*Component[T]) IsResolved added in v0.1.0

func (c *Component[T]) IsResolved() bool

IsResolved implements Ref

func (*Component[T]) Kind added in v0.1.0

func (c *Component[T]) Kind() Kind

func (*Component[T]) MakeReference added in v0.1.0

func (c *Component[T]) MakeReference(ref uri.URI) error

MakeReference converts the Component into a reference, altering the path of all nested nodes.

func (Component[T]) MarshalJSON added in v0.1.0

func (c Component[T]) MarshalJSON() ([]byte, error)

func (*Component[T]) MarshalYAML added in v0.1.0

func (c *Component[T]) MarshalYAML() (interface{}, error)

func (*Component[T]) ObjectKind added in v0.1.0

func (c *Component[T]) ObjectKind() Kind

ComponentKind returns the Kind of the containing Object, regardless of if it is referenced or not.

func (*Component[T]) Refs added in v0.1.0

func (c *Component[T]) Refs() []Ref

func (*Component[T]) URI added in v0.1.0

func (c *Component[T]) URI() *uri.URI

URI implements Ref

func (*Component[T]) UnmarshalJSON added in v0.1.0

func (c *Component[T]) UnmarshalJSON(data []byte) error

func (*Component[T]) UnmarshalYAML added in v0.1.0

func (c *Component[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type ComponentEntry added in v0.1.0

type ComponentEntry[V refable] struct {
	Key       Text
	Component *Component[V]
}

ComponentEntry is an entry in a ComponentMap consisting of a Key/Value pair for an object consiting of Component[T]s

type ComponentMap added in v0.1.0

type ComponentMap[T refable] struct {
	Location
	Items []*ComponentEntry[T]
}

ComponentMap is a pseudo map consisting of Components with type T.

Unlike a regular map, ComponentMap maintains the order of the map's fields.

Under the hood, ComponentMap is of a slice of ComponentField[T]

func (*ComponentMap[T]) Anchors added in v0.1.0

func (cm *ComponentMap[T]) Anchors() (*Anchors, error)

func (*ComponentMap[T]) Del added in v0.1.0

func (cm *ComponentMap[T]) Del(key Text)

func (*ComponentMap[T]) Get added in v0.1.0

func (cm *ComponentMap[T]) Get(key Text) *Component[T]

func (*ComponentMap[T]) Kind added in v0.1.0

func (*ComponentMap[T]) Kind() Kind

func (ComponentMap[T]) Map added in v0.1.0

func (cm ComponentMap[T]) Map() map[Text]*Component[T]

func (ComponentMap[T]) MarshalJSON added in v0.1.0

func (cm ComponentMap[T]) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (*ComponentMap[T]) MarshalYAML added in v0.1.0

func (cm *ComponentMap[T]) MarshalYAML() (interface{}, error)

func (*ComponentMap[T]) Refs added in v0.1.0

func (cm *ComponentMap[T]) Refs() []Ref

func (*ComponentMap[T]) Set added in v0.1.0

func (cm *ComponentMap[T]) Set(key Text, value *Component[T])

Set sets the value of the key in the ComponentMap

func (*ComponentMap[T]) UnmarshalJSON added in v0.1.0

func (cm *ComponentMap[T]) UnmarshalJSON(data []byte) error

func (*ComponentMap[T]) UnmarshalYAML added in v0.1.0

func (cm *ComponentMap[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type ComponentSlice added in v0.1.0

type ComponentSlice[T refable] struct {
	Location `json:"-"`
	Items    []*Component[T] `json:"-"`
}

ComponentSlice is a slice of Components of type T

func (*ComponentSlice[T]) Anchors added in v0.1.0

func (cs *ComponentSlice[T]) Anchors() (*Anchors, error)

func (ComponentSlice[T]) Kind added in v0.1.0

func (ComponentSlice[T]) Kind() Kind

func (ComponentSlice[T]) MarshalJSON added in v0.1.0

func (cs ComponentSlice[T]) MarshalJSON() ([]byte, error)

func (*ComponentSlice[T]) MarshalYAML added in v0.1.0

func (cs *ComponentSlice[T]) MarshalYAML() (interface{}, error)

func (*ComponentSlice[T]) Refs added in v0.1.0

func (cs *ComponentSlice[T]) Refs() []Ref

func (*ComponentSlice[T]) UnmarshalJSON added in v0.1.0

func (cs *ComponentSlice[T]) UnmarshalJSON(data []byte) error

func (*ComponentSlice[T]) UnmarshalYAML added in v0.1.0

func (cs *ComponentSlice[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type Components

type Components struct {
	// OpenAPI extensions
	Extensions `json:"-"`
	Location   `json:"-"`

	Schemas         *SchemaMap         `json:"schemas,omitempty"`
	Responses       *ResponseMap       `json:"responses,omitempty"`
	Parameters      *ParameterMap      `json:"parameters,omitempty"`
	RequestBodies   *RequestBodyMap    `json:"requestBodies,omitempty"`
	Headers         *HeaderMap         `json:"headers,omitempty"`
	SecuritySchemes *SecuritySchemeMap `json:"securitySchemes,omitempty"`
	Links           *LinkMap           `json:"links,omitempty"`
	Callbacks       *CallbacksMap      `json:"callbacks,omitempty"`
	PathItems       *PathItemMap       `json:"pathItems,omitempty"`
	Examples        *ExampleMap        `json:"examples,omitempty"` //
}

Components holds a set of reusable objects for different aspects of the OAS. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.

func (*Components) Anchors added in v0.1.0

func (c *Components) Anchors() (*Anchors, error)

func (*Components) Kind added in v0.1.0

func (*Components) Kind() Kind

func (Components) MarshalJSON

func (c Components) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Components) MarshalYAML

func (c Components) MarshalYAML() (interface{}, error)

func (*Components) Refs added in v0.1.0

func (c *Components) Refs() []Ref

func (*Components) UnmarshalJSON

func (c *Components) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Components) UnmarshalYAML

func (c *Components) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type Contact

type Contact struct {
	Extensions `json:"-"`
	Location   `json:"-"`
	// The identifying name of the contact person/organization.
	Name Text `json:"name,omitempty"`
	// The URL pointing to the contact information. This MUST be in the form of
	// a URL.
	URL *uri.URI `json:"url,omitempty"`
	// The email address of the contact person/organization. This MUST be in the
	// form of an email address.
	Emails Text `json:"email,omitempty"`
}

Contact information for the exposed API.

func (*Contact) Anchors added in v0.1.0

func (*Contact) Anchors() (*Anchors, error)

func (*Contact) Kind added in v0.1.0

func (*Contact) Kind() Kind

Kind returns KindContact

func (Contact) MarshalJSON

func (c Contact) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Contact) MarshalYAML

func (c Contact) MarshalYAML() (interface{}, error)

func (*Contact) Refs added in v0.1.0

func (*Contact) Refs() []Ref

func (*Contact) UnmarshalJSON

func (c *Contact) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Contact) UnmarshalYAML

func (c *Contact) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type ContentMap added in v0.1.0

type ContentMap = ObjMap[*MediaType]

ContentMap / MediaTypeMap is a map containing descriptions of potential response payloads. The key is a media type or media type range and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*

type Discriminator

type Discriminator struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The name of the property in the payload that will hold the discriminator
	// value.
	//
	// *required
	PropertyName Text `json:"propertyName"`
	// An object to hold mappings between payload values and schema names or
	// references.
	Mapping *Map[Text] `json:"mapping,omitempty"`
}

Discriminator can be used to aid in serialization, deserialization, and validation of request bodies or response payloads which may be one of a number of different schemas. The discriminator is a specific object in a schema which is used to inform the consumer of the document of an alternative schema based on the value associated with it.

func (*Discriminator) Anchors added in v0.1.0

func (d *Discriminator) Anchors() (*Anchors, error)

func (*Discriminator) Clone added in v0.1.0

func (d *Discriminator) Clone() *Discriminator

func (*Discriminator) Kind added in v0.1.0

func (*Discriminator) Kind() Kind

func (Discriminator) MarshalJSON

func (d Discriminator) MarshalJSON() ([]byte, error)

MarshalJSON marshals d into JSON

func (Discriminator) MarshalYAML

func (d Discriminator) MarshalYAML() (interface{}, error)

func (*Discriminator) Nodes added in v0.1.0

func (d *Discriminator) Nodes() []Node

func (*Discriminator) Refs added in v0.1.0

func (*Discriminator) Refs() []Ref

func (*Discriminator) UnmarshalJSON

func (d *Discriminator) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into d

func (*Discriminator) UnmarshalYAML

func (d *Discriminator) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type Document added in v0.1.0

type Document struct {
	Location   `json:"-"`
	Extensions `json:"-"`

	// OpenAPI - The OpenAPI Version
	//
	// This string MUST be the version number of the OpenAPI
	// Specification that the OpenAPI document uses. The openapi field SHOULD be
	// used by tooling to interpret the OpenAPI document. This is not related to
	// the API info.version string.
	//
	// 	*required*
	OpenAPI *semver.Version `json:"openapi"`

	// Provides metadata about the API. The metadata MAY be used by
	// tooling as required.
	//
	// 	*required*
	Info *Info `json:"info"`

	// The default value for the $schema keyword within Schema Objects contained
	// within this OAS document.
	JSONSchemaDialect *uri.URI `json:"jsonSchemaDialect,omitempty"`

	// A list of tags used by the document with additional metadata. The order
	// of the tags can be used to reflect on their order by the parsing tools.
	// Not all tags that are used by the Operation Object must be declared. The
	// tags that are not declared MAY be organized randomly or based on the
	// tools’ logic. Each tag name in the list MUST be unique.
	Tags *TagSlice `json:"tags,omitempty"`

	// An array of Server Objects, which provide connectivity information to a
	// target server. If the servers property is not provided, or is an empty
	// array, the default value would be a Server Object with a url value of /.
	Servers *ServerSlice `json:"servers,omitempty" yaml:"servers,omitempty,omtiempty"`

	// The available paths and operations for the API.
	Paths *Paths `json:"paths,omitempty"`

	// The incoming webhooks that MAY be received as part of this API and that
	// the API consumer MAY choose to implement. Closely related to the
	// callbacks feature, this section describes requests initiated other than
	// by an API call, for example by an out of band registration. The key name
	// is a unique string to refer to each webhook, while the (optionally
	// referenced) Path Item Object describes a request that may be initiated by
	// the API provider and the expected responses. An example is available.
	Webhooks *PathItemMap `json:"webhooks,omitempty"`

	// An element to hold various schemas for the document.
	Components *Components `json:"components,omitempty"`

	// A declaration of which security mechanisms can be used across the API.
	//
	// The list of values includes alternative security requirement objects that
	// can be used.
	//
	// Only one of the security requirement objects need to be
	// satisfied to authorize a request. Individual operations can override this
	// definition.
	//
	// To make security optional, an empty security requirement ({})
	// can be included in the array.
	//
	Security *SecurityRequirementSlice `json:"security,omitempty"`

	// Additional external documentation.
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}

Document root object of the Document document.

func Load added in v0.1.0

func Load(ctx context.Context, documentURI string, validator Validator, fn func(ctx context.Context, uri uri.URI, kind Kind) (Kind, []byte, error), opts ...LoadOpts) (*Document, error)

Load loads an OpenAPI document from a URI and validate it with the provided validator.

Loading the raw data for OpenAPI Documents and externally referenced referenced JSON Schema components is done through the anonymous function fn. It is passed the URI of the resource and if known, the expected Kind. fn should return the Kind for the resource and the raw data if successful.

Resources that can be referenced are:

  • OpenAPI Document (KindDocument)
  • JSON Schema (KindSchema)
  • Callbacks (KindCallbacks)
  • Example (KindExample)
  • Header (KindHeader)
  • Link (KindLink)
  • Parameter (KindParameter)
  • PathItem (KindPathItem)
  • Operation (KindOperation)
  • Reference (KindReference)
  • RequestBody (KindRequestBody)
  • Response (KindResponse)
  • SecurityScheme (KindSecurityScheme)

Load will invoke fn with a URI containing a fragment; it will be called to resolve to the absolute path (i.e. non-fragmented) root document (e.g. Document, Schema, etc.) data of the primary Document and foreign $refs, $dynamicRefs, and $recursiveRefs.

Knowing the shape of root document prevents scenarios where we resolve "example.json#/foo/bar" and then later encounter a $ref to "example.json#/foo". Without knowing the shape of "example.json", we would have to extract out "example.json#/foo/bar" from the raw json/yaml, and then reparse "#/foo" when we hit the second $ref. As a result, there would then exist two references to the same object within the graph.

Finally, being able to parse the root resource is necessary for anchors (i.e. $anchor, $dynamicAnchor, $recursiveAnchor) above referenced external resources. For example, if we have a reference to "example.json#/foo/bar" which has an anchor "#baz", that is located at the root of "example.json", it would not be found if example.json were not parsed entirely.

func (*Document) Anchors added in v0.1.0

func (d *Document) Anchors() (*Anchors, error)

func (*Document) Kind added in v0.1.0

func (*Document) Kind() Kind

func (Document) MarshalJSON added in v0.1.0

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

MarshalJSON marshals JSON

func (Document) MarshalYAML added in v0.1.0

func (d Document) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Document) Refs added in v0.1.0

func (d *Document) Refs() []Ref

func (*Document) UnmarshalJSON added in v0.1.0

func (d *Document) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Document) UnmarshalYAML added in v0.1.0

func (d *Document) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type DuplicateAnchorError added in v0.1.0

type DuplicateAnchorError struct {
	A *Anchor
	B *Anchor
}

func (*DuplicateAnchorError) Error added in v0.1.0

func (dae *DuplicateAnchorError) Error() string

type Encoding

type Encoding struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The Content-Type for encoding a specific property. Default value depends
	// on the property type:
	//
	//  - for object - application/json;
	//  - for array – the default is defined based on the inner type;
	//  - for all other cases the default is application/octet-stream.
	// The value can be a specific media type (e.g. application/json), a
	// wildcard media type (e.g. image/*), or a comma-separated list of the two
	// types.
	ContentType Text `json:"contentType,omitempty"`
	// A map allowing additional information to be provided as headers, for
	// example Content-Disposition. Content-Type is described separately and
	// SHALL be ignored in this section. This property SHALL be ignored if the
	// request body media type is not a multipart.
	Headers *HeaderMap `json:"headers,omitempty"`
	// Describes how a specific property value will be serialized depending on
	// its type. See Parameter Object for details on the style property. The
	// behavior follows the same values as query parameters, including default
	// values. This property SHALL be ignored if the request body media type is
	// not application/x-www-form-urlencoded or multipart/form-data. If a value
	// is explicitly defined, then the value of contentType (implicit or
	// explicit) SHALL be ignored.
	Style Text `json:"style,omitempty"`
	// When this is true, property values of type array or object generate
	// separate parameters for each value of the array, or key-value-pair of the
	// map. For other types of properties this property has no effect. When
	// style is form, the default value is true. For all other styles, the
	// default value is false. This property SHALL be ignored if the request
	// body media type is not application/x-www-form-urlencoded or
	// multipart/form-data. If a value is explicitly defined, then the value of
	// contentType (implicit or explicit) SHALL be ignored.
	Explode *bool `json:"explode,omitempty"`
	// Determines whether the parameter value SHOULD allow reserved characters,
	// as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included without
	// percent-encoding. The default value is false. This property SHALL be
	// ignored if the request body media type is not
	// application/x-www-form-urlencoded or multipart/form-data. If a value is
	// explicitly defined, then the value of contentType (implicit or explicit)
	// SHALL be ignored.
	AllowReserved *bool `json:"allowReserved,omitempty"`
}

Encoding definition applied to a single schema property.

func (*Encoding) Anchors added in v0.1.0

func (e *Encoding) Anchors() (*Anchors, error)

func (*Encoding) Kind added in v0.1.0

func (*Encoding) Kind() Kind

func (Encoding) MarshalJSON

func (e Encoding) MarshalJSON() ([]byte, error)

MarshalJSON marshals e into JSON

func (Encoding) MarshalYAML

func (e Encoding) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Encoding) Nodes added in v0.1.0

func (e *Encoding) Nodes() []Node

func (*Encoding) Refs added in v0.1.0

func (e *Encoding) Refs() []Ref

func (*Encoding) UnmarshalJSON

func (e *Encoding) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into e

func (*Encoding) UnmarshalYAML

func (e *Encoding) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type EncodingMap added in v0.1.0

type EncodingMap = ComponentMap[*Encoding]

EncodingMap is a ComponentMap between a property name and its encoding information. The key, being the property name, MUST exist in the schema as a property. The encoding object SHALL only apply to requestBody objects when the media type is multipart or application/x-www-form-urlencoded.

type Error added in v0.1.0

type Error struct {
	Err         error
	ResourceURI uri.URI
}

func (*Error) Error added in v0.1.0

func (e *Error) Error() string

func (*Error) Unwrap added in v0.1.0

func (e *Error) Unwrap() error

type Example

type Example struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// Short description for the example.
	Summary Text `json:"summary,omitempty"`

	// Long description for the example. CommonMark syntax MAY be used for rich
	// text representation.
	Description Text `json:"description,omitempty"`

	// Any embedded literal example. The value field and externalValue field are
	// mutually exclusive. To represent examples of media types that cannot
	// naturally represented in JSON or YAML, use a string value to contain the
	// example, escaping where necessary.
	Value jsonx.RawMessage `json:"value,omitempty"`

	// A URI that points to the literal example. This provides the capability to
	// reference examples that cannot easily be included in JSON or YAML
	// documents. The value field and externalValue field are mutually
	// exclusive. See the rules for resolving Relative References.
	ExternalValue *uri.URI `json:"externalValue,omitempty"`
}

Example is an example for various api interactions such as Responses

In all cases, the example value is expected to be compatible with the type schema of its associated value. Tooling implementations MAY choose to validate compatibility automatically, and reject the example value(s) if incompatible.

func (*Example) Anchors added in v0.1.0

func (e *Example) Anchors() (*Anchors, error)

func (*Example) Kind added in v0.1.0

func (*Example) Kind() Kind

func (Example) MarshalJSON added in v0.1.0

func (e Example) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Example) MarshalYAML added in v0.1.0

func (e Example) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Example) Nodes added in v0.1.0

func (e *Example) Nodes() []Node

func (*Example) Refs added in v0.1.0

func (*Example) Refs() []Ref

func (*Example) UnmarshalJSON added in v0.1.0

func (e *Example) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Example) UnmarshalYAML added in v0.1.0

func (e *Example) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ExampleMap added in v0.1.0

type ExampleMap = ComponentMap[*Example]

ExampleMap is an object to hold reusable ExampleMap.

type Extensions

type Extensions map[Text]jsonx.RawMessage

Extensions for OpenAPI

While the OpenAPI Specification tries to accommodate most use cases, additional data can be added to extend the specification at certain points.

The extensions properties are implemented as patterned fields that are always prefixed by "x-".

Field Pattern Type Description ^x- Any Allows extensions to the OpenAPI Schema. The field name MUST begin with x-, for example, x-internal-id. Field names beginning x-oai- and x-oas- are reserved for uses defined by the OpenAPI Initiative. The value can be null, a primitive, an array or an object. The extensions may or may not be supported by the available tooling, but those may be extended as well to add requested support (if tools are internal or open-sourced).

Security Filtering Some objects in the OpenAPI Specification MAY be declared and remain empty, or be completely removed, even though they are inherently the core of the API documentation.

The reasoning is to allow an additional layer of access control over the documentation. While not part of the specification itself, certain libraries MAY choose to allow access to parts of the documentation based on some form of authentication/authorization.

Two examples of this:

The Paths Object MAY be present but empty. It may be counterintuitive, but this may tell the viewer that they got to the right place, but can't access any documentation. They would still have access to at least the Info Object which may contain additional information regarding authentication. The Path Item Object MAY be empty. In this case, the viewer will be aware that the path exists, but will not be able to see any of its operations or parameters. This is different from hiding the path itself from the Paths Object, because the user will be aware of its existence. This allows the documentation provider to finely control what the viewer can see.

func (Extensions) DecodeExtension

func (e Extensions) DecodeExtension(key Text, dst interface{}) error

DecodeExtension decodes extension at key into dst.

func (Extensions) DecodeExtensions added in v0.1.0

func (e Extensions) DecodeExtensions(dst interface{}) error

Decode decodes all extensions into dst.

func (Extensions) Extension

func (e Extensions) Extension(key Text) (interface{}, bool)

Extension returns an extension by name

func (*Extensions) SetExtension

func (e *Extensions) SetExtension(key Text, val interface{}) error

SetExtension encodes val and sets the result to key

func (*Extensions) SetRawExtension added in v0.1.0

func (e *Extensions) SetRawExtension(key Text, val []byte)

SetRawExtension sets the raw JSON encoded val to key

type ExternalDocs

type ExternalDocs struct {
	Location   `json:"-"`
	Extensions `json:"-"`

	// The URL for the target documentation. This MUST be in the form of a URL.
	//
	// 	*required*
	URL *uri.URI `json:"url"`

	// A description of the target documentation. CommonMark syntax MAY be used
	// for rich text representation.
	Description Text `json:"description,omitempty"`
}

ExternalDocs allows referencing an external resource for extended documentation.

func (*ExternalDocs) Anchors added in v0.1.0

func (*ExternalDocs) Anchors() (*Anchors, error)

func (*ExternalDocs) Kind added in v0.1.0

func (*ExternalDocs) Kind() Kind

func (ExternalDocs) MarshalJSON

func (ed ExternalDocs) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (ExternalDocs) MarshalYAML

func (ed ExternalDocs) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*ExternalDocs) Nodes added in v0.1.0

func (ed *ExternalDocs) Nodes() []Node

func (*ExternalDocs) Refs added in v0.1.0

func (*ExternalDocs) Refs() []Ref

func (*ExternalDocs) UnmarshalJSON

func (ed *ExternalDocs) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*ExternalDocs) UnmarshalYAML

func (ed *ExternalDocs) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Header struct {
	// OpenAPI extensions
	Extensions `json:"-"`
	Location   `json:"-"`

	// A brief description of the parameter. This could contain examples of use.
	// CommonMark syntax MAY be used for rich text representation.
	Description Text `json:"description,omitempty"`

	// Determines whether this parameter is mandatory. If the parameter location
	// is "path", this property is REQUIRED and its value MUST be true.
	// Otherwise, the property MAY be included and its default value is false.
	Required *bool `json:"required,omitempty"`

	// Specifies that a parameter is deprecated and SHOULD be transitioned out
	// of usage. Default value is false.
	Deprecated *bool `json:"deprecated,omitempty"`

	// Sets the ability to pass empty-valued parameters. This is valid only for
	// query parameters and allows sending a parameter with an empty value.
	// Default value is false. If style is used, and if behavior is n/a (cannot
	// be serialized), the value of allowEmptyValue SHALL be ignored. Use of
	// this property is NOT RECOMMENDED, as it is likely to be removed in a
	// later revision.
	AllowEmptyValue *bool `json:"allowEmptyValue,omitempty"`

	// Describes how the parameter value will be serialized depending on the
	// type of the parameter value.
	// Default values (based on value of in):
	// 	- for query - form;
	// 	- for path - simple;
	// 	- for header - simple;
	// 	- for cookie - form.
	Style Text `json:"style,omitempty"`

	// When this is true, parameter values of type array or object generate
	// separate parameters for each value of the array or key-value pair of the
	// map. For other types of parameters this property has no effect. When
	// style is form, the default value is true. For all other styles, the
	// default value is false.
	Explode *bool `json:"explode,omitempty"`

	// Determines whether the parameter value SHOULD allow reserved characters,
	// as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included without
	// percent-encoding. This property only applies to parameters with an in
	// value of query. The default value is false.
	AllowReserved *bool `json:"allowReserved,omitempty"`

	// The schema defining the type used for the parameter.
	Schema *Schema `json:"schema,omitempty"`

	// Examples of the parameter's potential value. Each example SHOULD
	// contain a value in the correct format as specified in the parameter
	// encoding. The examples field is mutually exclusive of the example
	// field. Furthermore, if referencing a schema that contains an example,
	// the examples value SHALL override the example provided by the schema.
	Examples *ExampleMap `json:"examples,omitempty"`

	// Example of the parameter's potential value. The example SHOULD match the
	// specified schema and encoding properties if present. The example field is
	// mutually exclusive of the examples field. Furthermore, if referencing a
	// schema that contains an example, the example value SHALL override the
	// example provided by the schema. To represent examples of media types that
	// cannot naturally be represented in JSON or YAML, a string value can
	// contain the example with escaping where necessary.
	Example jsonx.RawMessage `json:"example,omitempty"`
}

Header follows the structure of the Parameter Object with the following changes:

  • name MUST NOT be specified, it is given in the corresponding headers map.
  • in MUST NOT be specified, it is implicitly in header.
  • All traits that are affected by the location MUST be applicable to a location of header (for example, style).

func (*Header) Anchors added in v0.1.0

func (h *Header) Anchors() (*Anchors, error)

func (*Header) Kind added in v0.1.0

func (*Header) Kind() Kind

func (Header) MarshalJSON added in v0.1.0

func (h Header) MarshalJSON() ([]byte, error)

func (Header) MarshalYAML added in v0.1.0

func (h Header) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Header) Nodes added in v0.1.0

func (h *Header) Nodes() []Node

func (*Header) Refs added in v0.1.0

func (h *Header) Refs() []Ref

func (*Header) UnmarshalJSON added in v0.1.0

func (h *Header) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into h

func (*Header) UnmarshalYAML added in v0.1.0

func (h *Header) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type HeaderMap added in v0.1.0

type HeaderMap = ComponentMap[*Header]

HeaderMap holds reusable HeaderMap.

type In

type In = Text

type Info

type Info struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// Version of the OpenAPI document (which is distinct from the OpenAPI
	// Specification version or the API implementation version).
	//
	// 	*required*
	Version Text `json:"version"`

	// The title of the API.
	//
	// 	*required*
	Title Text `json:"title"`

	// A short summary of the API.
	Summary Text `json:"summary,omitempty"`

	// A description of the API. CommonMark syntax MAY be used for rich text
	// representation.
	Description Text `json:"description,omitempty"`

	// A URL to the Terms of Service for the API. This MUST be in the form of a
	// URL.
	TermsOfService Text `json:"termsOfService,omitempty" bson:"termsOfService,omitempty"`

	// The contact information for the exposed API.
	Contact *Contact `json:"contact,omitempty" bson:"contact,omitempty"`

	// License information for the exposed API.
	License *License `json:"license,omitempty" bson:"license,omitempty"`
}

Info provides metadata about the API. The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience.

func (*Info) Anchors added in v0.1.0

func (*Info) Anchors() (*Anchors, error)

func (*Info) Kind added in v0.1.0

func (*Info) Kind() Kind

func (Info) MarshalJSON

func (i Info) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Info) MarshalYAML

func (i Info) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Info) Refs added in v0.1.0

func (*Info) Refs() []Ref

func (*Info) SemVer added in v0.1.0

func (i *Info) SemVer() (*semver.Version, error)

func (*Info) UnmarshalJSON

func (i *Info) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Info) UnmarshalYAML

func (i *Info) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Item added in v0.2.0

type Item[T node] struct {
	Location
	Key   Text
	Value T
}

type JSONObjEntry added in v0.1.0

type JSONObjEntry struct {
	Key   Text
	Value jsonx.RawMessage
}

type KeyValue added in v0.1.0

type KeyValue[V any] struct {
	Key   Text
	Value V
}

type Kind added in v0.1.0

type Kind uint16
const (
	KindUndefined                Kind = iota
	KindDocument                      // *Document
	KindComponents                    // *Components
	KindExample                       // *Example
	KindExampleMap                    // *ExampleMap
	KindExampleComponent              // *Component[*Example]
	KindSchema                        // *Schema
	KindSchemaSlice                   // *SchemaSlice
	KindSchemaMap                     // *SchemaMap
	KindSchemaRef                     // *SchemaRef
	KindDiscriminator                 // *Discriminator
	KindHeader                        // *Header
	KindHeaderMap                     // *HeaderMap
	KindHeaderSlice                   // *HeaderSlice
	KindHeaderComponent               // *Component[*Header]
	KindLink                          // *Link
	KindLinkComponent                 // *Component[*Link]
	KindLinkMap                       // *LinkMap
	KindResponse                      // *Response
	KindResponseMap                   // *ResponseMap
	KindResponseComponent             // *Component[*Response]
	KindParameter                     // *Parameter
	KindParameterComponent            // *Component[*Parameter]
	KindParameterSlice                // *ParameterSlice
	KindParameterMap                  // *ParameterMap
	KindPaths                         // *Paths
	KindPathItem                      // *PathItem
	KindPathItemComponent             // *Component[*PathItem]
	KindPathItemMap                   // *PathItemMap
	KindRequestBody                   // *RequestBody
	KindRequestBodyMap                // *RequestBodyMap
	KindRequestBodyComponent          // *Component[*RequestBody]
	KindCallbacks                     // *Callbacks
	KindCallbacksComponent            // *Component[*Callbacks]
	KindCallbacksMap                  // *CallbacksMap
	KindSecurityRequirementSlice      // *SecurityRequirements
	KindSecurityRequirement           // *SecurityRequirement
	KindSecurityRequirementItem       // *SecurityRequirementItem
	KindSecurityScheme                // *SecurityScheme
	KindSecuritySchemeComponent       // *Component[*SecurityScheme]
	KindSecuritySchemeMap             // *SecuritySchemeMap
	KindOperation                     // *Operation
	KindOperationRef                  // *OperationRef
	KindLicense                       // *License
	KindTag                           // *Tag
	KindTagSlice                      // *TagSlice
	KindMediaType                     // *MediaType
	KindMediaTypeMap                  // *MediaTypeMap
	KindInfo                          // *Info
	KindContact                       // *Contact
	KindEncoding                      // *Encoding
	KindEncodingMap                   // *EncodingMap
	KindExternalDocs                  // *ExternalDocs
	KindReference                     // *Reference
	KindServer                        // *Server
	KindServerComponent               // *Component[*Server]
	KindServerSlice                   // *ServerSlice
	KindServerVariable                // *ServerVariable
	KindServerVariableMap             // *ServerVariableMap
	KindOAuthFlow                     // *OAuthFlow
	KindOAuthFlows                    // *OAuthFlows
	KindXML                           // *XML
	KindScope                         // *Scope
	KindScopes                        // *Scopes
)

func (Kind) String added in v0.1.0

func (k Kind) String() string

type License

type License struct {
	Location `json:"-"`

	// The license name used for the API.
	//
	// 	*required*
	Name Text `json:"name"`

	// An SPDX license expression for the API. The identifier field is mutually
	// exclusive of the url field.
	Identifier Text `json:"identifier,omitempty"`
	// A URL to the license used for the API. This MUST be in the form of a URL.
	// The url field is mutually exclusive of the identifier field.
	URL *uri.URI `json:"url,omitempty"`
}

License information for the exposed API.

func (*License) Anchors added in v0.1.0

func (*License) Anchors() (*Anchors, error)

func (*License) Kind added in v0.1.0

func (*License) Kind() Kind

Kind returns KindLicense

func (License) MarshalJSON added in v0.1.0

func (l License) MarshalJSON() ([]byte, error)
func (l *License) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
	if err := ptr.Validate(); err != nil {
		return nil, err
	}
	return l.resolveNodeByPointer(ptr)
}

func (l *License) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
	if ptr.IsRoot() {
		return l, nil
	}
	tok, _ := ptr.NextToken()
	return nil, newErrNotResolvable(l.absolute, tok)
}

MarshalJSON marshals JSON

func (License) MarshalYAML added in v0.1.0

func (l License) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler

func (*License) Refs added in v0.1.0

func (*License) Refs() []Ref

func (*License) UnmarshalJSON added in v0.1.0

func (l *License) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*License) UnmarshalYAML added in v0.1.0

func (l *License) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler

type Link struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The name of an existing, resolvable OAS operation, as defined with a
	// unique operationId. This field is mutually exclusive of the operationRef
	// field.
	OperationID Text `json:"operationId,omitempty"`

	// A relative or absolute URI reference to an OAS operation.
	//
	// This field is mutually exclusive of the operationId field, and MUST point
	// to an Operation Object.
	OperationRef *OperationRef `json:"operationRef,omitempty"`

	// A description of the link. CommonMark syntax MAY be used for rich text
	// representation.
	Description Text `json:"description,omitempty"`

	// A map representing parameters to pass to an operation as specified with
	// operationID or identified via operationRef.
	//
	// The key is the parameter name
	// to be used, whereas the value can be a constant or an expression to be
	// evaluated and passed to the linked operation.
	//
	// The parameter name can be
	// qualified using the parameter location [{in}.]{name} for operations that
	// use the same parameter name in different locations (e.g. path.id).
	Parameters OrderedJSONObj `json:"parameters,omitempty"`

	// A literal value or {expression} to use as a request body when calling the
	// target operation.
	RequestBody jsonx.RawMessage `json:"requestBody,omitempty"`
}

Link represents a possible design-time link for a response. The presence of a link does not guarantee the caller's ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.

Unlike dynamic links (i.e. links provided in the response payload), the OAS linking mechanism does not require link information in the runtime response.

For computing links, and providing instructions to execute them, a runtime expression is used for accessing values in an operation and using them as parameters while invoking the linked operation.

func (*Link) Anchors added in v0.1.0

func (l *Link) Anchors() (*Anchors, error)

func (*Link) DecodeRequestBody added in v0.1.0

func (l *Link) DecodeRequestBody(dst interface{}) error

DecodeRequestBody decodes l.RequestBody into dst

dst should be a pointer to a concrete type

func (*Link) Kind added in v0.1.0

func (*Link) Kind() Kind

func (Link) MarshalJSON added in v0.1.0

func (l Link) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Link) MarshalYAML added in v0.1.0

func (l Link) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Link) Nodes added in v0.1.0

func (l *Link) Nodes() []Node

func (*Link) Refs added in v0.1.0

func (l *Link) Refs() []Ref

func (*Link) UnmarshalJSON added in v0.1.0

func (l *Link) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Link) UnmarshalYAML added in v0.1.0

func (l *Link) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type LinkMap added in v0.1.0

type LinkMap = ComponentMap[*Link]

LinkMap is a Map of either LinkMap or References to LinkMap

type LoadOpts added in v0.1.0

type LoadOpts struct {
	DefaultSchemaDialect *uri.URI
}

type Location added in v0.1.0

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

func NewLocation added in v0.1.0

func NewLocation(uri uri.URI) (Location, error)

func (Location) AbsoluteLocation added in v0.1.0

func (l Location) AbsoluteLocation() uri.URI

func (Location) AppendLocation added in v0.1.0

func (l Location) AppendLocation(p string) Location

func (Location) IsRelativeTo added in v0.1.0

func (l Location) IsRelativeTo(uri *uri.URI) bool

func (Location) RelativeLocation added in v0.1.0

func (l Location) RelativeLocation() jsonpointer.Pointer

RelativeLocation returns a jsonpointer.Pointer of the path from the containing resource file.

func (Location) String added in v0.1.0

func (l Location) String() string

type Map added in v0.1.0

type Map[T any] struct {
	Items []KeyValue[T]
}

func (*Map[T]) Del added in v0.1.0

func (m *Map[T]) Del(key Text)

func (Map[T]) Get added in v0.1.0

func (m Map[T]) Get(key Text) (T, bool)

func (Map[T]) Has added in v0.1.0

func (m Map[T]) Has(key Text) bool

func (Map[T]) MarshalJSON added in v0.1.0

func (m Map[T]) MarshalJSON() ([]byte, error)

func (*Map[T]) Set added in v0.1.0

func (m *Map[T]) Set(key Text, value T)

func (*Map[T]) UnmarshalJSON added in v0.1.0

func (m *Map[T]) UnmarshalJSON(data []byte) error

type MediaType

type MediaType struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The schema defining the content of the request, response, or parameter.
	Schema *Schema `json:"schema,omitempty"`
	// Example of the media type. The example object SHOULD be in the correct
	// format as specified by the media type. The example field is mutually
	// exclusive of the examples field. Furthermore, if referencing a schema
	// which contains an example, the example value SHALL override the example
	// provided by the schema.
	Example jsonx.RawMessage `json:"example,omitempty"`
	// Examples of the media type. Each example object SHOULD match the media
	// type and specified schema if present. The examples field is mutually
	// exclusive of the example field. Furthermore, if referencing a schema
	// which contains an example, the examples value SHALL override the example
	// provided by the schema.
	Examples *ExampleMap `json:"examples,omitempty"`
	// A map between a property name and its encoding information. The key,
	// being the property name, MUST exist in the schema as a property. The
	// encoding object SHALL only apply to requestBody objects when the media
	// type is multipart or application/x-www-form-urlencoded.
	Encoding *EncodingMap `json:"encoding,omitempty"`
}

MediaType provides schema and examples for the media type identified by its key.

func (*MediaType) Anchors added in v0.1.0

func (mt *MediaType) Anchors() (*Anchors, error)

func (*MediaType) Kind added in v0.1.0

func (*MediaType) Kind() Kind

func (MediaType) MarshalJSON

func (mt MediaType) MarshalJSON() ([]byte, error)

MarshalJSON marshals mt into JSON

func (MediaType) MarshalYAML

func (mt MediaType) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*MediaType) Nodes added in v0.1.0

func (mt *MediaType) Nodes() []Node

func (*MediaType) Refs added in v0.1.0

func (mt *MediaType) Refs() []Ref

func (*MediaType) UnmarshalJSON

func (mt *MediaType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into mt

func (*MediaType) UnmarshalYAML

func (mt *MediaType) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type MediaTypeMap added in v0.1.0

type MediaTypeMap = ObjMap[*MediaType]

ContentMap / MediaTypeMap is a map containing descriptions of potential response payloads. The key is a media type or media type range and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*

type Node added in v0.1.0

type Node interface {
	// AbsoluteLocation returns the absolute path of the node in URI form.
	// This includes the URI path of the resource and the JSON pointer
	// of the node.
	//
	// e.g. openapi.json#/components/schemas/Example
	AbsoluteLocation() uri.URI

	// RelativeLocation returns the path as a JSON pointer for the Node.
	RelativeLocation() jsonpointer.Pointer

	// Kind returns the Kind for the given Node
	Kind() Kind

	// Anchors returns a list of all Anchors in the Node and all descendants.
	Anchors() (*Anchors, error)

	// Refs returns a list of all Refs from the Node and all descendants.
	Refs() []Ref

	// MarshalJSON marshals JSON
	//
	// MarshalJSON satisfies the json.Marshaler interface
	MarshalJSON() ([]byte, error)
	// UnmarshalJSON unmarshals JSON
	//
	// UnmarshalJSON satisfies the json.Unmarshaler interface
	UnmarshalJSON(data []byte) error

	// UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface
	MarshalYAML() (interface{}, error)

	// UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface
	UnmarshalYAML(value *yaml.Node) error
}

type Number

type Number = jsonx.Number

type OAuthFlow

type OAuthFlow struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The authorization URL to be used for this flow. This MUST be in the form
	// of a URL. The OAuth2 standard requires the use of TLS.
	//
	// Applies to: OAuth2 ("implicit", "authorizationCode")
	//
	// 	*required*
	AuthorizationURL Text `json:"authorizationUrl,omitempty"`
	// The token URL to be used for this flow. This MUST be in the form of a
	// URL. The OAuth2 standard requires the use of TLS.
	//
	// Applies to: OAuth2Flow ("password", "clientCredentials", "authorizationCode")
	//
	// 	*required*
	TokenURL Text `json:"tokenUrl,omitempty"`
	// The URL to be used for obtaining refresh tokens. This MUST be in the form
	// of a URL. The OAuth2 standard requires the use of TLS.
	RefreshURL Text `json:"refreshUrl,omitempty"`
	// The available scopes for the OAuth2 security scheme. A map between the
	// scope name and a short description for it. The map MAY be empty.
	//
	// 	*required*
	Scopes *Scopes `json:"scopes"`
}

OAuthFlow configuration details for a supported OAuth Flow

func (*OAuthFlow) Anchors added in v0.1.0

func (f *OAuthFlow) Anchors() (*Anchors, error)

func (*OAuthFlow) Kind added in v0.1.0

func (*OAuthFlow) Kind() Kind

func (OAuthFlow) MarshalJSON

func (o OAuthFlow) MarshalJSON() ([]byte, error)

MarshalJSON marshals json

func (OAuthFlow) MarshalYAML

func (o OAuthFlow) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*OAuthFlow) Nodes added in v0.1.0

func (r *OAuthFlow) Nodes() []Node
func (f *OAuthFlow) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
	if ptr.IsRoot() {
		return f, nil
	}
	nxt, tok, _ := ptr.Next()
	switch tok {
	case "scopes":
		if f.Scopes == nil {
			return nil, newErrNotFound(f.Location.AbsoluteLocation(), tok)
		}
		return f.Scopes.resolveNodeByPointer(nxt)
	default:
		return nil, newErrNotResolvable(f.Location.AbsoluteLocation(), tok)
	}
}

func (*OAuthFlow) Refs added in v0.1.0

func (f *OAuthFlow) Refs() []Ref

func (*OAuthFlow) UnmarshalJSON

func (o *OAuthFlow) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json

func (*OAuthFlow) UnmarshalYAML

func (o *OAuthFlow) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type OAuthFlows

type OAuthFlows struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// Configuration for the OAuth Implicit flow
	Implicit *OAuthFlow `json:"implicit,omitempty"`
	// Configuration for the OAuth Resource Owner Password flow
	Password *OAuthFlow `json:"password,omitempty"`
	// Configuration for the OAuth Client Credentials flow. Previously called
	// application in OpenAPI 2.0.
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
	// Configuration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
}

OAuthFlows allows configuration of the supported OAuth Flows.

func (*OAuthFlows) Anchors added in v0.1.0

func (f *OAuthFlows) Anchors() (*Anchors, error)

func (*OAuthFlows) Kind added in v0.1.0

func (*OAuthFlows) Kind() Kind

func (OAuthFlows) MarshalJSON

func (o OAuthFlows) MarshalJSON() ([]byte, error)

MarshalJSON marshals json

func (OAuthFlows) MarshalYAML

func (f OAuthFlows) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*OAuthFlows) Nodes added in v0.1.0

func (f *OAuthFlows) Nodes() []Node

func (*OAuthFlows) Refs added in v0.1.0

func (f *OAuthFlows) Refs() []Ref

func (*OAuthFlows) UnmarshalJSON

func (f *OAuthFlows) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json

func (*OAuthFlows) UnmarshalYAML

func (f *OAuthFlows) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ObjMap added in v0.1.0

type ObjMap[T node] struct {
	Location
	Items []Item[T]
}

ObjMap is a map of OpenAPI Objects of type T

func (*ObjMap[T]) Anchors added in v0.1.0

func (om *ObjMap[T]) Anchors() (*Anchors, error)

func (*ObjMap[T]) Del added in v0.1.0

func (om *ObjMap[T]) Del(key Text)

func (*ObjMap[T]) Get added in v0.1.0

func (om *ObjMap[T]) Get(key Text) T

func (*ObjMap[T]) Kind added in v0.1.0

func (*ObjMap[T]) Kind() Kind

func (*ObjMap[T]) MarshalJSON added in v0.1.0

func (om *ObjMap[T]) MarshalJSON() ([]byte, error)

func (ObjMap[T]) MarshalYAML added in v0.1.0

func (om ObjMap[T]) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*ObjMap[T]) Refs added in v0.1.0

func (om *ObjMap[T]) Refs() []Ref

func (*ObjMap[T]) Set added in v0.1.0

func (om *ObjMap[T]) Set(key Text, obj T)

func (*ObjMap[T]) UnmarshalJSON added in v0.1.0

func (om *ObjMap[T]) UnmarshalJSON(data []byte) error

func (*ObjMap[T]) UnmarshalYAML added in v0.1.0

func (om *ObjMap[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ObjSlice added in v0.1.0

type ObjSlice[T node] struct {
	Location `json:"-"`
	Items    []T `json:"-"`
}

func (*ObjSlice[T]) Anchors added in v0.1.0

func (os *ObjSlice[T]) Anchors() (*Anchors, error)

Anchors implements node

func (*ObjSlice[T]) Kind added in v0.1.0

func (os *ObjSlice[T]) Kind() Kind

Kind implements node

func (*ObjSlice[T]) MarshalJSON added in v0.1.0

func (os *ObjSlice[T]) MarshalJSON() ([]byte, error)

func (ObjSlice[T]) MarshalYAML added in v0.1.0

func (os ObjSlice[T]) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*ObjSlice[T]) Refs added in v0.1.0

func (os *ObjSlice[T]) Refs() []Ref

Refs implements node

func (*ObjSlice[T]) UnmarshalJSON added in v0.1.0

func (os *ObjSlice[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements node

func (*ObjSlice[T]) UnmarshalYAML added in v0.1.0

func (os *ObjSlice[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Operation

type Operation struct {
	// Location contains information about the location of the node in the
	// document or referenced resource
	Location   `json:"-"`
	Extensions `json:"-"`

	// Unique string used to identify the operation. The id MUST be unique among
	// all operations described in the API. The operationId value is
	// case-sensitive. Tools and libraries MAY use the operationId to uniquely
	// identify an operation, therefore, it is RECOMMENDED to follow common
	// programming naming conventions.
	OperationID Text `json:"operationId,omitempty"`

	// Declares this operation to be deprecated. Consumers SHOULD refrain from
	// usage of the declared operation. Default value is false.
	Deprecated bool `json:"deprecated,omitempty"`

	// A short summary of what the operation does.
	Summary Text `json:"summary,omitempty"`

	// A verbose explanation of the operation behavior. CommonMark syntax MAY be
	// used for rich text representation.
	Description Text `json:"description,omitempty"`

	// A list of tags for API documentation control. Tags can be used for
	// logical grouping of operations by resources or any other qualifier.
	Tags Texts `json:"tags,omitempty"`

	// A list of parameters that are applicable for this operation. If a
	// parameter is already defined at the Path Item, the new definition will
	// override it but can never remove it. The list MUST NOT include duplicated
	// parameters. A unique parameter is defined by a combination of a name and
	// location. The list can use the Reference Object to link to parameters
	// that are defined at the OpenAPI Object's components/parameters.
	Parameters *ParameterSlice `json:"parameters,omitempty"`

	// The request body applicable for this operation. The requestBody is fully
	// supported in HTTP methods where the HTTP 1.1 specification RFC7231 has
	// explicitly defined semantics for request bodies. In other cases where the
	// HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is
	// permitted but does not have well-defined semantics and SHOULD be avoided
	// if possible.
	RequestBody *Component[*RequestBody] `json:"requestBody,omitempty"`

	// The list of possible responses as they are returned from executing this
	// operation.
	Responses *ResponseMap `json:"responses,omitempty"`

	// A map of possible out-of band callbacks related to the parent operation.
	// The key is a unique identifier for the Callback Object. Each value in the
	// map is a Callback Object that describes a request that may be initiated
	// by the API provider and the expected responses.
	Callbacks *CallbacksMap `json:"callbacks,omitempty"`

	// A declaration of which security mechanisms can be used for this
	// operation. The list of values includes alternative security requirement
	// objects that can be used. Only one of the security requirement objects
	// need to be satisfied to authorize a request. To make security optional,
	// an empty security requirement ({}) can be included in the array. This
	// definition overrides any declared top-level security. To remove a
	// top-level security declaration, an empty array can be used.
	Security *SecurityRequirementMap `json:"security,omitempty"`

	// An alternative server array to service this operation. If an alternative
	// server object is specified at the Path Item Object or Root level, it will
	// be overridden by this value.
	Servers *ServerSlice `json:"servers,omitempty"`

	// externalDocs	Additional external documentation.
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}

Operation describes a single API operation on a path.

func (*Operation) Anchors added in v0.1.0

func (o *Operation) Anchors() (*Anchors, error)

func (*Operation) Kind added in v0.1.0

func (*Operation) Kind() Kind

func (Operation) MarshalJSON

func (o Operation) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Operation) MarshalYAML

func (o Operation) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Operation) Nodes added in v0.1.0

func (o *Operation) Nodes() []Node

func (*Operation) Refs added in v0.1.0

func (o *Operation) Refs() []Ref

func (*Operation) UnmarshalJSON

func (o *Operation) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Operation) UnmarshalYAML

func (o *Operation) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type OperationRef added in v0.1.0

type OperationRef struct {
	Location
	Ref      *uri.URI
	Resolved *Operation
}

func (*OperationRef) Anchors added in v0.1.0

func (*OperationRef) Anchors() (*Anchors, error)

func (*OperationRef) IsResolved added in v0.1.0

func (or *OperationRef) IsResolved() bool

func (*OperationRef) Kind added in v0.1.0

func (*OperationRef) Kind() Kind

func (OperationRef) MarshalJSON added in v0.1.0

func (or OperationRef) MarshalJSON() ([]byte, error)

func (OperationRef) MarshalYAML added in v0.1.0

func (or OperationRef) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*OperationRef) Nodes added in v0.1.0

func (or *OperationRef) Nodes() []Node

func (*OperationRef) RefKind added in v0.1.0

func (*OperationRef) RefKind() Kind

func (*OperationRef) RefType added in v0.1.0

func (*OperationRef) RefType() RefType

func (*OperationRef) Refs added in v0.1.0

func (or *OperationRef) Refs() []Ref

func (*OperationRef) ResolvedNode added in v0.1.0

func (or *OperationRef) ResolvedNode() Node

func (*OperationRef) URI added in v0.1.0

func (or *OperationRef) URI() *uri.URI

URI returns the reference URI

func (*OperationRef) UnmarshalJSON added in v0.1.0

func (or *OperationRef) UnmarshalJSON(data []byte) error

func (*OperationRef) UnmarshalYAML added in v0.1.0

func (or *OperationRef) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type OrderedJSONObj added in v0.1.0

type OrderedJSONObj []JSONObjEntry

func (OrderedJSONObj) Decode added in v0.1.0

func (j OrderedJSONObj) Decode(dst interface{}) error

Decode decodes all of j into dst

For field-level decoding, use DecodeValue

func (OrderedJSONObj) DecodeValue added in v0.1.0

func (j OrderedJSONObj) DecodeValue(key Text, dst interface{}) error

DecodeValue decodes a given parameter by key.

func (OrderedJSONObj) Get added in v0.1.0

func (j OrderedJSONObj) Get(key Text) jsonx.RawMessage

func (OrderedJSONObj) Has added in v0.1.0

func (j OrderedJSONObj) Has(key Text) bool

Has returns true if key exists in j

func (OrderedJSONObj) Map added in v0.1.0

func (j OrderedJSONObj) Map() map[string]jsonx.RawMessage

func (OrderedJSONObj) MarshalJSON added in v0.1.0

func (j OrderedJSONObj) MarshalJSON() ([]byte, error)

func (*OrderedJSONObj) Set added in v0.1.0

func (j *OrderedJSONObj) Set(key Text, value interface{}) error

Set concrete object to lp. To add JSON, use SetEncoded

func (*OrderedJSONObj) UnmarshalJSON added in v0.1.0

func (j *OrderedJSONObj) UnmarshalJSON(data []byte) error

type Parameter

type Parameter struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The name of the parameter. Parameter names are case sensitive:
	//
	// - If In is "path", the name field MUST correspond to a template
	// expression occurring within the path field in the Paths Object.
	// See Path Templating for further information.
	//
	// - If In is "header" and the name field is "Accept", "Content-Type"
	// or "Authorization", the parameter definition SHALL be ignored.
	//
	// - For all other cases, the name corresponds to the parameter name
	// used by the in property.
	//
	//  *required*
	Name Text `json:"name"`

	// The location of the parameter. Possible values are "query", "header",
	// "path" or "cookie".
	//
	//  *required*
	In In `json:"in"`

	// A brief description of the parameter. This could contain examples of use.
	// CommonMark syntax MAY be used for rich text representation.
	Description Text `json:"description,omitempty"`

	// Determines whether this parameter is mandatory. If the parameter location
	// is "path", this property is REQUIRED and its value MUST be true.
	// Otherwise, the property MAY be included and its default value is false.
	Required *bool `json:"required,omitempty"`

	// Specifies that a parameter is deprecated and SHOULD be transitioned out
	// of usage. Default value is false.
	Deprecated bool `json:"deprecated,omitempty"`

	// Sets the ability to pass empty-valued parameters. This is valid only for
	// query parameters and allows sending a parameter with an empty value.
	// Default value is false. If style is used, and if behavior is n/a (cannot
	// be serialized), the value of allowEmptyValue SHALL be ignored. Use of
	// this property is NOT RECOMMENDED, as it is likely to be removed in a
	// later revision.
	AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`

	// Describes how the parameter value will be serialized depending on the
	// type of the parameter value.
	// Default values (based on value of in):
	//  - for query - form;
	// 	- for path - simple;
	// 	- for header - simple;
	// 	- for cookie - form.
	Style Text `json:"style,omitempty"`

	// When this is true, parameter values of type array or object generate
	// separate parameters for each value of the array or key-value pair of the
	// map. For other types of parameters this property has no effect. When
	// style is form, the default value is true. For all other styles, the
	// default value is false.
	Explode bool `json:"explode,omitempty"`

	// Determines whether the parameter value SHOULD allow reserved characters,
	// as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included without
	// percent-encoding. This property only applies to parameters with an in
	// value of query. The default value is false.
	AllowReserved bool `json:"allowReserved,omitempty"`

	// The schema defining the type used for the parameter.
	Schema *Schema `json:"schema,omitempty"`

	// Examples of the parameter's potential value. Each example SHOULD
	// contain a value in the correct format as specified in the parameter
	// encoding. The examples field is mutually exclusive of the example
	// field. Furthermore, if referencing a schema that contains an example,
	// the examples value SHALL override the example provided by the schema.
	Examples *ExampleMap `json:"examples,omitempty"`

	Example jsonx.RawMessage `json:"example,omitempty"`

	// For more complex scenarios, the content property can define the media
	// type and schema of the parameter. A parameter MUST contain either a
	// schema property, or a content property, but not both. When example or
	// examples are provided in conjunction with the schema object, the example
	// MUST follow the prescribed serialization strategy for the parameter.
	Content *ContentMap `json:"content,omitempty"`
}

Parameter describes a single operation parameter.

A unique parameter is defined by a combination of a name and location.

func (*Parameter) Anchors added in v0.1.0

func (p *Parameter) Anchors() (*Anchors, error)

func (*Parameter) Kind added in v0.1.0

func (*Parameter) Kind() Kind

func (Parameter) MarshalJSON added in v0.1.0

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

MarshalJSON marshals h into JSON

func (Parameter) MarshalYAML added in v0.1.0

func (p Parameter) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Parameter) Nodes added in v0.1.0

func (p *Parameter) Nodes() []Node

func (*Parameter) Refs added in v0.1.0

func (p *Parameter) Refs() []Ref

func (*Parameter) UnmarshalJSON added in v0.1.0

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

UnmarshalJSON unmarshals json into p

func (*Parameter) UnmarshalYAML added in v0.1.0

func (p *Parameter) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ParameterMap added in v0.1.0

type ParameterMap = ComponentMap[*Parameter]

ParameterMap is a map of Parameter

type ParameterSlice added in v0.1.0

type ParameterSlice = ComponentSlice[*Parameter]

ParameterSlice is list of parameters that are applicable for a given operation. If a parameter is already defined at the Path Item, the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. The list can use the Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.

Can either be a Parameter or a Reference

type PathItem added in v0.1.0

type PathItem struct {
	Location   `json:"-"`
	Extensions `json:"-"`

	// An optional, string summary, intended to apply to all operations in this path.
	Summary Text `json:"summary,omitempty"`

	// An optional, string description, intended to apply to all operations in
	// this path. CommonMark syntax MAY be used for rich text representation.
	Description Text `json:"description,omitempty"`

	// A list of parameters that are applicable for all the operations described
	// under this path. These parameters can be overridden at the operation
	// level, but cannot be removed there. The list MUST NOT include duplicated
	// parameters. A unique parameter is defined by a combination of a name and
	// location. The list can use the Reference Object to link to parameters
	// that are defined at the OpenAPI Object's components/parameters.
	Parameters *ParameterSlice `json:"parameters,omitempty"`

	// A definition of a GET operation on this path.
	Get *Operation `json:"get,omitempty"`

	// A definition of a PUT operation on this path.
	Put *Operation `json:"put,omitempty"`

	// A definition of a POST operation on this path.
	Post *Operation `json:"post,omitempty"`

	// A definition of a DELETE operation on this path.
	Delete *Operation `json:"delete,omitempty"`

	// A definition of a OPTIONS operation on this path.
	Options *Operation `json:"options,omitempty"`

	// A definition of a HEAD operation on this path.
	Head *Operation `json:"head,omitempty"`

	// A definition of a PATCH operation on this path.
	Patch *Operation `json:"patch,omitempty"`

	// A definition of a TRACE operation on this path.
	Trace *Operation `json:"trace,omitempty"`

	// An alternative server array to service all operations in this path.
	Servers *ServerSlice `json:"servers,omitempty"`
}

PathItem describes the operations available on a single path. A PathItem Item MAY be empty, due to ACL constraints. The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.

func (*PathItem) Anchors added in v0.1.0

func (pi *PathItem) Anchors() (*Anchors, error)

func (*PathItem) Kind added in v0.1.0

func (*PathItem) Kind() Kind

func (PathItem) MarshalJSON added in v0.1.0

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

MarshalJSON marshals p into JSON

func (PathItem) MarshalYAML added in v0.1.0

func (p PathItem) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*PathItem) Nodes added in v0.1.0

func (pi *PathItem) Nodes() []Node

func (*PathItem) Refs added in v0.1.0

func (pi *PathItem) Refs() []Ref

func (*PathItem) UnmarshalJSON added in v0.1.0

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

UnmarshalJSON unmarshals json into p

func (*PathItem) UnmarshalYAML added in v0.1.0

func (p *PathItem) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type PathItemEntry added in v0.1.0

type PathItemEntry struct {
	Key      text.Text
	PathItem *PathItem
}

type PathItemMap added in v0.1.0

type PathItemMap = ComponentMap[*PathItem]

PathItemMap is a map of Paths that can either be a Path or a Reference

type PathItems

type PathItems = ObjMap[*PathItem]

type Paths

type Paths struct {
	Extensions `json:"-"`

	// Items are the Path
	PathItems `json:"-"`
}

Paths holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the Server Object in order to construct the full URL. The Paths MAY be empty, due to Access Control List (ACL) constraints.

func (*Paths) Anchors added in v0.1.0

func (p *Paths) Anchors() (*Anchors, error)

func (*Paths) Kind added in v0.1.0

func (*Paths) Kind() Kind

func (Paths) MarshalJSON

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

MarshalJSON marshals JSON

func (Paths) MarshalYAML added in v0.1.0

func (p Paths) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Paths) Nodes added in v0.1.0

func (p *Paths) Nodes() []Node

func (*Paths) UnmarshalJSON

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

UnmarshalJSON unmarshals JSON data into p

func (*Paths) UnmarshalYAML added in v0.1.0

func (p *Paths) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Ref added in v0.1.0

type Ref interface {
	Node
	URI() *uri.URI
	IsResolved() bool
	ResolvedNode() Node
	// ReferencedKind returns the Kind for the referenced node
	RefKind() Kind
	// RefType returns the RefType for the reference
	RefType() RefType
}

type RefType added in v0.1.0

type RefType uint8
const (
	RefTypeUndefined RefType = iota
	RefTypeComponent
	RefTypeSchema
	RefTypeSchemaDynamicRef
	RefTypeSchemaRecursiveRef
	RefTypeOperationRef
)

func (RefType) String added in v0.1.0

func (rk RefType) String() string

type Reference

type Reference[T refable] struct {
	// The reference identifier. This MUST be in the form of a URI.
	//
	// 	*required*
	Ref *uri.URI `json:"$ref"`

	// A short summary which by default SHOULD override that of the referenced
	// component. If the referenced object-type does not allow a summary field,
	// then this field has no effect.
	Summary Text `json:"summary,omitempty"`

	// A description which by default SHOULD override that of the referenced
	// component. CommonMark syntax MAY be used for rich text representation. If
	// the referenced object-type does not allow a description field, then this
	// field has no effect.
	Description Text `json:"description,omitempty"`

	// Location of the Reference
	Location `json:"-"`

	ReferencedKind Kind `json:"-"`

	Resolved T `json:"-"`
	// contains filtered or unexported fields
}

Reference is simple object to allow referencing other components in the OpenAPI document, internally and externally.

The $ref string value contains a URI [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986), which identifies the location of the value being referenced.

See the [rules for resolving Relative References](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relativeReferencesURI).

func (*Reference[T]) Anchors added in v0.1.0

func (r *Reference[T]) Anchors() (*Anchors, error)

func (*Reference[T]) IsResolved added in v0.1.0

func (r *Reference[T]) IsResolved() bool

func (*Reference[T]) Kind added in v0.1.0

func (r *Reference[T]) Kind() Kind

func (Reference[T]) MarshalJSON added in v0.1.0

func (r Reference[T]) MarshalJSON() ([]byte, error)

func (Reference[T]) MarshalYAML

func (r Reference[T]) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Reference[T]) Nodes added in v0.1.0

func (r *Reference[T]) Nodes() []Node

func (*Reference[T]) RefKind added in v0.1.0

func (r *Reference[T]) RefKind() Kind

func (*Reference[T]) RefType added in v0.1.0

func (*Reference[T]) RefType() RefType

func (*Reference[T]) Refs added in v0.1.0

func (*Reference[T]) Refs() []Ref

Refs returns nil as instances of Reference do not contain the referenced object

func (*Reference[T]) ResolvedNode added in v0.1.0

func (r *Reference[T]) ResolvedNode() Node

Referenced returns the resolved referenced Node

func (*Reference[T]) String added in v0.1.0

func (r *Reference[T]) String() string

func (*Reference[T]) URI added in v0.1.0

func (r *Reference[T]) URI() *uri.URI

func (*Reference[T]) UnmarshalJSON added in v0.1.0

func (r *Reference[T]) UnmarshalJSON(data []byte) error

func (*Reference[T]) UnmarshalYAML

func (r *Reference[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Regexp

type Regexp struct {
	*regexp.Regexp
}

Regexp is a wrapper around *regexp.Regexp to allow for marshinaling/unmarshaling

func (*Regexp) IsNil

func (sr *Regexp) IsNil() bool

IsNil returns true if either sr or sr.Regexp is nil

func (Regexp) MarshalJSON

func (sr Regexp) MarshalJSON() ([]byte, error)

MarshalJSON unmarshals data into sr

func (*Regexp) UnmarshalJSON

func (sr *Regexp) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals data into sr

type RequestBody

type RequestBody struct {
	Location   `json:"-"`
	Extensions `json:"-"`

	// A brief description of the request body. This could contain examples of
	// use. CommonMark syntax MAY be used for rich text representation.
	Description Text `json:"description,omitempty"`
	// The content of the request body. The key is a media type or media type range and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text
	//
	// *required*
	Content *ContentMap `json:"content,omitempty"`
	// Determines if the request body is required in the request. Defaults to false.
	Required bool `json:"required,omitempty"`
}

RequestBody describes a single request body.

func (*RequestBody) Anchors added in v0.1.0

func (rb *RequestBody) Anchors() (*Anchors, error)

func (*RequestBody) Kind added in v0.1.0

func (*RequestBody) Kind() Kind

func (RequestBody) MarshalJSON added in v0.1.0

func (rb RequestBody) MarshalJSON() ([]byte, error)

MarshalJSON marshals h into JSON

func (RequestBody) MarshalYAML added in v0.1.0

func (rb RequestBody) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*RequestBody) Nodes added in v0.1.0

func (rb *RequestBody) Nodes() []Node

func (*RequestBody) Refs added in v0.1.0

func (rb *RequestBody) Refs() []Ref

func (*RequestBody) UnmarshalJSON added in v0.1.0

func (rb *RequestBody) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into rb

func (*RequestBody) UnmarshalYAML added in v0.1.0

func (rb *RequestBody) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type RequestBodyMap added in v0.1.0

type RequestBodyMap = ComponentMap[*RequestBody]

RequestBodyMap is a map of RequestBody

type ResolutionError added in v0.1.0

type ResolutionError struct {
	URI      uri.URI
	Expected Kind
	Actual   Kind
	RefType  RefType
}

func (*ResolutionError) Error added in v0.1.0

func (e *ResolutionError) Error() string

func (*ResolutionError) Unwrap added in v0.1.0

func (e *ResolutionError) Unwrap() error

type Response

type Response struct {
	// A description of the response. CommonMark syntax MAY be used for rich
	// text representation.
	//
	// *required*
	Description Text `json:"description,omitempty"`
	// Maps a header name to its definition. RFC7230 states header names are
	// case insensitive. If a response header is defined with the name
	// "Content-Type", it SHALL be ignored.
	Headers *HeaderMap `json:"headers,omitempty"`
	// A map containing descriptions of potential response payloads. The key is
	// a media type or media type range and the value describes it. For
	// responses that match multiple keys, only the most specific key is
	// applicable. e.g. text/plain overrides text/*
	Content *ContentMap `json:"content,omitempty"`
	// A map of operations links that can be followed from the response. The key
	// of the map is a short name for the link, following the naming constraints
	// of the names for Component Objects.
	Links      *LinkMap `json:"links,omitempty"`
	Extensions `json:"-"`

	Location `json:"-"`
}

Response describes a single response from an API Operation, including design-time, static links to operations based on the response.

func (*Response) Anchors added in v0.1.0

func (r *Response) Anchors() (*Anchors, error)

func (*Response) Kind added in v0.1.0

func (*Response) Kind() Kind

func (Response) MarshalJSON added in v0.1.0

func (r Response) MarshalJSON() ([]byte, error)

MarshalJSON marshals r into JSON

func (Response) MarshalYAML added in v0.1.0

func (r Response) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Response) Nodes added in v0.1.0

func (r *Response) Nodes() []Node

func (*Response) Refs added in v0.1.0

func (r *Response) Refs() []Ref

func (*Response) UnmarshalJSON added in v0.1.0

func (r *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into r

func (*Response) UnmarshalYAML added in v0.1.0

func (r *Response) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ResponseMap added in v0.1.0

type ResponseMap = ComponentMap[*Response]

ResponseMap is a container for the expected responses of an operation. The container maps a HTTP response code to the expected response.

The documentation is not necessarily expected to cover all possible HTTP response codes because they may not be known in advance. However, documentation is expected to cover a successful operation response and any known errors.

The default MAY be used as a default response object for all HTTP codes that are not covered individually by the ResponseMap Object.

The ResponseMap Object MUST contain at least one response code, and if only one response code is provided it SHOULD be the response for a successful operation call.

type Schema

type Schema struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	Schema *uri.URI `json:"$schema,omitempty"`

	// The value of $id is a URI-reference without a fragment that resolves
	// against the Retrieval URI. The resulting URI is the base URI for the
	// schema.
	//
	// https://json-schema.org/understanding-json-schema/structuring.html?highlight=id#id
	ID *uri.URI `json:"$id,omitempty"`

	// A less common way to identify a subschema is to create a named anchor in
	// the schema using the $anchor keyword and using that name in the URI
	// fragment. Anchors must start with a letter followed by any number of
	// letters, digits, -, _, :, or ..
	//
	// https://json-schema.org/understanding-json-schema/structuring.html?highlight=anchor#anchor
	Anchor Text `json:"$anchor,omitempty"`

	DynamicAnchor Text `json:"$dynamicAnchor,omitempty"`

	RecursiveAnchor *bool `json:"$recursiveAnchor,omitempty"`

	// At its core, JSON *SchemaObj defines the following basic types:
	//
	// 	"string", "number", "integer", "object", "array", "boolean", "null"
	//
	// https://json-schema.org/understanding-json-schema/reference/type.html#type
	Type Types `json:"type,omitempty"`

	// The "$ref" keyword is an applicator that is used to reference a
	// statically identified schema. Its results are the results of the
	// referenced schema. [CREF5]
	//
	// The value of the "$ref" keyword MUST be a string which is a
	// URI-Reference. Resolved against the current URI base, it produces the URI
	// of the schema to apply. This resolution is safe to perform on schema
	// load, as the process of evaluating an instance cannot change how the
	// reference resolves.
	//
	// https://json-schema.org/draft/2020-12/json-schema-core.html#ref
	//
	// https://json-schema.org/understanding-json-schema/structuring.html?highlight=ref#ref
	Ref *SchemaRef `json:"$ref,omitempty"`

	// The "$dynamicRef" keyword is an applicator that allows for deferring the
	// full resolution until runtime, at which point it is resolved each time it
	// is encountered while evaluating an instance.
	//
	// https://json-schema.org/draft/2020-12/json-schema-core.html#dynamic-ref
	DynamicRef *SchemaRef `json:"$dynamicRef,omitempty"`

	RecursiveRef *SchemaRef `json:"$recursiveRef,omitempty"`

	// The format keyword allows for basic semantic identification of certain Kinds of string values that are commonly used. For example, because JSON doesn’t have a “DateTime” type, dates need to be encoded as strings. format allows the schema author to indicate that the string value should be interpreted as a date. By default, format is just an annotation and does not effect validation.
	//
	// Optionally, validator implementations can provide a configuration option to
	// enable format to function as an assertion rather than just an annotation.
	// That means that validation will fail if, for example, a value with a date
	// format isn’t in a form that can be parsed as a date. This can allow values to
	// be constrained beyond what the other tools in JSON *SchemaObj, including Regular
	// Expressions can do.
	//
	// https://json-schema.org/understanding-json-schema/reference/string.html#format
	Format Text `json:"format,omitempty"`

	// The const keyword is used to restrict a value to a single value.
	//
	// https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=const#constant-values
	Const jsonx.RawMessage `json:"const,omitempty"`

	Required Texts `json:"required,omitempty"`

	Properties *SchemaMap `json:"properties,omitempty"`

	// The enum keyword is used to restrict a value to a fixed set of values. It
	// must be an array with at least one element, where each element is unique.
	//
	// https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=const#enumerated-values
	Enum Texts `json:"enum,omitempty"`

	// The $comment keyword is strictly intended for adding comments to a
	// schema. Its value must always be a string. Unlike the annotations title,
	// description, and examples, JSON schema implementations aren’t allowed to
	// attach any meaning or behavior to it whatsoever, and may even strip them
	// at any time. Therefore, they are useful for leaving notes to future
	// editors of a JSON schema, but should not be used to communicate to users
	// of the schema.
	//
	// https://json-schema.org/understanding-json-schema/reference/generic.html?highlight=const#comments
	Comments Text `json:"$comment,omitempty"`

	// The not keyword declares that an instance validates if it doesn’t
	// validate against the given subschema.
	//
	// https://json-schema.org/understanding-json-schema/reference/combining.html?highlight=not#not
	Not *Schema `json:"not,omitempty"`

	// validate against allOf, the given data must be valid against all of the
	// given subschemas.
	//
	// https://json-schema.org/understanding-json-schema/reference/combining.html?highlight=anyof#anyof
	AllOf *SchemaSlice `json:"allOf,omitempty"`

	// validate against anyOf, the given data must be valid against any (one or
	// more) of the given subschemas.
	//
	// https://json-schema.org/understanding-json-schema/reference/combining.html?highlight=allof#allof
	AnyOf *SchemaSlice `json:"anyOf,omitempty"`

	// alidate against oneOf, the given data must be valid against exactly one of the given subschemas.
	//
	// https://json-schema.org/understanding-json-schema/reference/combining.html?highlight=oneof#oneof
	OneOf *SchemaSlice `json:"oneOf,omitempty"`

	// if, then and else keywords allow the application of a subschema based on
	// the outcome of another schema, much like the if/then/else constructs
	// you’ve probably seen in traditional programming languages.
	//
	// https://json-schema.org/understanding-json-schema/reference/conditionals.html#if-then-else
	If *Schema `json:"if,omitempty"`

	// https://json-schema.org/understanding-json-schema/reference/conditionals.html#if-then-else
	Then *Schema `json:"then,omitempty"`

	Else *Schema `json:"else,omitempty"`

	MinProperties *Number `json:"minProperties,omitempty"`

	MaxProperties *Number `json:"maxProperties,omitempty"`

	PropertyNames *Schema `json:"propertyNames,omitempty"`

	RegexProperties *bool `json:"regexProperties,omitempty"`

	PatternProperties *SchemaMap `json:"patternProperties,omitempty"`

	AdditionalProperties *Schema `json:"additionalProperties,omitempty"`

	// The dependentRequired keyword conditionally requires that certain
	// properties must be present if a given property is present in an object.
	// For example, suppose we have a schema representing a customer. If you
	// have their credit card number, you also want to ensure you have a billing
	// address. If you don’t have their credit card number, a billing address
	// would not be required. We represent this dependency of one property on
	// another using the dependentRequired keyword. The value of the
	// dependentRequired keyword is an object. Each entry in the object maps
	// from the name of a property, p, to an array of strings listing properties
	// that are required if p is present.
	DependentRequired *Map[Texts] `json:"dependentRequired,omitempty"`

	DependentSchemas *SchemaMap `json:"dependentSchemas,omitempty"`

	UnevaluatedProperties *Schema `json:"unevaluatedProperties,omitempty"`

	UniqueItems *bool `json:"uniqueItems,omitempty"`

	// List validation is useful for arrays of arbitrary length where each item
	// matches the same schema. For this kind of array, set the items keyword to
	// a single schema that will be used to validate all of the items in the
	// array.
	//
	// https://json-schema.org/understanding-json-schema/reference/array.html#items
	Items *Schema `json:"items,omitempty"`

	UnevaluatedItems *Schema `json:"unevaluatedItems,omitempty"`

	AdditionalItems *Schema `json:"additionalItems,omitempty"`

	PrefixItems *SchemaSlice `json:"prefixItems,omitempty"`

	Contains *Schema `json:"contains,omitempty"`

	MinContains *Number `json:"minContains,omitempty"`

	MaxContains *Number `json:"maxContains,omitempty"`

	MinLength *Number `json:"minLength,omitempty"`

	MaxLength *Number `json:"maxLength,omitempty"`

	Pattern *Regexp `json:"pattern,omitempty"`

	ContentEncoding Text `json:"contentEncoding,omitempty"`

	ContentMediaType Text `json:"contentMediaType,omitempty"`

	Minimum *Number `json:"minimum,omitempty"`

	ExclusiveMinimum *Number `json:"exclusiveMinimum,omitempty"`

	Maximum *Number `json:"maximum,omitempty"`

	ExclusiveMaximum *Number `json:"exclusiveMaximum,omitempty"`

	MultipleOf *Number `json:"multipleOf,omitempty"`

	Title Text `json:"title,omitempty"`

	Description Text `json:"description,omitempty"`

	Default jsonx.RawMessage `json:"default,omitempty"`

	ReadOnly *bool `json:"readOnly,omitempty"`

	WriteOnly *bool `json:"writeOnly,omitempty"`

	Examples []jsonx.RawMessage `json:"examples,omitempty"`

	Example jsonx.RawMessage `json:"example,omitempty"`

	Deprecated *bool `json:"deprecated,omitempty"`

	ExternalDocs Text `json:"externalDocs,omitempty"`

	// When request bodies or response payloads may be one of a number of
	// different schemas, a discriminator object can be used to aid in
	// serialization, deserialization, and validation. The discriminator is a
	// specific object in a schema which is used to inform the consumer of the
	// document of an alternative schema based on the value associated with it.
	//
	// This object MAY be extended with Specification Extensions.
	//
	// The discriminator object is legal only when using one of the composite
	// keywords oneOf, anyOf, allOf.
	//
	// 3.1:
	//
	// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminatorObject
	//
	// 3.0:
	//
	// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#discriminatorObject
	Discriminator *Discriminator `json:"discriminator,omitempty"`

	// This MAY be used only on properties schemas. It has no effect on root
	// schemas. Adds additional metadata to describe the XML representation of
	// this property.
	XML *XML `json:"xml,omitempty"`

	// The "$defs" keyword reserves a location for schema authors to inline
	// re-usable JSON Schemas into a more general schema. The keyword does not
	// directly affect the validation result.
	//
	// This keyword's value MUST be an object. Each member value of this object
	// MUST be a valid JSON *SchemaObj.
	//
	// https://json-schema.org/draft/2020-12/json-schema-core.html#defs
	//
	// https://json-schema.org/understanding-json-schema/structuring.html?highlight=defs#defs
	Definitions *SchemaMap `json:"$defs,omitempty"`

	Keywords map[Text]jsonx.RawMessage `json:"-"`
}

Schema allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is a superSlice of the [JSON Schema Specification Draft 2020-12](https://tools.ietf.org/html/draft-bhutton-json-schema-00).

For more information about the properties, see [JSON Schema Core](https://tools.ietf.org/html/draft-bhutton-json-schema-00) and [JSON Schema Validation](https://tools.ietf.org/html/draft-bhutton-json-schema-validation-00).

Unless stated otherwise, the property definitions follow those of JSON Schema and do not add any additional semantics. Where JSON Schema indicates that behavior is defined by the application (e.g. for annotations), OAS also defers the definition of semantics to the application consuming the OpenAPI document.

The OpenAPI Schema Object [dialect](https://tools.ietf.org/html/draft-bhutton-json-schema-00#section-4.3.3) is defined as requiring the [OAS base vocabulary](#baseVocabulary), in addition to the vocabularies as specified in the JSON Schema draft 2020-12 [general purpose meta-schema](https://tools.ietf.org/html/draft-bhutton-json-schema-00#section-8).

The OpenAPI Schema Object dialect for this version of the specification is identified by the URI `https://spec.openapis.org/oas/3.1/dialect/base` (the <a name="dialectSchemaId"></a>"OAS dialect schema id").

The following properties are taken from the JSON Schema specification but their definitions have been extended by the OAS:

- description - [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation. - format - See [Data Type Formats](#dataTypeFormat) for further details. While relying on JSON Schema's defined formats, the OAS offers a few additional predefined formats.

In addition to the JSON Schema properties comprising the OAS dialect, the Schema Object supports keywords from any other vocabularies, or entirely arbitrary properties. A Schema represents compiled version of json-schema.

func (*Schema) Anchors added in v0.1.0

func (s *Schema) Anchors() (*Anchors, error)

func (*Schema) Clone added in v0.1.0

func (s *Schema) Clone() *Schema

Clone returns a deep copy of Schema. This is to avoid overriding the initial Schema when dealing with $dynamicRef and $recursiveRef.

func (*Schema) DecodeKeyword added in v0.1.0

func (s *Schema) DecodeKeyword(key Text, dst interface{}) error

DecodeKeyword unmarshals the keyword's raw data into dst

func (*Schema) DecodeKeywords added in v0.1.0

func (s *Schema) DecodeKeywords(dst interface{}) error

DecodeKeywords unmarshals all keywords raw data into dst

func (*Schema) Kind added in v0.1.0

func (*Schema) Kind() Kind

func (Schema) MarshalJSON added in v0.1.0

func (s Schema) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Schema) MarshalYAML added in v0.1.0

func (s Schema) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Schema) Nodes added in v0.1.0

func (s *Schema) Nodes() []Node

func (*Schema) Refs added in v0.1.0

func (s *Schema) Refs() []Ref

func (*Schema) SetKeyword added in v0.1.0

func (s *Schema) SetKeyword(key Text, value interface{}) error

SetKeyword marshals value and sets the encoded json to key in Keywords

If setting the value as []byte, it should be in the form of json.RawMessage or jsonx.RawMessage as both types implement json.Marshaler

func (*Schema) UnmarshalJSON added in v0.1.0

func (s *Schema) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Schema) UnmarshalYAML added in v0.1.0

func (s *Schema) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type SchemaItem added in v0.1.0

type SchemaItem struct {
	Key    Text
	Schema *Schema
}

func (*SchemaItem) Clone added in v0.1.0

func (si *SchemaItem) Clone() SchemaItem

type SchemaMap added in v0.1.0

type SchemaMap struct {
	Location
	Items []SchemaItem
}

SchemaMap is a pseudo, ordered map ofASew3 Schemas

Under the hood, SchemaMap is a slice of SchemaEntry

func (*SchemaMap) Anchors added in v0.1.0

func (sm *SchemaMap) Anchors() (*Anchors, error)

func (*SchemaMap) Clone added in v0.1.0

func (sm *SchemaMap) Clone() *SchemaMap

func (SchemaMap) Get added in v0.1.0

func (sm SchemaMap) Get(key Text) *Schema

func (*SchemaMap) Kind added in v0.1.0

func (*SchemaMap) Kind() Kind

func (SchemaMap) MarshalJSON added in v0.1.0

func (sm SchemaMap) MarshalJSON() ([]byte, error)

func (SchemaMap) MarshalYAML added in v0.1.0

func (sm SchemaMap) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*SchemaMap) Nodes added in v0.1.0

func (sm *SchemaMap) Nodes() []Node

func (*SchemaMap) Refs added in v0.1.0

func (sm *SchemaMap) Refs() []Ref

func (*SchemaMap) Set added in v0.1.0

func (sm *SchemaMap) Set(key Text, s *Schema)

func (*SchemaMap) UnmarshalJSON added in v0.1.0

func (sm *SchemaMap) UnmarshalJSON(data []byte) error

func (*SchemaMap) UnmarshalYAML added in v0.1.0

func (sm *SchemaMap) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type SchemaRef added in v0.1.0

type SchemaRef struct {
	Location
	Ref      *uri.URI `json:"-"`
	Resolved *Schema  `json:"-"`

	SchemaRefKind SchemaRefType `json:"-"`
}

func (*SchemaRef) Anchors added in v0.1.0

func (*SchemaRef) Anchors() (*Anchors, error)

func (*SchemaRef) Clone added in v0.1.0

func (sr *SchemaRef) Clone() *SchemaRef

func (*SchemaRef) IsResolved added in v0.1.0

func (sr *SchemaRef) IsResolved() bool

func (*SchemaRef) Kind added in v0.1.0

func (*SchemaRef) Kind() Kind

func (SchemaRef) MarshalJSON added in v0.1.0

func (sr SchemaRef) MarshalJSON() ([]byte, error)

func (SchemaRef) MarshalYAML added in v0.1.0

func (sr SchemaRef) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*SchemaRef) Nodes added in v0.1.0

func (sr *SchemaRef) Nodes() []Node

func (*SchemaRef) RefKind added in v0.1.0

func (sr *SchemaRef) RefKind() Kind

func (*SchemaRef) RefType added in v0.1.0

func (sr *SchemaRef) RefType() RefType

func (*SchemaRef) Refs added in v0.1.0

func (*SchemaRef) Refs() []Ref

func (*SchemaRef) ResolvedNode added in v0.1.0

func (sr *SchemaRef) ResolvedNode() Node

func (*SchemaRef) URI added in v0.1.0

func (sr *SchemaRef) URI() *uri.URI

func (*SchemaRef) UnmarshalJSON added in v0.1.0

func (sr *SchemaRef) UnmarshalJSON(data []byte) error

func (*SchemaRef) UnmarshalYAML added in v0.1.0

func (sr *SchemaRef) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type SchemaRefType added in v0.1.0

type SchemaRefType uint8
const (
	SchamRefTypeUndefined SchemaRefType = iota
	SchemaRefTypeRef
	SchemaRefTypeDynamic
	SchemaRefTypeRecursive
)

type SchemaSlice added in v0.1.0

type SchemaSlice struct {
	Location
	Items []*Schema
}

func (*SchemaSlice) Anchors added in v0.1.0

func (ss *SchemaSlice) Anchors() (*Anchors, error)

func (*SchemaSlice) Clone added in v0.1.0

func (ss *SchemaSlice) Clone() *SchemaSlice

func (*SchemaSlice) Kind added in v0.1.0

func (*SchemaSlice) Kind() Kind

func (SchemaSlice) MarshalJSON added in v0.1.0

func (ss SchemaSlice) MarshalJSON() ([]byte, error)

func (SchemaSlice) MarshalYAML added in v0.1.0

func (ss SchemaSlice) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*SchemaSlice) Nodes added in v0.1.0

func (ss *SchemaSlice) Nodes() []Node

func (*SchemaSlice) Refs added in v0.1.0

func (ss *SchemaSlice) Refs() []Ref

func (*SchemaSlice) UnmarshalJSON added in v0.1.0

func (ss *SchemaSlice) UnmarshalJSON(data []byte) error

func (*SchemaSlice) UnmarshalYAML added in v0.1.0

func (ss *SchemaSlice) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Scope added in v0.1.0

type Scope struct {
	Location `json:"-"`
	Key      Text `json:"-"`
	Value    Text `json:"-"`
}

func (*Scope) Anchors added in v0.1.0

func (*Scope) Anchors() (*Anchors, error)

func (*Scope) Kind added in v0.1.0

func (*Scope) Kind() Kind

func (Scope) MarshalJSON added in v0.1.0

func (s Scope) MarshalJSON() ([]byte, error)

func (Scope) MarshalYAML added in v0.1.0

func (s Scope) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Scope) Nodes added in v0.1.0

func (s *Scope) Nodes() []Node
func (s *Scope) ResolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
	if err := ptr.Validate(); err != nil {
		return nil, err
	}
	return s.resolveNodeByPointer(ptr)
}
func (s *Scope) resolveNodeByPointer(ptr jsonpointer.Pointer) (Node, error) {
	if ptr.IsRoot() {
		return s, nil
	}
	tok, _ := ptr.NextToken()
	return nil, newErrNotResolvable(s.AbsoluteLocation(), tok)
}

func (*Scope) Refs added in v0.1.0

func (s *Scope) Refs() []Ref

func (Scope) String added in v0.1.0

func (s Scope) String() string

func (Scope) Text added in v0.1.0

func (s Scope) Text() Text

func (*Scope) UnmarshalJSON added in v0.1.0

func (s *Scope) UnmarshalJSON(data []byte) error

func (*Scope) UnmarshalYAML added in v0.1.0

func (s *Scope) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Scopes added in v0.1.0

type Scopes struct {
	Location `json:"-"`

	Items []*Scope `json:"-"`
}

func (*Scopes) Anchors added in v0.1.0

func (*Scopes) Anchors() (*Anchors, error)

func (Scopes) Get added in v0.1.0

func (s Scopes) Get(key Text) *Scope

func (Scopes) Has added in v0.1.0

func (s Scopes) Has(key Text) bool

func (*Scopes) Kind added in v0.1.0

func (*Scopes) Kind() Kind

func (*Scopes) Map added in v0.1.0

func (s *Scopes) Map() map[Text]Text

func (Scopes) MarshalJSON added in v0.1.0

func (s Scopes) MarshalJSON() ([]byte, error)

func (Scopes) MarshalYAML added in v0.1.0

func (s Scopes) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Scopes) Nodes added in v0.1.0

func (s *Scopes) Nodes() []Node

func (*Scopes) Refs added in v0.1.0

func (s *Scopes) Refs() []Ref

func (*Scopes) Set added in v0.1.0

func (s *Scopes) Set(key Text, value Text)

func (*Scopes) UnmarshalJSON added in v0.1.0

func (s *Scopes) UnmarshalJSON(data []byte) error

func (*Scopes) UnmarshalYAML added in v0.1.0

func (s *Scopes) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type SecurityRequirement

type SecurityRequirement = ObjMap[*SecurityRequirementItem]

SecurityRequirement lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object.

Security Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized. This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information.

When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object, only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.

Each name MUST correspond to a security scheme which is declared in the Security Schemes under the Components Object. If the security scheme is of type "oauth2" or "openIdConnect", then the value is a list of scope names required for the execution, and the list MAY be empty if authorization does not require a specified scope. For other security scheme types, the array MAY contain a list of role names which are required for the execution, but are not otherwise defined or exchanged in-band.

type SecurityRequirementItem added in v0.1.0

type SecurityRequirementItem struct {
	Location
	Key   Text
	Value Texts
}

func (*SecurityRequirementItem) Anchors added in v0.1.0

func (sri *SecurityRequirementItem) Anchors() (*Anchors, error)

func (*SecurityRequirementItem) Kind added in v0.1.0

func (*SecurityRequirementItem) Kind() Kind

func (SecurityRequirementItem) MarshalJSON added in v0.1.0

func (sri SecurityRequirementItem) MarshalJSON() ([]byte, error)

func (SecurityRequirementItem) MarshalYAML added in v0.1.0

func (sri SecurityRequirementItem) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*SecurityRequirementItem) Nodes added in v0.1.0

func (sri *SecurityRequirementItem) Nodes() []Node

func (*SecurityRequirementItem) Refs added in v0.1.0

func (sri *SecurityRequirementItem) Refs() []Ref

func (*SecurityRequirementItem) UnmarshalJSON added in v0.1.0

func (sri *SecurityRequirementItem) UnmarshalJSON(data []byte) error

func (*SecurityRequirementItem) UnmarshalYAML added in v0.1.0

func (sri *SecurityRequirementItem) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type SecurityRequirementMap added in v0.1.0

type SecurityRequirementMap = ObjMap[*SecurityRequirement]

SecurityRequirementMap is a list of SecurityRequirement

type SecurityRequirementSlice added in v0.1.0

type SecurityRequirementSlice = ObjSlice[*SecurityRequirement]

type SecurityScheme

type SecurityScheme struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// The type of the security scheme.
	//
	// *required
	Type Text `json:"type,omitempty"`

	// Any description for security scheme. CommonMark syntax MAY be used for
	// rich text representation.
	Description Text `json:"description,omitempty"`
	// The name of the header, query or cookie parameter to be used.
	//
	// Applies to: API Key
	//
	// 	*required*
	Name Text `json:"name,omitempty"`
	// The location of the API key. Valid values are "query", "header" or "cookie".
	//
	// Applies to: APIKey
	//
	// 	*required*
	In In `json:"in,omitempty"`
	// The name of the HTTP Authorization scheme to be used in the Authorization
	// header as defined in RFC7235. The values used SHOULD be registered in the
	// IANA Authentication Scheme registry.
	//
	// 	*required*
	Scheme Text `json:"scheme,omitempty"`

	// http ("bearer")  A hint to the client to identify how the bearer token is
	// formatted. Bearer tokens are usually generated by an authorization
	// server, so this information is primarily for documentation purposes.
	BearerFormat Text `json:"bearerFormat,omitempty"`

	// An object containing configuration information for the flow types supported.
	//
	// 	*required*
	Flows *OAuthFlows `json:"flows,omitempty"`

	// OpenId Connect URL to discover OAuth2 configuration values. This MUST be
	// in the form of a URL. The OpenID Connect standard requires the use of
	// TLS.
	//
	// 	*required*
	OpenIDConnectURL Text `json:"openIdConnect,omitempty"`
}

SecurityScheme defines a security scheme that can be used by the operations.

func (*SecurityScheme) Anchors added in v0.1.0

func (ss *SecurityScheme) Anchors() (*Anchors, error)

func (*SecurityScheme) Kind added in v0.1.0

func (*SecurityScheme) Kind() Kind

func (SecurityScheme) MarshalJSON added in v0.1.0

func (ss SecurityScheme) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (SecurityScheme) MarshalYAML added in v0.1.0

func (ss SecurityScheme) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*SecurityScheme) Nodes added in v0.1.0

func (ss *SecurityScheme) Nodes() []Node

func (*SecurityScheme) Refs added in v0.1.0

func (ss *SecurityScheme) Refs() []Ref

func (*SecurityScheme) UnmarshalJSON added in v0.1.0

func (ss *SecurityScheme) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*SecurityScheme) UnmarshalYAML added in v0.1.0

func (ss *SecurityScheme) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type SecuritySchemeMap added in v0.1.0

type SecuritySchemeMap = ComponentMap[*SecurityScheme]

SecuritySchemeMap is a map of SecurityScheme

type SemVerError added in v0.1.0

type SemVerError struct {
	Value string
	Err   error
	URI   uri.URI
}

func (SemVerError) Error added in v0.1.0

func (e SemVerError) Error() string

func (SemVerError) Is added in v0.1.0

func (e SemVerError) Is(err error) bool

func (SemVerError) Unwrap added in v0.1.0

func (e SemVerError) Unwrap() error

type Server

type Server struct {
	Location   `json:"-"`
	Extensions `json:"-"`

	// A URL to the target host. This URL supports Server Variables and MAY be
	// relative, to indicate that the host location is relative to the location
	// where the OpenAPI document is being served. Variable substitutions will
	// be made when a variable is named in {brackets}.
	URL Text `json:"url"`

	// Description of the host designated by the URL. CommonMark syntax MAY be
	// used for rich text representation.
	Description Text `json:"description,omitempty"`

	// A map between a variable name and its value. The value is used for
	// substitution in the server's URL template.
	Variables *ServerVariableMap `json:"variables,omitempty"`
}

Server representation of a Server.

func (*Server) Anchors added in v0.1.0

func (*Server) Anchors() (*Anchors, error)

func (*Server) Kind added in v0.1.0

func (*Server) Kind() Kind

func (Server) MarshalJSON

func (s Server) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Server) MarshalYAML

func (s Server) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Server) Nodes added in v0.1.0

func (s *Server) Nodes() []Node

func (*Server) Refs added in v0.1.0

func (s *Server) Refs() []Ref

func (*Server) UnmarshalJSON

func (s *Server) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Server) UnmarshalYAML

func (s *Server) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ServerSlice added in v0.1.0

type ServerSlice = ObjSlice[*Server]

type ServerVariable

type ServerVariable struct {
	// An enumeration of string values to be used if the substitution options
	// are from a limited set. The array MUST NOT be empty.
	Enum Texts `json:"enum"`
	// The default value to use for substitution, which SHALL be sent if an
	// alternate value is not supplied. Note this behavior is different than the
	// Schema Object's treatment of default values, because in those cases
	// parameter values are optional. If the enum is defined, the value MUST
	// exist in the enum's values.
	//
	// 	*required*
	Default Text `json:"default"`
	// An optional description for the server variable. CommonMark syntax MAY be
	// used for rich text representation.
	Description Text `json:"description,omitempty"`

	Location   `json:"-"`
	Extensions `json:"-"`
}

ServerVariable for server URL template substitution.

func (*ServerVariable) Anchors added in v0.1.0

func (sv *ServerVariable) Anchors() (*Anchors, error)

func (*ServerVariable) Kind added in v0.1.0

func (*ServerVariable) Kind() Kind

func (ServerVariable) MarshalJSON

func (sv ServerVariable) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (ServerVariable) MarshalYAML

func (sv ServerVariable) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*ServerVariable) Nodes added in v0.1.0

func (sv *ServerVariable) Nodes() []Node

func (*ServerVariable) Refs added in v0.1.0

func (*ServerVariable) Refs() []Ref

func (*ServerVariable) UnmarshalJSON

func (sv *ServerVariable) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*ServerVariable) UnmarshalYAML

func (sv *ServerVariable) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type ServerVariableMap added in v0.1.0

type ServerVariableMap = ObjMap[*ServerVariable]

type StdValidator added in v0.1.0

type StdValidator struct {
	Schemas CompiledSchemas
}

StdValidator is an implemtation of the Validator interface.

func NewValidator added in v0.1.0

func NewValidator(compiler *jsonschema.Compiler, resources ...fs.FS) (*StdValidator, error)

Each fs.FS in resources will be walked and all files ending in .json will be be added to the compiler. Defaults are provided from an embedded fs.FS.

## Resource Defaults

func (*StdValidator) Validate added in v0.1.0

func (sv *StdValidator) Validate(data []byte, resource uri.URI, kind Kind, openapi semver.Version, jsonschema uri.URI) error

func (*StdValidator) ValidateDocument added in v0.1.0

func (sv *StdValidator) ValidateDocument(doc *Document) error

Validate should validate the fully-resolved OpenAPI document.

This currently only validates with JSON Schema.

type Tag

type Tag struct {
	Location   `json:"-"`
	Extensions `json:"-"`
	// The name of the tag.
	//
	// 	*required*
	Name Text `json:"name"`
	//  A description for the tag.
	//
	// CommonMark syntax MAY be used for rich text representation.
	//
	// https://spec.commonmark.org/
	Description Text `json:"description,omitempty"`
	// Additional external documentation for this tag.
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" bson:"externalDocs,omitempty"`
}

Tag adds metadata that is used by the Operation Object.

It is not mandatory to have a Tag Object per tag defined in the Operation Object instances.

func (*Tag) Anchors added in v0.1.0

func (*Tag) Anchors() (*Anchors, error)

func (*Tag) Kind added in v0.1.0

func (*Tag) Kind() Kind

func (Tag) MarshalJSON

func (t Tag) MarshalJSON() ([]byte, error)

MarshalJSON marshals t into JSON

func (Tag) MarshalYAML

func (t Tag) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*Tag) Nodes added in v0.1.0

func (t *Tag) Nodes() []Node

func (*Tag) Refs added in v0.1.0

func (*Tag) Refs() []Ref

func (*Tag) UnmarshalJSON

func (t *Tag) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals json into t

func (*Tag) UnmarshalYAML

func (t *Tag) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type TagMap added in v0.1.0

type TagMap = ObjMap[*Tag]

type TagSlice added in v0.1.0

type TagSlice struct {
	Location `json:"-"`

	Items []*Tag
}

func (*TagSlice) Anchors added in v0.1.0

func (*TagSlice) Anchors() (*Anchors, error)

func (*TagSlice) Kind added in v0.1.0

func (*TagSlice) Kind() Kind

func (*TagSlice) MarshalJSON added in v0.1.0

func (ts *TagSlice) MarshalJSON() ([]byte, error)

func (TagSlice) MarshalYAML added in v0.1.0

func (t TagSlice) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*TagSlice) Nodes added in v0.1.0

func (tl *TagSlice) Nodes() []Node

func (*TagSlice) Refs added in v0.1.0

func (ts *TagSlice) Refs() []Ref

func (*TagSlice) UnmarshalJSON added in v0.1.0

func (ts *TagSlice) UnmarshalJSON(data []byte) error

func (*TagSlice) UnmarshalYAML added in v0.1.0

func (t *TagSlice) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

type Text added in v0.1.0

type Text = text.Text
const (
	// InQuery - Parameters that are appended to the URL. For example, in
	// /items?id=###, the query parameter is id.
	InQuery Text = "query"
	// InHeader - Custom headers that are expected as part of the request. Note
	// that RFC7230 states header names are case insensitive.
	InHeader Text = "header"
	// InCookie -  Used to pass a specific cookie value to the API.
	InCookie Text = "cookie"
	// InPath - Used together with Path Templating, where the parameter value is
	// actually part of the operation's URL. This does not include the host or
	// base path of the API. For example, in /items/{itemId}, the path parameter
	// is itemId.
	InPath Text = "path"
)
const (
	// SecuritySchemeTypeAPIKey = "apiKey"
	SecuritySchemeTypeAPIKey Text = "apiKey"
	// SecuritySchemeTypeHTTP = "http"
	SecuritySchemeTypeHTTP Text = "http"
	// SecuritySchemeTypeMutualTLS = mutualTLS
	SecuritySchemeTypeMutualTLS Text = "mutualTLS"
	// SecuritySchemeTypeOAuth2 = oauth2
	SecuritySchemeTypeOAuth2 Text = "oauth2"
	// SecuritySchemeTypeOpenIDConnect = "openIdConnect"
	SecuritySchemeTypeOpenIDConnect Text = "openIdConnect"
)
const (
	// StyleForm for
	StyleForm Text = "form"
	// StyleSimple comma-separated values. Corresponds to the
	// {param_name} URI template.
	StyleSimple Text = "simple"
	// StyleMatrix is semicolon-prefixed values, also known as path-style
	// expansion. Corresponds to the {;param_name} URI template.
	StyleMatrix Text = "matrix"
	// StyleLabel dot-prefixed values, also known as label expansion.
	// Corresponds to the {.param_name} URI template.
	StyleLabel Text = "label"
	// StyleDeepObject a simple way of rendering nested objects using
	// form parameters (applies to objects only).
	StyleDeepObject Text = "deepObject"
	// StylePipeDelimited is pipeline-separated array values.
	//
	// Same as collectionFormat: pipes in OpenAPI 2.0. Has effect only for
	// non-exploded arrays (explode: false), that is, the pipe separates the
	// array values if the array is a single parameter, as in
	// 	arr=a|b|c
	StylePipeDelimited Text = "pipeDelimited"
)

type Texts added in v0.1.0

type Texts = text.Texts

type Type added in v0.1.0

type Type = Text

Type restricts to a JSON Schema specific type

https://json-schema.org/understanding-json-schema/reference/type.html#type

type Types

type Types []Type

Types is a set of Types. A single Type marshals/unmarshals into a string while 2+ marshals into an array.

func (*Types) Add

func (t *Types) Add(typ Type) Types

Add adds typ if not present

func (Types) Clone added in v0.1.0

func (t Types) Clone() Types

func (Types) Contains

func (t Types) Contains(typ Type) bool

Contains returns true if t contains typ

func (Types) ContainsArray

func (t Types) ContainsArray() bool

ContainsArray returns true if TypeArray is present

func (Types) ContainsBoolean

func (t Types) ContainsBoolean() bool

ContainsBoolean returns true if TypeBoolean is present

func (Types) ContainsInteger

func (t Types) ContainsInteger() bool

ContainsInteger returns true if TypeInteger is present

func (Types) ContainsNull

func (t Types) ContainsNull() bool

ContainsNull returns true if TypeNull is present

func (Types) ContainsNumber

func (t Types) ContainsNumber() bool

ContainsNumber returns true if TypeNumber is present

func (Types) ContainsObject

func (t Types) ContainsObject() bool

ContainsObject returns true if TypeObject is present

func (Types) ContainsString

func (t Types) ContainsString() bool

ContainsString returns true if TypeString is present

func (Types) IsSingle

func (t Types) IsSingle() bool

IsSingle returns true if len(t) == 1

func (Types) Len

func (t Types) Len() int

Len returns len(t)

func (Types) MarshalJSON

func (t Types) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON

func (Types) MarshalYAML added in v0.2.3

func (t Types) MarshalYAML() (interface{}, error)

func (*Types) Remove

func (t *Types) Remove(typ Type) Types

Remove removes typ if present

func (*Types) UnmarshalJSON

func (t *Types) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Types) UnmarshalYAML added in v0.2.3

func (t *Types) UnmarshalYAML(value *yaml.Node) error

type UnsupportedVersionError added in v0.1.0

type UnsupportedVersionError struct {
	Version string  `json:"version"`
	Errs    []error `json:"errors"`
}

func (*UnsupportedVersionError) As added in v0.1.0

func (e *UnsupportedVersionError) As(target interface{}) bool

func (*UnsupportedVersionError) Error added in v0.1.0

func (e *UnsupportedVersionError) Error() string

func (*UnsupportedVersionError) Is added in v0.1.0

func (e *UnsupportedVersionError) Is(err error) bool

type ValidationError added in v0.1.0

type ValidationError struct {
	Kind Kind
	Err  error
	URI  uri.URI
}

func (*ValidationError) Error added in v0.1.0

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap added in v0.1.0

func (e *ValidationError) Unwrap() error

type Validator added in v0.1.0

type Validator interface {
	// Validate should validate the fully-resolved OpenAPI document.
	ValidateDocument(document *Document) error

	// ValidateComponent should validate the structural integrity of a of an OpenAPI
	// document or component.
	//
	// If $ref is present in the data and the data is not a Schema, the Kind will be KindReference.
	// Otherwise, it will be the Kind of the data being loaded.
	//
	// openapi should only ever call Validate for the following:
	//    - OpenAPI Document (KindDocument)
	//    - JSON Schema (KindSchema)
	//    - Components (KindComponents)
	//    - Callbacks (KindCallbacks)
	//    - Example (KindExample)
	//    - Header (KindHeader)
	//    - Link (KindLink)
	//    - Parameter (KindParameter)
	//    - PathItem (KindPathItem)
	//    - Operation (KindOperation)
	//    - Reference (KindReference)
	//    - RequestBody (KindRequestBody)
	//    - Response (KindResponse)
	//    - SecurityScheme (KindSecurityScheme)
	//
	// StdComponentValidator will return an error if CompiledSchemas does not contain
	// a CompiledSchema for the given Kind.
	Validate(data []byte, resource uri.URI, kind Kind, openapi semver.Version, jsonschema uri.URI) error
}

type XML

type XML struct {
	Extensions `json:"-"`
	Location   `json:"-"`

	// Replaces the name of the element/attribute used for the described schema
	// property. When defined within items, it will affect the name of the
	// individual XML elements within the list. When defined alongside type
	// being array (outside the items), it will affect the wrapping element and
	// only if wrapped is true. If wrapped is false, it will be ignored.
	Name Text `json:"name,omitempty"`
	// The URI of the namespace definition. This MUST be in the form of an
	// absolute URI.
	Namespace Text `json:"namespace,omitempty"`
	// The prefix to be used for the name.
	Prefix Text `json:"prefix,omitempty"`
	// Declares whether the property definition translates to an attribute
	// instead of an element. Default value is false.
	Attribute *bool `json:"attribute,omitempty"`
	// MAY be used only for an array definition. Signifies whether the array is
	// wrapped (for example, <books><book/><book/></books>) or unwrapped
	// (<book/><book/>). Default value is false. The definition takes effect
	// only when defined alongside type being array (outside the items).
	Wrapped *bool `json:"wrapped,omitempty"`
}

XML is a metadata object that allows for more fine-tuned XML model definitions.

When using arrays, XML element names are not inferred (for singular/plural forms) and the name property SHOULD be used to add that information. See examples for expected behavior.

func (*XML) Anchors added in v0.1.0

func (*XML) Anchors() (*Anchors, error)

func (*XML) Clone added in v0.1.0

func (xml *XML) Clone() *XML

func (*XML) Kind added in v0.1.0

func (*XML) Kind() Kind

func (XML) MarshalJSON added in v0.1.0

func (x XML) MarshalJSON() ([]byte, error)

func (XML) MarshalYAML added in v0.1.0

func (xml XML) MarshalYAML() (interface{}, error)

UnmarshalYAML satisfies gopkg.in/yaml.v3 Marshaler interface

func (*XML) Nodes added in v0.1.0

func (xml *XML) Nodes() []Node

func (*XML) Refs added in v0.1.0

func (xml *XML) Refs() []Ref

func (*XML) UnmarshalJSON added in v0.1.0

func (x *XML) UnmarshalJSON(data []byte) error

func (*XML) UnmarshalYAML added in v0.1.0

func (xml *XML) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies gopkg.in/yaml.v3 Unmarshaler interface

Jump to

Keyboard shortcuts

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