spec

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 25 Imported by: 0

README

Documentation

Overview

Package openapi3 parses and writes OpenAPI 3 specification documents.

See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md

Index

Examples

Constants

View Source
const (
	ParameterInPath   = "path"
	ParameterInQuery  = "query"
	ParameterInHeader = "header"
	ParameterInCookie = "cookie"
)
View Source
const (
	TypeArray   = "array"
	TypeBoolean = "boolean"
	TypeInteger = "integer"
	TypeNumber  = "number"
	TypeObject  = "object"
	TypeString  = "string"
)
View Source
const (
	SerializationSimple         = "simple"
	SerializationLabel          = "label"
	SerializationMatrix         = "matrix"
	SerializationForm           = "form"
	SerializationSpaceDelimited = "spaceDelimited"
	SerializationPipeDelimited  = "pipeDelimited"
	SerializationDeepObject     = "deepObject"
)
View Source
const (
	// FormatOfStringForUUIDOfRFC4122 is an optional predefined format for UUID v1-v5 as specified by RFC4122
	FormatOfStringForUUIDOfRFC4122 = `^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$`
)

Variables

View Source
var (
	// SchemaErrorDetailsDisabled disables printing of details about schema errors.
	SchemaErrorDetailsDisabled = false

	// ErrOneOfConflict is the SchemaError Origin when data matches more than one oneOf schema
	ErrOneOfConflict = errors.New("input matches more than one oneOf schemas")

	// ErrSchemaInputNaN may be returned when validating a number
	ErrSchemaInputNaN = errors.New("floating point NaN is not allowed")
	// ErrSchemaInputInf may be returned when validating a number
	ErrSchemaInputInf = errors.New("floating point Inf is not allowed")
)
View Source
var IdentifierRegExp = regexp.MustCompile(identifierPattern)

IdentifierRegExp verifies whether Component object key matches 'identifierPattern' pattern, according to OapiAPI v3.x.0. Hovever, to be able supporting legacy OpenAPI v2.x, there is a need to customize above pattern in orde not to fail converted v2-v3 validation

View Source
var SchemaStringFormats = make(map[string]Format, 4)

SchemaStringFormats allows for validating string formats

Functions

func BoolPtr

func BoolPtr(value bool) *bool

BoolPtr is a helper for defining OpenAPI schemas.

func DefaultRefNameResolver

func DefaultRefNameResolver(ref string) string

DefaultRefResolver is a default implementation of refNameResolver for the InternalizeRefs function.

If a reference points to an element inside a document, it returns the last element in the reference using filepath.Base. Otherwise if the reference points to a file, it returns the file name trimmed of all extensions.

func DefineIPv4Format

func DefineIPv4Format()

DefineIPv4Format opts in ipv4 format validation on top of OAS 3 spec

func DefineIPv6Format

func DefineIPv6Format()

DefineIPv6Format opts in ipv6 format validation on top of OAS 3 spec

func DefineStringFormat

func DefineStringFormat(name string, pattern string)

DefineStringFormat defines a new regexp pattern for a given format

func DefineStringFormatCallback

func DefineStringFormatCallback(name string, callback FormatCallback)

DefineStringFormatCallback adds a validation function for a specific schema format entry

func Float64Ptr

func Float64Ptr(value float64) *float64

Float64Ptr is a helper for defining OpenAPI schemas.

func Int64Ptr

func Int64Ptr(value int64) *int64

Int64Ptr is a helper for defining OpenAPI schemas.

func RegisterArrayUniqueItemsChecker

func RegisterArrayUniqueItemsChecker(fn SliceUniqueItemsChecker)

RegisterArrayUniqueItemsChecker is used to register a customized function used to check if JSON array have unique items.

func Uint64Ptr

func Uint64Ptr(value uint64) *uint64

Uint64Ptr is a helper for defining OpenAPI schemas.

func ValidateIdentifier

func ValidateIdentifier(value string) error

func WithValidationOptions

func WithValidationOptions(ctx context.Context, options *ValidationOptions) context.Context

WithValidationOptions allows adding validation options to a context object that can be used when validationg any OpenAPI type.

Types

type Callback

type Callback map[string]*PathItem

Callback is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject

func (Callback) Validate

func (callback Callback) Validate(ctx context.Context) error

Validate returns an error if Callback does not comply with the OpenAPI spec.

type CallbackRef

type CallbackRef struct {
	Ref   string
	Value *Callback
}

CallbackRef represents either a Callback or a $ref to a Callback. When serializing and both fields are set, Ref is preferred over Value.

func (CallbackRef) JSONLookup

func (value CallbackRef) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*CallbackRef) MarshalJSON

func (value *CallbackRef) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of CallbackRef.

func (*CallbackRef) MarshalYAML

func (value *CallbackRef) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML encoding of CallbackRef.

func (*CallbackRef) UnmarshalJSON

func (value *CallbackRef) UnmarshalJSON(data []byte) error

UnmarshalJSON sets CallbackRef to a copy of data.

func (*CallbackRef) Validate

func (value *CallbackRef) Validate(ctx context.Context) error

Validate returns an error if CallbackRef does not comply with the OpenAPI spec.

type Callbacks

type Callbacks map[string]*CallbackRef

func (Callbacks) JSONLookup

func (c Callbacks) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type Components

type Components struct {
	ExtensionProps `json:"-" yaml:"-"`

	Schemas         Schemas         `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Parameters      ParametersMap   `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Headers         Headers         `json:"headers,omitempty" yaml:"headers,omitempty"`
	RequestBodies   RequestBodies   `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	Responses       Responses       `json:"responses,omitempty" yaml:"responses,omitempty"`
	SecuritySchemes SecuritySchemes `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
	Examples        Examples        `json:"examples,omitempty" yaml:"examples,omitempty"`
	Links           Links           `json:"links,omitempty" yaml:"links,omitempty"`
	Callbacks       Callbacks       `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
}

Components is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject

func NewComponents

func NewComponents() Components

func (*Components) MarshalJSON

func (components *Components) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Components.

func (*Components) UnmarshalJSON

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

UnmarshalJSON sets Components to a copy of data.

func (*Components) Validate

func (components *Components) Validate(ctx context.Context) (err error)

Validate returns an error if Components does not comply with the OpenAPI spec.

type Contact

type Contact struct {
	ExtensionProps `json:"-" yaml:"-"`

	Name  string `json:"name,omitempty" yaml:"name,omitempty"`
	URL   string `json:"url,omitempty" yaml:"url,omitempty"`
	Email string `json:"email,omitempty" yaml:"email,omitempty"`
}

Contact is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contactObject

func (*Contact) MarshalJSON

func (contact *Contact) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Contact.

func (*Contact) UnmarshalJSON

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

UnmarshalJSON sets Contact to a copy of data.

func (*Contact) Validate

func (contact *Contact) Validate(ctx context.Context) error

Validate returns an error if Contact does not comply with the OpenAPI spec.

type Content

type Content map[string]*MediaType

Content is specified by OpenAPI/Swagger 3.0 standard.

func NewContent

func NewContent() Content

func NewContentWithFormDataSchema

func NewContentWithFormDataSchema(schema *Schema) Content

func NewContentWithFormDataSchemaRef

func NewContentWithFormDataSchemaRef(schema *Schema) Content

func NewContentWithJSONSchema

func NewContentWithJSONSchema(schema *Schema) Content

func NewContentWithJSONSchemaRef

func NewContentWithJSONSchemaRef(schema *Schema) Content

func NewContentWithSchema

func NewContentWithSchema(schema *Schema, consumes []string) Content

func NewContentWithSchemaRef

func NewContentWithSchemaRef(schema *Schema, consumes []string) Content

func (Content) Get

func (content Content) Get(mime string) *MediaType

func (Content) Validate

func (content Content) Validate(ctx context.Context) error

Validate returns an error if Content does not comply with the OpenAPI spec.

type Discriminator

type Discriminator struct {
	ExtensionProps `json:"-" yaml:"-"`

	PropertyName string            `json:"propertyName" yaml:"propertyName"`
	Mapping      map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}

Discriminator is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminatorObject

func (*Discriminator) MarshalJSON

func (discriminator *Discriminator) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Discriminator.

func (*Discriminator) UnmarshalJSON

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

UnmarshalJSON sets Discriminator to a copy of data.

func (*Discriminator) Validate

func (discriminator *Discriminator) Validate(ctx context.Context) error

Validate returns an error if Discriminator does not comply with the OpenAPI spec.

type Encoding

type Encoding struct {
	ExtensionProps `json:"-" yaml:"-"`

	ContentType   string  `json:"contentType,omitempty" yaml:"contentType,omitempty"`
	Headers       Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
	Style         string  `json:"style,omitempty" yaml:"style,omitempty"`
	Explode       *bool   `json:"explode,omitempty" yaml:"explode,omitempty"`
	AllowReserved bool    `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}

Encoding is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encodingObject

func NewEncoding

func NewEncoding() *Encoding

func (*Encoding) MarshalJSON

func (encoding *Encoding) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Encoding.

func (*Encoding) SerializationMethod

func (encoding *Encoding) SerializationMethod() *SerializationMethod

SerializationMethod returns a serialization method of request body. When serialization method is not defined the method returns the default serialization method.

func (*Encoding) UnmarshalJSON

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

UnmarshalJSON sets Encoding to a copy of data.

func (*Encoding) Validate

func (encoding *Encoding) Validate(ctx context.Context) error

Validate returns an error if Encoding does not comply with the OpenAPI spec.

func (*Encoding) WithHeader

func (encoding *Encoding) WithHeader(name string, header *Header) *Encoding

func (*Encoding) WithHeaderRef

func (encoding *Encoding) WithHeaderRef(name string, ref *HeaderRef) *Encoding

type Example

type Example struct {
	ExtensionProps `json:"-" yaml:"-"`

	Summary       string      `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description   string      `json:"description,omitempty" yaml:"description,omitempty"`
	Value         interface{} `json:"value,omitempty" yaml:"value,omitempty"`
	ExternalValue string      `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
}

Example is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#exampleObject

func NewExample

func NewExample(value interface{}) *Example

func (*Example) MarshalJSON

func (example *Example) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Example.

func (*Example) UnmarshalJSON

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

UnmarshalJSON sets Example to a copy of data.

func (*Example) Validate

func (example *Example) Validate(ctx context.Context) error

Validate returns an error if Example does not comply with the OpenAPI spec.

type ExampleRef

type ExampleRef struct {
	Ref   string
	Value *Example
}

ExampleRef represents either a Example or a $ref to a Example. When serializing and both fields are set, Ref is preferred over Value.

func (ExampleRef) JSONLookup

func (value ExampleRef) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*ExampleRef) MarshalJSON

func (value *ExampleRef) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of ExampleRef.

func (*ExampleRef) MarshalYAML

func (value *ExampleRef) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML encoding of ExampleRef.

func (*ExampleRef) UnmarshalJSON

func (value *ExampleRef) UnmarshalJSON(data []byte) error

UnmarshalJSON sets ExampleRef to a copy of data.

func (*ExampleRef) Validate

func (value *ExampleRef) Validate(ctx context.Context) error

Validate returns an error if ExampleRef does not comply with the OpenAPI spec.

type Examples

type Examples map[string]*ExampleRef

func (Examples) JSONLookup

func (e Examples) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type ExtendedEnumItem

type ExtendedEnumItem struct {
	Key         string      `json:"key"`
	Value       interface{} `json:"value"`
	Description string      `json:"description"`
}

func NewExtendEnumItem

func NewExtendEnumItem(key string, value interface{}, description string) *ExtendedEnumItem

type ExtendedType

type ExtendedType = string
const (
	ExtendedTypeMap      ExtendedType = "map"
	ExtendedTypeAny      ExtendedType = "any"
	ExtendedTypeEnum     ExtendedType = "enum"
	ExtendedTypeSpecific ExtendedType = "specific"
	ExtendedTypeParam    ExtendedType = "param"
	ExtendedTypeObject   ExtendedType = "object"
	ExtendedTypeArray    ExtendedType = "array"
	ExtendedTypeNull     ExtendedType = "null"
	ExtendedTypeUnknown  ExtendedType = "unknown"
)

type ExtendedTypeInfo

type ExtendedTypeInfo struct {
	Type string `json:"type,omitempty"`

	// for array
	Items *Schema `json:"items,omitempty"`

	MapKey   *Schema `json:"mapKey,omitempty"`
	MapValue *Schema `json:"mapValue,omitempty"`

	EnumItems []*ExtendedEnumItem `json:"enumItems,omitempty"`

	SpecificType *SpecificType `json:"specificType,omitempty"`

	// for generic type params
	TypeParams []*TypeParam `json:"typeParams,omitempty"`

	TypeParam *TypeParam `json:"typeParam,omitempty"`
}

func NewAnyExtendedType

func NewAnyExtendedType() *ExtendedTypeInfo

func NewArrayExtType

func NewArrayExtType(items *Schema) *ExtendedTypeInfo

func NewExtendedEnumType

func NewExtendedEnumType(items ...*ExtendedEnumItem) *ExtendedTypeInfo

func NewMapExtendedType

func NewMapExtendedType(key, value *Schema) *ExtendedTypeInfo

func NewNullExtType

func NewNullExtType() *ExtendedTypeInfo

func NewObjectExtType

func NewObjectExtType() *ExtendedTypeInfo

func NewSpecificExtendType

func NewSpecificExtendType(genericType *Schema, args ...*Schema) *ExtendedTypeInfo

func NewTypeParamExtendedType

func NewTypeParamExtendedType(param *TypeParam) *ExtendedTypeInfo

func NewUnknownExtType

func NewUnknownExtType() *ExtendedTypeInfo

type ExtensionProps

type ExtensionProps struct {
	Extensions map[string]interface{} `json:"-" yaml:"-"`
}

ExtensionProps provides support for OpenAPI extensions. It reads/writes all properties that begin with "x-".

func (*ExtensionProps) DecodeWith

func (props *ExtensionProps) DecodeWith(decoder *jsoninfo.ObjectDecoder, value interface{}) error

DecodeWith will be invoked by package "jsoninfo"

func (*ExtensionProps) EncodeWith

func (props *ExtensionProps) EncodeWith(encoder *jsoninfo.ObjectEncoder, value interface{}) error

EncodeWith will be invoked by package "jsoninfo"

type ExternalDocs

type ExternalDocs struct {
	ExtensionProps `json:"-" yaml:"-"`

	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	URL         string `json:"url,omitempty" yaml:"url,omitempty"`
}

ExternalDocs is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#external-documentation-object

func (*ExternalDocs) MarshalJSON

func (e *ExternalDocs) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of ExternalDocs.

func (*ExternalDocs) UnmarshalJSON

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

UnmarshalJSON sets ExternalDocs to a copy of data.

func (*ExternalDocs) Validate

func (e *ExternalDocs) Validate(ctx context.Context) error

Validate returns an error if ExternalDocs does not comply with the OpenAPI spec.

type Format

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

Format represents a format validator registered by either DefineStringFormat or DefineStringFormatCallback

type FormatCallback

type FormatCallback func(value string) error

FormatCallback performs custom checks on exotic formats

type Header struct {
	Parameter
}

Header is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject

func (Header) JSONLookup

func (header Header) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*Header) SerializationMethod

func (header *Header) SerializationMethod() (*SerializationMethod, error)

SerializationMethod returns a header's serialization method.

func (*Header) UnmarshalJSON

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

UnmarshalJSON sets Header to a copy of data.

func (*Header) Validate

func (header *Header) Validate(ctx context.Context) error

Validate returns an error if Header does not comply with the OpenAPI spec.

type HeaderRef

type HeaderRef struct {
	Ref   string
	Value *Header
}

HeaderRef represents either a Header or a $ref to a Header. When serializing and both fields are set, Ref is preferred over Value.

func (HeaderRef) JSONLookup

func (value HeaderRef) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*HeaderRef) MarshalJSON

func (value *HeaderRef) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of HeaderRef.

func (*HeaderRef) MarshalYAML

func (value *HeaderRef) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML encoding of HeaderRef.

func (*HeaderRef) UnmarshalJSON

func (value *HeaderRef) UnmarshalJSON(data []byte) error

UnmarshalJSON sets HeaderRef to a copy of data.

func (*HeaderRef) Validate

func (value *HeaderRef) Validate(ctx context.Context) error

Validate returns an error if HeaderRef does not comply with the OpenAPI spec.

type Headers

type Headers map[string]*HeaderRef

func (Headers) JSONLookup

func (h Headers) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type Info

type Info struct {
	ExtensionProps `json:"-" yaml:"-"`

	Title          string   `json:"title" yaml:"title"` // Required
	Description    string   `json:"description,omitempty" yaml:"description,omitempty"`
	TermsOfService string   `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
	Contact        *Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
	License        *License `json:"license,omitempty" yaml:"license,omitempty"`
	Version        string   `json:"version" yaml:"version"` // Required
}

Info is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#infoObject

func (*Info) MarshalJSON

func (info *Info) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Info.

func (*Info) UnmarshalJSON

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

UnmarshalJSON sets Info to a copy of data.

func (*Info) Validate

func (info *Info) Validate(ctx context.Context) error

Validate returns an error if Info does not comply with the OpenAPI spec.

type License

type License struct {
	ExtensionProps `json:"-" yaml:"-"`

	Name string `json:"name" yaml:"name"` // Required
	URL  string `json:"url,omitempty" yaml:"url,omitempty"`
}

License is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#licenseObject

func (*License) MarshalJSON

func (license *License) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of License.

func (*License) UnmarshalJSON

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

UnmarshalJSON sets License to a copy of data.

func (*License) Validate

func (license *License) Validate(ctx context.Context) error

Validate returns an error if License does not comply with the OpenAPI spec.

type Link struct {
	ExtensionProps `json:"-" yaml:"-"`

	OperationRef string                 `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
	OperationID  string                 `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Description  string                 `json:"description,omitempty" yaml:"description,omitempty"`
	Parameters   map[string]interface{} `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Server       *Server                `json:"server,omitempty" yaml:"server,omitempty"`
	RequestBody  interface{}            `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
}

Link is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#linkObject

func (*Link) MarshalJSON

func (link *Link) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Link.

func (*Link) UnmarshalJSON

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

UnmarshalJSON sets Link to a copy of data.

func (*Link) Validate

func (link *Link) Validate(ctx context.Context) error

Validate returns an error if Link does not comply with the OpenAPI spec.

type LinkRef

type LinkRef struct {
	Ref   string
	Value *Link
}

LinkRef represents either a Link or a $ref to a Link. When serializing and both fields are set, Ref is preferred over Value.

func (*LinkRef) MarshalJSON

func (value *LinkRef) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of LinkRef.

func (*LinkRef) MarshalYAML

func (value *LinkRef) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML encoding of LinkRef.

func (*LinkRef) UnmarshalJSON

func (value *LinkRef) UnmarshalJSON(data []byte) error

UnmarshalJSON sets LinkRef to a copy of data.

func (*LinkRef) Validate

func (value *LinkRef) Validate(ctx context.Context) error

Validate returns an error if LinkRef does not comply with the OpenAPI spec.

type Links map[string]*LinkRef

func (Links) JSONLookup

func (links Links) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type MediaType

type MediaType struct {
	ExtensionProps `json:"-" yaml:"-"`

	Schema   *Schema              `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example  interface{}          `json:"example,omitempty" yaml:"example,omitempty"`
	Examples Examples             `json:"examples,omitempty" yaml:"examples,omitempty"`
	Encoding map[string]*Encoding `json:"encoding,omitempty" yaml:"encoding,omitempty"`
}

MediaType is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject

func NewMediaType

func NewMediaType() *MediaType

func (MediaType) JSONLookup

func (mediaType MediaType) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*MediaType) MarshalJSON

func (mediaType *MediaType) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of MediaType.

func (*MediaType) UnmarshalJSON

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

UnmarshalJSON sets MediaType to a copy of data.

func (*MediaType) Validate

func (mediaType *MediaType) Validate(ctx context.Context) error

Validate returns an error if MediaType does not comply with the OpenAPI spec.

func (*MediaType) WithEncoding

func (mediaType *MediaType) WithEncoding(name string, enc *Encoding) *MediaType

func (*MediaType) WithExample

func (mediaType *MediaType) WithExample(name string, value interface{}) *MediaType

func (*MediaType) WithSchema

func (mediaType *MediaType) WithSchema(schema *Schema) *MediaType

func (*MediaType) WithSchemaRef

func (mediaType *MediaType) WithSchemaRef(schema *Schema) *MediaType

type MultiError

type MultiError []error

MultiError is a collection of errors, intended for when multiple issues need to be reported upstream

func (MultiError) As

func (me MultiError) As(target interface{}) bool

As allows you to use `errors.As()` to set target to the first error within the multi error that matches the target type

func (MultiError) Error

func (me MultiError) Error() string

func (MultiError) Is

func (me MultiError) Is(target error) bool

Is allows you to determine if a generic error is in fact a MultiError using `errors.Is()` It will also return true if any of the contained errors match target

type OAuthFlow

type OAuthFlow struct {
	ExtensionProps `json:"-" yaml:"-"`

	AuthorizationURL string            `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
	TokenURL         string            `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
	RefreshURL       string            `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes" yaml:"scopes"`
}

OAuthFlow is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowObject

func (*OAuthFlow) MarshalJSON

func (flow *OAuthFlow) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of OAuthFlow.

func (*OAuthFlow) UnmarshalJSON

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

UnmarshalJSON sets OAuthFlow to a copy of data.

func (*OAuthFlow) Validate

func (flow *OAuthFlow) Validate(ctx context.Context, typ oAuthFlowType) error

Validate returns an error if OAuthFlow does not comply with the OpenAPI spec.

type OAuthFlows

type OAuthFlows struct {
	ExtensionProps `json:"-" yaml:"-"`

	Implicit          *OAuthFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty" yaml:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}

OAuthFlows is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowsObject

func (*OAuthFlows) MarshalJSON

func (flows *OAuthFlows) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of OAuthFlows.

func (*OAuthFlows) UnmarshalJSON

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

UnmarshalJSON sets OAuthFlows to a copy of data.

func (*OAuthFlows) Validate

func (flows *OAuthFlows) Validate(ctx context.Context) error

Validate returns an error if OAuthFlows does not comply with the OpenAPI spec.

type Operation

type Operation struct {
	ExtensionProps `json:"-" yaml:"-"`

	// Optional tags for documentation.
	Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`

	// Optional short summary.
	Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`

	// Optional description. Should use CommonMark syntax.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Optional operation ID.
	OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`

	// Optional parameters.
	Parameters Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`

	// Optional body parameter.
	RequestBody *RequestBodyRef `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`

	// Responses.
	Responses Responses `json:"responses" yaml:"responses"` // Required

	// Optional callbacks
	Callbacks Callbacks `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`

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

	// Optional security requirements that overrides top-level security.
	Security *SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`

	// Optional servers that overrides top-level servers.
	Servers *Servers `json:"servers,omitempty" yaml:"servers,omitempty"`

	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}

Operation represents "operation" specified by" OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object

func NewOperation

func NewOperation() *Operation

func (*Operation) AddParameter

func (operation *Operation) AddParameter(p *Parameter)

func (*Operation) AddResponse

func (operation *Operation) AddResponse(status int, response *Response)

func (Operation) JSONLookup

func (operation Operation) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*Operation) MarshalJSON

func (operation *Operation) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Operation.

func (*Operation) UnmarshalJSON

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

UnmarshalJSON sets Operation to a copy of data.

func (*Operation) Validate

func (operation *Operation) Validate(ctx context.Context) error

Validate returns an error if Operation does not comply with the OpenAPI spec.

type Parameter

type Parameter struct {
	ExtensionProps `json:"-" yaml:"-"`

	Ref             string      `json:"ref,omitempty"`
	Name            string      `json:"name,omitempty" yaml:"name,omitempty"`
	In              string      `json:"in,omitempty" yaml:"in,omitempty"`
	Description     string      `json:"description,omitempty" yaml:"description,omitempty"`
	Style           string      `json:"style,omitempty" yaml:"style,omitempty"`
	Explode         *bool       `json:"explode,omitempty" yaml:"explode,omitempty"`
	AllowEmptyValue bool        `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
	AllowReserved   bool        `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
	Deprecated      bool        `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Required        bool        `json:"required,omitempty" yaml:"required,omitempty"`
	Schema          *Schema     `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         interface{} `json:"example,omitempty" yaml:"example,omitempty"`
	Examples        Examples    `json:"examples,omitempty" yaml:"examples,omitempty"`
	Content         Content     `json:"content,omitempty" yaml:"content,omitempty"`
}

Parameter is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject

func NewCookieParameter

func NewCookieParameter(name string) *Parameter

func NewHeaderParameter

func NewHeaderParameter(name string) *Parameter

func NewPathParameter

func NewPathParameter(name string) *Parameter

func NewQueryParameter

func NewQueryParameter(name string) *Parameter

func (Parameter) JSONLookup

func (parameter Parameter) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*Parameter) MarshalJSON

func (parameter *Parameter) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Parameter.

func (*Parameter) SerializationMethod

func (parameter *Parameter) SerializationMethod() (*SerializationMethod, error)

SerializationMethod returns a parameter's serialization method. When a parameter's serialization method is not defined the method returns the default serialization method corresponding to a parameter's location.

func (*Parameter) UnmarshalJSON

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

UnmarshalJSON sets Parameter to a copy of data.

func (*Parameter) Validate

func (parameter *Parameter) Validate(ctx context.Context) error

Validate returns an error if Parameter does not comply with the OpenAPI spec.

func (*Parameter) WithDescription

func (parameter *Parameter) WithDescription(value string) *Parameter

func (*Parameter) WithRequired

func (parameter *Parameter) WithRequired(value bool) *Parameter

func (*Parameter) WithSchema

func (parameter *Parameter) WithSchema(value *Schema) *Parameter

type ParameterRef

type ParameterRef = Parameter

ParameterRef represents either a Parameter or a $ref to a Parameter. When serializing and both fields are set, Ref is preferred over Value.

type Parameters

type Parameters []*ParameterRef

Parameters is specified by OpenAPI/Swagger 3.0 standard.

func NewParameters

func NewParameters() Parameters

func (Parameters) GetByInAndName

func (parameters Parameters) GetByInAndName(in string, name string) *Parameter

func (Parameters) JSONLookup

func (p Parameters) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (Parameters) Validate

func (parameters Parameters) Validate(ctx context.Context) error

Validate returns an error if Parameters does not comply with the OpenAPI spec.

type ParametersMap

type ParametersMap map[string]*ParameterRef

func (ParametersMap) JSONLookup

func (p ParametersMap) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type PathItem

type PathItem struct {
	ExtensionProps `json:"-" yaml:"-"`

	Ref         string     `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Summary     string     `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string     `json:"description,omitempty" yaml:"description,omitempty"`
	Connect     *Operation `json:"connect,omitempty" yaml:"connect,omitempty"`
	Delete      *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
	Get         *Operation `json:"get,omitempty" yaml:"get,omitempty"`
	Head        *Operation `json:"head,omitempty" yaml:"head,omitempty"`
	Options     *Operation `json:"options,omitempty" yaml:"options,omitempty"`
	Patch       *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
	Post        *Operation `json:"post,omitempty" yaml:"post,omitempty"`
	Put         *Operation `json:"put,omitempty" yaml:"put,omitempty"`
	Trace       *Operation `json:"trace,omitempty" yaml:"trace,omitempty"`
	Servers     Servers    `json:"servers,omitempty" yaml:"servers,omitempty"`
	Parameters  Parameters `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

PathItem is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject

func (*PathItem) GetOperation

func (pathItem *PathItem) GetOperation(method string) *Operation

func (*PathItem) MarshalJSON

func (pathItem *PathItem) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of PathItem.

func (*PathItem) Operations

func (pathItem *PathItem) Operations() map[string]*Operation

func (*PathItem) SetOperation

func (pathItem *PathItem) SetOperation(method string, operation *Operation)

func (*PathItem) UnmarshalJSON

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

UnmarshalJSON sets PathItem to a copy of data.

func (*PathItem) Validate

func (pathItem *PathItem) Validate(ctx context.Context) error

Validate returns an error if PathItem does not comply with the OpenAPI spec.

type Paths

type Paths map[string]*PathItem

Paths is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#paths-object

func (Paths) Find

func (paths Paths) Find(key string) *PathItem

Find returns a path that matches the key.

The method ignores differences in template variable names (except possible "*" suffix).

For example:

paths := Paths {
  "/person/{personName}": &PathItem{},
}
pathItem := path.Find("/person/{name}")

would return the correct path item.

func (Paths) Validate

func (paths Paths) Validate(ctx context.Context) error

Validate returns an error if Paths does not comply with the OpenAPI spec.

type Ref

type Ref struct {
	Ref string `json:"$ref" yaml:"$ref"`
}

Ref is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject

type RefNameResolver

type RefNameResolver func(string) string

type RequestBodies

type RequestBodies map[string]*RequestBodyRef

func (RequestBodies) JSONLookup

func (r RequestBodies) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type RequestBody

type RequestBody struct {
	ExtensionProps `json:"-" yaml:"-"`

	Ref         string  `json:"$ref,omitempty"`
	Description string  `json:"description,omitempty" yaml:"description,omitempty"`
	Required    bool    `json:"required,omitempty" yaml:"required,omitempty"`
	Content     Content `json:"content" yaml:"content"`
}

RequestBody is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#requestBodyObject

func NewRequestBody

func NewRequestBody() *RequestBody

func (*RequestBody) GetMediaType

func (requestBody *RequestBody) GetMediaType(mediaType string) *MediaType

func (*RequestBody) MarshalJSON

func (requestBody *RequestBody) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of RequestBody.

func (*RequestBody) UnmarshalJSON

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

UnmarshalJSON sets RequestBody to a copy of data.

func (*RequestBody) Validate

func (requestBody *RequestBody) Validate(ctx context.Context) error

Validate returns an error if RequestBody does not comply with the OpenAPI spec.

func (*RequestBody) WithContent

func (requestBody *RequestBody) WithContent(content Content) *RequestBody

func (*RequestBody) WithDescription

func (requestBody *RequestBody) WithDescription(value string) *RequestBody

func (*RequestBody) WithFormDataSchema

func (requestBody *RequestBody) WithFormDataSchema(value *Schema) *RequestBody

func (*RequestBody) WithFormDataSchemaRef

func (requestBody *RequestBody) WithFormDataSchemaRef(value *Schema) *RequestBody

func (*RequestBody) WithJSONSchema

func (requestBody *RequestBody) WithJSONSchema(value *Schema) *RequestBody

func (*RequestBody) WithJSONSchemaRef

func (requestBody *RequestBody) WithJSONSchemaRef(value *Schema) *RequestBody

func (*RequestBody) WithRequired

func (requestBody *RequestBody) WithRequired(value bool) *RequestBody

func (*RequestBody) WithSchema

func (requestBody *RequestBody) WithSchema(value *Schema, consumes []string) *RequestBody

func (*RequestBody) WithSchemaRef

func (requestBody *RequestBody) WithSchemaRef(value *Schema, consumes []string) *RequestBody

type RequestBodyRef

type RequestBodyRef = RequestBody

RequestBodyRef represents either a RequestBody or a $ref to a RequestBody. When serializing and both fields are set, Ref is preferred over Value.

type Response

type Response struct {
	ExtensionProps `json:"-" yaml:"-"`

	Ref         string  `json:"$ref,omitempty"`
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`
	Headers     Headers `json:"headers,omitempty" yaml:"headers,omitempty"`
	Content     Content `json:"content,omitempty" yaml:"content,omitempty"`
	Links       Links   `json:"links,omitempty" yaml:"links,omitempty"`
}

Response is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responseObject

func NewResponse

func NewResponse() *Response

func (*Response) MarshalJSON

func (response *Response) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Response.

func (*Response) UnmarshalJSON

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

UnmarshalJSON sets Response to a copy of data.

func (*Response) Validate

func (response *Response) Validate(ctx context.Context) error

Validate returns an error if Response does not comply with the OpenAPI spec.

func (*Response) WithContent

func (response *Response) WithContent(content Content) *Response

func (*Response) WithDescription

func (response *Response) WithDescription(value string) *Response

func (*Response) WithJSONSchema

func (response *Response) WithJSONSchema(schema *Schema) *Response

func (*Response) WithJSONSchemaRef

func (response *Response) WithJSONSchemaRef(schema *Schema) *Response

type ResponseRef

type ResponseRef = Response

ResponseRef represents either a Response or a $ref to a Response. When serializing and both fields are set, Ref is preferred over Value.

type Responses

type Responses map[string]*ResponseRef

Responses is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responsesObject

func NewResponses

func NewResponses() Responses

func (Responses) Default

func (responses Responses) Default() *ResponseRef

func (Responses) Get

func (responses Responses) Get(status int) *ResponseRef

func (Responses) JSONLookup

func (responses Responses) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (Responses) Validate

func (responses Responses) Validate(ctx context.Context) error

Validate returns an error if Responses does not comply with the OpenAPI spec.

type Schema

type Schema struct {
	ExtensionProps `json:"-" yaml:"-"`

	Ref          string        `json:"ref,omitempty"`
	Summary      string        `json:"summary,omitempty"`
	OneOf        SchemaRefs    `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
	AnyOf        SchemaRefs    `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
	AllOf        SchemaRefs    `json:"allOf,omitempty" yaml:"allOf,omitempty"`
	Not          *Schema       `json:"not,omitempty" yaml:"not,omitempty"`
	Type         string        `json:"type,omitempty" yaml:"type,omitempty"`
	Title        string        `json:"title,omitempty" yaml:"title,omitempty"`
	Format       string        `json:"format,omitempty" yaml:"format,omitempty"`
	Description  string        `json:"description,omitempty" yaml:"description,omitempty"`
	Enum         []interface{} `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default      interface{}   `json:"default,omitempty" yaml:"default,omitempty"`
	Example      interface{}   `json:"example,omitempty" yaml:"example,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`

	// Array-related, here for struct compactness
	UniqueItems bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
	// Number-related, here for struct compactness
	ExclusiveMin bool `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
	ExclusiveMax bool `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	// Properties
	Nullable        bool `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	ReadOnly        bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	WriteOnly       bool `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
	Deprecated      bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	XML             *XML `json:"xml,omitempty" yaml:"xml,omitempty"`

	// Number
	Min        *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	Max        *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`

	// String
	MinLength uint64  `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	MaxLength *uint64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	Pattern   string  `json:"pattern,omitempty" yaml:"pattern,omitempty"`

	// Array
	MinItems uint64  `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxItems *uint64 `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	Items    *Schema `json:"items,omitempty" yaml:"items,omitempty"`

	// Object
	Required                    []string       `json:"required,omitempty" yaml:"required,omitempty"`
	Properties                  Schemas        `json:"properties,omitempty" yaml:"properties,omitempty"`
	MinProps                    uint64         `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	MaxProps                    *uint64        `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
	AdditionalPropertiesAllowed *bool          `multijson:"additionalProperties,omitempty" json:"-" yaml:"-"` // In this order...
	AdditionalProperties        *Schema        `multijson:"additionalProperties,omitempty" json:"-" yaml:"-"` // ...for multijson
	Discriminator               *Discriminator `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`

	// 拓展类型信息. 用于代码生成
	ExtendedTypeInfo       *ExtendedTypeInfo `json:"ext,omitempty" yaml:"-"`
	Key                    string            `json:"-" yaml:"-"`
	SpecializedFromGeneric bool              `json:"-"`
	// contains filtered or unexported fields
}

Schema is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject

func NewAllOfSchema

func NewAllOfSchema(schemas ...*Schema) *Schema

func NewAnyOfSchema

func NewAnyOfSchema(schemas ...*Schema) *Schema

func NewArraySchema

func NewArraySchema(item *Schema) *Schema

func NewBoolSchema

func NewBoolSchema() *Schema

func NewBytesSchema

func NewBytesSchema() *Schema

func NewDateTimeSchema

func NewDateTimeSchema() *Schema

func NewFloat64Schema

func NewFloat64Schema() *Schema

func NewInt32Schema

func NewInt32Schema() *Schema

func NewInt64Schema

func NewInt64Schema() *Schema

func NewIntegerSchema

func NewIntegerSchema() *Schema

func NewObjectSchema

func NewObjectSchema() *Schema

func NewOneOfSchema

func NewOneOfSchema(schemas ...*Schema) *Schema

func NewSchema

func NewSchema() *Schema

func NewStringSchema

func NewStringSchema() *Schema

func NewTypeParamSchema

func NewTypeParamSchema(param *TypeParam) *Schema

func NewUUIDSchema

func NewUUIDSchema() *Schema

func RefComponentSchemas

func RefComponentSchemas(key string) *Schema

func RefSchema

func RefSchema(id string) *Schema

func RefTo

func RefTo(path ...string) *Schema

func Unref

func Unref(t *T, schema *Schema) *Schema

func (*Schema) Clone

func (schema *Schema) Clone() *Schema

func (*Schema) GetKey

func (value *Schema) GetKey() string

func (*Schema) IsEmpty

func (schema *Schema) IsEmpty() bool

func (*Schema) IsMatching

func (schema *Schema) IsMatching(value interface{}) bool

func (*Schema) IsMatchingJSONArray

func (schema *Schema) IsMatchingJSONArray(value []interface{}) bool

func (*Schema) IsMatchingJSONBoolean

func (schema *Schema) IsMatchingJSONBoolean(value bool) bool

func (*Schema) IsMatchingJSONNumber

func (schema *Schema) IsMatchingJSONNumber(value float64) bool

func (*Schema) IsMatchingJSONObject

func (schema *Schema) IsMatchingJSONObject(value map[string]interface{}) bool

func (*Schema) IsMatchingJSONString

func (schema *Schema) IsMatchingJSONString(value string) bool

func (*Schema) IsTypeAlias

func (value *Schema) IsTypeAlias() bool

func (*Schema) JSONLookup

func (schema *Schema) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*Schema) MarshalJSON

func (schema *Schema) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Schema.

func (*Schema) NewRef

func (schema *Schema) NewRef() *Schema

func (*Schema) UnmarshalJSON

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

UnmarshalJSON sets Schema to a copy of data.

func (*Schema) Unref

func (value *Schema) Unref(doc *T) *Schema

func (*Schema) Validate

func (schema *Schema) Validate(ctx context.Context) error

Validate returns an error if Schema does not comply with the OpenAPI spec.

func (*Schema) VisitJSON

func (schema *Schema) VisitJSON(value interface{}, opts ...SchemaValidationOption) error

func (*Schema) VisitJSONArray

func (schema *Schema) VisitJSONArray(value []interface{}) error

func (*Schema) VisitJSONBoolean

func (schema *Schema) VisitJSONBoolean(value bool) error

func (*Schema) VisitJSONNumber

func (schema *Schema) VisitJSONNumber(value float64) error

func (*Schema) VisitJSONObject

func (schema *Schema) VisitJSONObject(value map[string]interface{}) error

func (*Schema) VisitJSONString

func (schema *Schema) VisitJSONString(value string) error

func (*Schema) WithAdditionalProperties

func (schema *Schema) WithAdditionalProperties(v *Schema) *Schema

func (*Schema) WithAnyAdditionalProperties

func (schema *Schema) WithAnyAdditionalProperties() *Schema

func (*Schema) WithDefault

func (schema *Schema) WithDefault(defaultValue interface{}) *Schema

func (*Schema) WithDescription

func (schema *Schema) WithDescription(s string) *Schema

func (*Schema) WithEnum

func (schema *Schema) WithEnum(values ...interface{}) *Schema

func (*Schema) WithExclusiveMax

func (schema *Schema) WithExclusiveMax(value bool) *Schema

func (*Schema) WithExclusiveMin

func (schema *Schema) WithExclusiveMin(value bool) *Schema

func (*Schema) WithExtendedType

func (schema *Schema) WithExtendedType(t *ExtendedTypeInfo) *Schema

func (*Schema) WithFormat

func (schema *Schema) WithFormat(value string) *Schema

func (*Schema) WithItems

func (schema *Schema) WithItems(value *Schema) *Schema

func (*Schema) WithLength

func (schema *Schema) WithLength(i int64) *Schema

func (*Schema) WithLengthDecodedBase64

func (schema *Schema) WithLengthDecodedBase64(i int64) *Schema

func (*Schema) WithMax

func (schema *Schema) WithMax(value float64) *Schema

func (*Schema) WithMaxItems

func (schema *Schema) WithMaxItems(i int64) *Schema

func (*Schema) WithMaxLength

func (schema *Schema) WithMaxLength(i int64) *Schema

func (*Schema) WithMaxLengthDecodedBase64

func (schema *Schema) WithMaxLengthDecodedBase64(i int64) *Schema

func (*Schema) WithMaxProperties

func (schema *Schema) WithMaxProperties(i int64) *Schema

func (*Schema) WithMin

func (schema *Schema) WithMin(value float64) *Schema

func (*Schema) WithMinItems

func (schema *Schema) WithMinItems(i int64) *Schema

func (*Schema) WithMinLength

func (schema *Schema) WithMinLength(i int64) *Schema

func (*Schema) WithMinLengthDecodedBase64

func (schema *Schema) WithMinLengthDecodedBase64(i int64) *Schema

func (*Schema) WithMinProperties

func (schema *Schema) WithMinProperties(i int64) *Schema

func (*Schema) WithNullable

func (schema *Schema) WithNullable() *Schema

func (*Schema) WithPattern

func (schema *Schema) WithPattern(pattern string) *Schema

func (*Schema) WithProperties

func (schema *Schema) WithProperties(properties map[string]*Schema) *Schema

func (*Schema) WithProperty

func (schema *Schema) WithProperty(name string, propertySchema *Schema) *Schema

func (*Schema) WithPropertyRef

func (schema *Schema) WithPropertyRef(name string, ref *Schema) *Schema

func (*Schema) WithType

func (schema *Schema) WithType(s string) *Schema

func (*Schema) WithUniqueItems

func (schema *Schema) WithUniqueItems(unique bool) *Schema

type SchemaError

type SchemaError struct {
	Value interface{}

	Schema      *Schema
	SchemaField string
	Reason      string
	Origin      error
	// contains filtered or unexported fields
}

func (*SchemaError) Error

func (err *SchemaError) Error() string

func (*SchemaError) JSONPointer

func (err *SchemaError) JSONPointer() []string

func (SchemaError) Unwrap

func (err SchemaError) Unwrap() error

type SchemaRef

type SchemaRef = Schema

SchemaRef represents either a Schema or a $ref to a Schema. When serializing and both fields are set, Ref is preferred over Value.

type SchemaRefs

type SchemaRefs []*Schema

func (SchemaRefs) JSONLookup

func (s SchemaRefs) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type SchemaValidationOption

type SchemaValidationOption func(*schemaValidationSettings)

SchemaValidationOption describes options a user has when validating request / response bodies.

func DefaultsSet

func DefaultsSet(f func()) SchemaValidationOption

DefaultsSet executes the given callback (once) IFF schema validation set default values.

func DisablePatternValidation

func DisablePatternValidation() SchemaValidationOption

DisablePatternValidation setting makes Validate not return an error when validating patterns that are not supported by the Go regexp engine.

func EnableFormatValidation

func EnableFormatValidation() SchemaValidationOption

EnableFormatValidation setting makes Validate not return an error when validating documents that mention schema formats that are not defined by the OpenAPIv3 specification.

func FailFast

func FailFast() SchemaValidationOption

FailFast returns schema validation errors quicker.

func MultiErrors

func MultiErrors() SchemaValidationOption

func SetSchemaErrorMessageCustomizer

func SetSchemaErrorMessageCustomizer(f func(err *SchemaError) string) SchemaValidationOption

SetSchemaErrorMessageCustomizer allows to override the schema error message. If the passed function returns an empty string, it returns to the previous Error() implementation.

Example
package main

import (
	"fmt"

	"github.com/getkin/kin-openapi/openapi3"
)

func main() {
	loader := openapi3.NewLoader()
	spc := `
components:
  schemas:
    Something:
      type: object
      properties:
        field:
          title: Some field
          type: string
`[1:]

	doc, err := loader.LoadFromData([]byte(spc))
	if err != nil {
		panic(err)
	}

	opt := openapi3.SetSchemaErrorMessageCustomizer(func(err *openapi3.SchemaError) string {
		return fmt.Sprintf(`field "%s" should be string`, err.Schema.Title)
	})

	err = doc.Components.Schemas["Something"].Value.Properties["field"].Value.VisitJSON(123, opt)

	fmt.Println(err.Error())

}
Output:

field "Some field" should be string

func VisitAsRequest

func VisitAsRequest() SchemaValidationOption

func VisitAsResponse

func VisitAsResponse() SchemaValidationOption

type Schemas

type Schemas map[string]*Schema

func (Schemas) JSONLookup

func (s Schemas) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type SecurityRequirement

type SecurityRequirement map[string][]string

SecurityRequirement is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityRequirementObject

func NewSecurityRequirement

func NewSecurityRequirement() SecurityRequirement

func (SecurityRequirement) Authenticate

func (security SecurityRequirement) Authenticate(provider string, scopes ...string) SecurityRequirement

func (*SecurityRequirement) Validate

func (security *SecurityRequirement) Validate(ctx context.Context) error

Validate returns an error if SecurityRequirement does not comply with the OpenAPI spec.

type SecurityRequirements

type SecurityRequirements []SecurityRequirement

func NewSecurityRequirements

func NewSecurityRequirements() *SecurityRequirements

func (SecurityRequirements) Validate

func (srs SecurityRequirements) Validate(ctx context.Context) error

Validate returns an error if SecurityRequirements does not comply with the OpenAPI spec.

func (*SecurityRequirements) With

func (srs *SecurityRequirements) With(securityRequirement SecurityRequirement) *SecurityRequirements

type SecurityScheme

type SecurityScheme struct {
	ExtensionProps `json:"-" yaml:"-"`

	Type             string      `json:"type,omitempty" yaml:"type,omitempty"`
	Description      string      `json:"description,omitempty" yaml:"description,omitempty"`
	Name             string      `json:"name,omitempty" yaml:"name,omitempty"`
	In               string      `json:"in,omitempty" yaml:"in,omitempty"`
	Scheme           string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`
	BearerFormat     string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
	Flows            *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
	OpenIdConnectUrl string      `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
}

SecurityScheme is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securitySchemeObject

func NewCSRFSecurityScheme

func NewCSRFSecurityScheme() *SecurityScheme

func NewJWTSecurityScheme

func NewJWTSecurityScheme() *SecurityScheme

func NewOIDCSecurityScheme

func NewOIDCSecurityScheme(oidcUrl string) *SecurityScheme

func NewSecurityScheme

func NewSecurityScheme() *SecurityScheme

func (*SecurityScheme) MarshalJSON

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

MarshalJSON returns the JSON encoding of SecurityScheme.

func (*SecurityScheme) UnmarshalJSON

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

UnmarshalJSON sets SecurityScheme to a copy of data.

func (*SecurityScheme) Validate

func (ss *SecurityScheme) Validate(ctx context.Context) error

Validate returns an error if SecurityScheme does not comply with the OpenAPI spec.

func (*SecurityScheme) WithBearerFormat

func (ss *SecurityScheme) WithBearerFormat(value string) *SecurityScheme

func (*SecurityScheme) WithDescription

func (ss *SecurityScheme) WithDescription(value string) *SecurityScheme

func (*SecurityScheme) WithIn

func (ss *SecurityScheme) WithIn(value string) *SecurityScheme

func (*SecurityScheme) WithName

func (ss *SecurityScheme) WithName(value string) *SecurityScheme

func (*SecurityScheme) WithScheme

func (ss *SecurityScheme) WithScheme(value string) *SecurityScheme

func (*SecurityScheme) WithType

func (ss *SecurityScheme) WithType(value string) *SecurityScheme

type SecuritySchemeRef

type SecuritySchemeRef struct {
	Ref   string
	Value *SecurityScheme
}

SecuritySchemeRef represents either a SecurityScheme or a $ref to a SecurityScheme. When serializing and both fields are set, Ref is preferred over Value.

func (SecuritySchemeRef) JSONLookup

func (value SecuritySchemeRef) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

func (*SecuritySchemeRef) MarshalJSON

func (value *SecuritySchemeRef) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of SecuritySchemeRef.

func (*SecuritySchemeRef) MarshalYAML

func (value *SecuritySchemeRef) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML encoding of SecuritySchemeRef.

func (*SecuritySchemeRef) UnmarshalJSON

func (value *SecuritySchemeRef) UnmarshalJSON(data []byte) error

UnmarshalJSON sets SecuritySchemeRef to a copy of data.

func (*SecuritySchemeRef) Validate

func (value *SecuritySchemeRef) Validate(ctx context.Context) error

Validate returns an error if SecuritySchemeRef does not comply with the OpenAPI spec.

type SecuritySchemes

type SecuritySchemes map[string]*SecuritySchemeRef

func (SecuritySchemes) JSONLookup

func (s SecuritySchemes) JSONLookup(token string) (interface{}, error)

JSONLookup implements github.com/go-openapi/jsonpointer#JSONPointable

type SerializationMethod

type SerializationMethod struct {
	Style   string
	Explode bool
}

SerializationMethod describes a serialization method of HTTP request's parameters and body.

type Server

type Server struct {
	ExtensionProps `json:"-" yaml:"-"`

	URL         string                     `json:"url" yaml:"url"`
	Description string                     `json:"description,omitempty" yaml:"description,omitempty"`
	Variables   map[string]*ServerVariable `json:"variables,omitempty" yaml:"variables,omitempty"`
}

Server is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject

func (*Server) BasePath

func (server *Server) BasePath() (string, error)

BasePath returns the base path extracted from the default values of variables, if any. Assumes a valid struct (per Validate()).

func (*Server) MarshalJSON

func (server *Server) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Server.

func (Server) MatchRawURL

func (server Server) MatchRawURL(input string) ([]string, string, bool)

func (Server) ParameterNames

func (server Server) ParameterNames() ([]string, error)

func (*Server) UnmarshalJSON

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

UnmarshalJSON sets Server to a copy of data.

func (*Server) Validate

func (server *Server) Validate(ctx context.Context) (err error)

Validate returns an error if Server does not comply with the OpenAPI spec.

type ServerVariable

type ServerVariable struct {
	ExtensionProps `json:"-" yaml:"-"`

	Enum        []string `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default     string   `json:"default,omitempty" yaml:"default,omitempty"`
	Description string   `json:"description,omitempty" yaml:"description,omitempty"`
}

ServerVariable is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object

func (*ServerVariable) MarshalJSON

func (serverVariable *ServerVariable) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of ServerVariable.

func (*ServerVariable) UnmarshalJSON

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

UnmarshalJSON sets ServerVariable to a copy of data.

func (*ServerVariable) Validate

func (serverVariable *ServerVariable) Validate(ctx context.Context) error

Validate returns an error if ServerVariable does not comply with the OpenAPI spec.

type Servers

type Servers []*Server

Servers is specified by OpenAPI/Swagger standard version 3.

func (Servers) BasePath

func (servers Servers) BasePath() (string, error)

BasePath returns the base path of the first server in the list, or /.

func (Servers) MatchURL

func (servers Servers) MatchURL(parsedURL *url.URL) (*Server, []string, string)

func (Servers) Validate

func (servers Servers) Validate(ctx context.Context) error

Validate returns an error if Servers does not comply with the OpenAPI spec.

type SliceUniqueItemsChecker

type SliceUniqueItemsChecker func(items []interface{}) bool

SliceUniqueItemsChecker is an function used to check if an given slice have unique items.

type SpecificType

type SpecificType struct {
	Args []*Schema `json:"args"`
	Type *Schema   `json:"type"`
}

type T

type T struct {
	ExtensionProps `json:"-" yaml:"-"`

	OpenAPI      string               `json:"openapi" yaml:"openapi"` // Required
	Components   Components           `json:"components,omitempty" yaml:"components,omitempty"`
	Info         *Info                `json:"info" yaml:"info"`   // Required
	Paths        Paths                `json:"paths" yaml:"paths"` // Required
	Security     SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
	Servers      Servers              `json:"servers,omitempty" yaml:"servers,omitempty"`
	Tags         Tags                 `json:"tags,omitempty" yaml:"tags,omitempty"`
	ExternalDocs *ExternalDocs        `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
	// contains filtered or unexported fields
}

T is the root of an OpenAPI v3 document See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasObject

func (*T) AddOperation

func (doc *T) AddOperation(path string, method string, operation *Operation)

func (*T) AddServer

func (doc *T) AddServer(server *Server)

func (*T) GetSchemaByRef

func (doc *T) GetSchemaByRef(ref string) *Schema

func (*T) InternalizeRefs

func (doc *T) InternalizeRefs(ctx context.Context, refNameResolver func(ref string) string)

InternalizeRefs removes all references to external files from the spec and moves them to the components section.

refNameResolver takes in references to returns a name to store the reference under locally. It MUST return a unique name for each reference type. A default implementation is provided that will suffice for most use cases. See the function documention for more details.

Example:

doc.InternalizeRefs(context.Background(), nil)

func (*T) MarshalJSON

func (doc *T) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of T.

func (*T) Specialize

func (doc *T) Specialize() *T

func (*T) UnmarshalJSON

func (doc *T) UnmarshalJSON(data []byte) error

UnmarshalJSON sets T to a copy of data.

func (*T) Validate

func (doc *T) Validate(ctx context.Context, opts ...ValidationOption) error

Validate returns an error if T does not comply with the OpenAPI spec. Validations Options can be provided to modify the validation behavior.

type Tag

type Tag struct {
	ExtensionProps `json:"-" yaml:"-"`

	Name         string        `json:"name,omitempty" yaml:"name,omitempty"`
	Description  string        `json:"description,omitempty" yaml:"description,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}

Tag is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tagObject

func (*Tag) MarshalJSON

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

MarshalJSON returns the JSON encoding of Tag.

func (*Tag) UnmarshalJSON

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

UnmarshalJSON sets Tag to a copy of data.

func (*Tag) Validate

func (t *Tag) Validate(ctx context.Context) error

Validate returns an error if Tag does not comply with the OpenAPI spec.

type Tags

type Tags []*Tag

Tags is specified by OpenAPI/Swagger 3.0 standard.

func (Tags) Get

func (tags Tags) Get(name string) *Tag

func (Tags) Validate

func (tags Tags) Validate(ctx context.Context) error

Validate returns an error if Tags does not comply with the OpenAPI spec.

type TypeParam

type TypeParam struct {
	Index      int    `json:"index"`
	Name       string `json:"name"`
	Constraint string `json:"constraint"`
}

type ValidationOption

type ValidationOption func(options *ValidationOptions)

ValidationOption allows the modification of how the OpenAPI document is validated.

func DisableExamplesValidation

func DisableExamplesValidation() ValidationOption

DisableExamplesValidation disables all example schema validation.

func DisableSchemaPatternValidation

func DisableSchemaPatternValidation() ValidationOption

DisableSchemaPatternValidation makes Validate not return an error when validating patterns that are not supported by the Go regexp engine.

func EnableSchemaFormatValidation

func EnableSchemaFormatValidation() ValidationOption

EnableSchemaFormatValidation makes Validate not return an error when validating documents that mention schema formats that are not defined by the OpenAPIv3 specification.

type ValidationOptions

type ValidationOptions struct {
	SchemaFormatValidationEnabled   bool
	SchemaPatternValidationDisabled bool
	ExamplesValidationDisabled      bool
	// contains filtered or unexported fields
}

ValidationOptions provides configuration for validating OpenAPI documents.

type XML

type XML struct {
	ExtensionProps `json:"-" yaml:"-"`

	Name      string `json:"name,omitempty" yaml:"name,omitempty"`
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	Prefix    string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
	Attribute bool   `json:"attribute,omitempty" yaml:"attribute,omitempty"`
	Wrapped   bool   `json:"wrapped,omitempty" yaml:"wrapped,omitempty"`
}

XML is specified by OpenAPI/Swagger standard version 3. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xmlObject

func (*XML) MarshalJSON

func (xml *XML) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of XML.

func (*XML) UnmarshalJSON

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

UnmarshalJSON sets XML to a copy of data.

func (*XML) Validate

func (xml *XML) Validate(ctx context.Context) error

Validate returns an error if XML does not comply with the OpenAPI spec.

Jump to

Keyboard shortcuts

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