openapi3

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package openapi3 parses and writes OpenAPI 3 specifications.

The OpenAPI 3.0 specification can be found at:

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

Index

Examples

Constants

View Source
const (
	ParameterInPath   = "path"
	ParameterInQuery  = "query"
	ParameterInHeader = "header"
	ParameterInCookie = "cookie"
)

Variables

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

	ErrSchemaInputNaN = errors.New("NaN is not allowed")
	ErrSchemaInputInf = errors.New("Inf is not allowed")
)
View Source
var SchemaStringFormats = make(map[string]*regexp.Regexp, 8)

Functions

func BoolPtr

func BoolPtr(value bool) *bool

BoolPtr is a helper for defining OpenAPI schemas.

func DefineStringFormat

func DefineStringFormat(name string, pattern string)

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 Uint64Ptr

func Uint64Ptr(value uint64) *uint64

Uint64Ptr is a helper for defining OpenAPI schemas.

func ValidateIdentifier

func ValidateIdentifier(value string) error

Types

type Callback

type Callback map[string]*PathItem

Callback is specified by OpenAPI/Swagger standard version 3.0.

func (Callback) Validate

func (value Callback) Validate(c context.Context) error

type CallbackRef

type CallbackRef struct {
	Ref   string
	Value *Callback
}

func (*CallbackRef) MarshalJSON

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

func (*CallbackRef) UnmarshalJSON

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

func (*CallbackRef) Validate

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

type Components

type Components struct {
	ExtensionProps
	Schemas         map[string]*SchemaRef         `json:"schemas,omitempty"`
	Parameters      map[string]*ParameterRef      `json:"parameters,omitempty"`
	Headers         map[string]*HeaderRef         `json:"headers,omitempty"`
	RequestBodies   map[string]*RequestBodyRef    `json:"requestBodies,omitempty"`
	Responses       map[string]*ResponseRef       `json:"responses,omitempty"`
	SecuritySchemes map[string]*SecuritySchemeRef `json:"securitySchemes,omitempty"`
	Examples        map[string]*ExampleRef        `json:"examples,omitempty"`
	Tags            Tags                          `json:"tags,omitempty"`
	Links           map[string]*LinkRef           `json:"links,omitempty"`
	Callbacks       map[string]*CallbackRef       `json:"callbacks,omitempty"`
}

Components is specified by OpenAPI/Swagger standard version 3.0.

func NewComponents

func NewComponents() Components

func (*Components) MarshalJSON

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

func (*Components) UnmarshalJSON

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

func (*Components) Validate

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

type Contact

type Contact struct {
	ExtensionProps
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

Contact is specified by OpenAPI/Swagger standard version 3.0.

func (*Contact) MarshalJSON

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

func (*Contact) UnmarshalJSON

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

type Content

type Content map[string]*MediaType

Content is specified by OpenAPI/Swagger 3.0 standard.

func NewContent

func NewContent() Content

func NewContentWithJSONSchema

func NewContentWithJSONSchema(schema *Schema) Content

func NewContentWithJSONSchemaRef

func NewContentWithJSONSchemaRef(schema *SchemaRef) Content

func (Content) Get

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

func (Content) Validate

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

type Encoding

type Encoding struct {
	ExtensionProps

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

Encoding is specified by OpenAPI/Swagger 3.0 standard.

func NewEncoding

func NewEncoding() *Encoding

func (*Encoding) MarshalJSON

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

func (*Encoding) UnmarshalJSON

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

func (*Encoding) Validate

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

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

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

Example is specified by OpenAPI/Swagger 3.0 standard.

func NewExample

func NewExample(value interface{}) *Example

func (*Example) MarshalJSON

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

func (*Example) UnmarshalJSON

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

type ExampleRef

type ExampleRef struct {
	Ref   string
	Value *Example
}

func (*ExampleRef) MarshalJSON

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

func (*ExampleRef) UnmarshalJSON

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

func (*ExampleRef) Validate

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

type ExtensionProps

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

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 {
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
}

ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.

type Header struct {
	ExtensionProps

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

	// Optional schema
	Schema *SchemaRef `json:"schema,omitempty"`
}

func (*Header) Validate

func (value *Header) Validate(c context.Context) error

type HeaderRef

type HeaderRef struct {
	Ref   string
	Value *Header
}

func (*HeaderRef) MarshalJSON

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

func (*HeaderRef) UnmarshalJSON

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

func (*HeaderRef) Validate

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

type Info

type Info struct {
	ExtensionProps
	Title          string   `json:"title,omitempty"`
	Description    string   `json:"description,omitempty"`
	TermsOfService string   `json:"termsOfService,omitempty"`
	Contact        *Contact `json:"contact,omitempty"`
	License        *License `json:"license,omitempty"`
	Version        string   `json:"version,omitempty"`
}

Info is specified by OpenAPI/Swagger standard version 3.0.

func (*Info) MarshalJSON

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

func (*Info) UnmarshalJSON

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

type License

type License struct {
	ExtensionProps
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

License is specified by OpenAPI/Swagger standard version 3.0.

func (*License) MarshalJSON

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

func (*License) UnmarshalJSON

func (value *License) UnmarshalJSON(data []byte) error
type Link struct {
	ExtensionProps
	Description string                 `json:"description,omitempty"`
	Href        string                 `json:"href,omitempty"`
	OperationID string                 `json:"operationId,omitempty"`
	Parameters  map[string]interface{} `json:"parameters,omitempty"`
	Headers     map[string]*Schema     `json:"headers,omitempty"`
}

Link is specified by OpenAPI/Swagger standard version 3.0.

func (*Link) MarshalJSON

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

func (*Link) UnmarshalJSON

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

func (*Link) Validate

func (value *Link) Validate(c context.Context) error

type LinkRef

type LinkRef struct {
	Ref   string
	Value *Link
}

func (*LinkRef) MarshalJSON

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

func (*LinkRef) UnmarshalJSON

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

func (*LinkRef) Validate

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

type MediaType

type MediaType struct {
	ExtensionProps

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

MediaType is specified by OpenAPI/Swagger 3.0 standard.

func NewMediaType

func NewMediaType() *MediaType

func (*MediaType) MarshalJSON

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

func (*MediaType) UnmarshalJSON

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

func (*MediaType) Validate

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

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 *SchemaRef) *MediaType

type OAuthFlow

type OAuthFlow struct {
	ExtensionProps
	AuthorizationURL string            `json:"authorizationUrl,omitempty"`
	TokenURL         string            `json:"tokenUrl,omitempty"`
	RefreshURL       string            `json:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes"`
}

func (*OAuthFlow) MarshalJSON

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

func (*OAuthFlow) UnmarshalJSON

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

func (*OAuthFlow) Validate

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

type OAuthFlows

type OAuthFlows struct {
	ExtensionProps
	Implicit          *OAuthFlow `json:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
}

func (*OAuthFlows) MarshalJSON

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

func (*OAuthFlows) UnmarshalJSON

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

func (*OAuthFlows) Validate

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

type Operation

type Operation struct {
	ExtensionProps

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

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

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

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

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

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

	// Optional responses.
	Responses Responses `json:"responses,omitempty"`

	// Optional callbacks
	Callbacks map[string]*CallbackRef `json:"callbacks,omitempty"`

	Deprecated bool `json:"deprecated,omitempty"`

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

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

Operation represents "operation" specified by" OpenAPI/Swagger 3.0 standard.

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) MarshalJSON

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

func (*Operation) UnmarshalJSON

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

func (*Operation) Validate

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

type Parameter

type Parameter struct {
	ExtensionProps
	Name            string                 `json:"name,omitempty"`
	In              string                 `json:"in,omitempty"`
	Description     string                 `json:"description,omitempty"`
	Style           string                 `json:"style,omitempty"`
	AllowEmptyValue bool                   `json:"allowEmptyValue,omitempty"`
	AllowReserved   bool                   `json:"allowReserved,omitempty"`
	Deprecated      bool                   `json:"deprecated,omitempty"`
	Required        bool                   `json:"required,omitempty"`
	Schema          *SchemaRef             `json:"schema,omitempty"`
	Example         interface{}            `json:"example,omitempty"`
	Examples        map[string]*ExampleRef `json:"examples,omitempty"`
	Content         Content                `json:"content,omitempty"`
}

Parameter is specified by OpenAPI/Swagger 3.0 standard.

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) MarshalJSON

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

func (*Parameter) UnmarshalJSON

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

func (*Parameter) Validate

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

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 struct {
	Ref   string
	Value *Parameter
}

func (*ParameterRef) MarshalJSON

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

func (*ParameterRef) UnmarshalJSON

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

func (*ParameterRef) Validate

func (value *ParameterRef) Validate(c context.Context) error

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) Validate

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

type PathItem

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

func (*PathItem) GetOperation

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

func (*PathItem) MarshalJSON

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

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

func (*PathItem) Validate

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

type Paths

type Paths map[string]*PathItem

Paths is specified by OpenAPI/Swagger standard version 3.0.

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 := openapi3.Paths {
  "/person/{personName}": &openapi3.PathItem{},
}
pathItem := path.Find("/person/{name}")

would return the correct path item.

func (Paths) Validate

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

type RequestBody

type RequestBody struct {
	ExtensionProps
	Description string  `json:"description,omitempty"`
	Required    bool    `json:"required,omitempty"`
	Content     Content `json:"content,omitempty"`
}

RequestBody is specified by OpenAPI/Swagger 3.0 standard.

func NewRequestBody

func NewRequestBody() *RequestBody

func (*RequestBody) GetMediaType

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

func (*RequestBody) MarshalJSON

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

func (*RequestBody) UnmarshalJSON

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

func (*RequestBody) Validate

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

func (*RequestBody) WithContent

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

func (*RequestBody) WithDescription

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

func (*RequestBody) WithJSONSchema

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

func (*RequestBody) WithJSONSchemaRef

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

func (*RequestBody) WithRequired

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

type RequestBodyRef

type RequestBodyRef struct {
	Ref   string
	Value *RequestBody
}

func (*RequestBodyRef) MarshalJSON

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

func (*RequestBodyRef) UnmarshalJSON

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

func (*RequestBodyRef) Validate

func (value *RequestBodyRef) Validate(c context.Context) error

type Response

type Response struct {
	ExtensionProps
	Description string              `json:"description,omitempty"`
	Headers     map[string]*Schema  `json:"headers,omitempty"`
	Content     Content             `json:"content,omitempty"`
	Links       map[string]*LinkRef `json:"links,omitempty"`
}

Response is specified by OpenAPI/Swagger 3.0 standard.

func NewResponse

func NewResponse() *Response

func (*Response) MarshalJSON

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

func (*Response) UnmarshalJSON

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

func (*Response) Validate

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

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 *SchemaRef) *Response

type ResponseRef

type ResponseRef struct {
	Ref   string
	Value *Response
}

func (*ResponseRef) MarshalJSON

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

func (*ResponseRef) UnmarshalJSON

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

func (*ResponseRef) Validate

func (value *ResponseRef) Validate(c context.Context) error

type Responses

type Responses map[string]*ResponseRef

Responses is specified by OpenAPI/Swagger 3.0 standard.

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) Validate

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

type Schema

type Schema struct {
	ExtensionProps

	OneOf        []*SchemaRef  `json:"oneOf,omitempty"`
	AnyOf        []*SchemaRef  `json:"anyOf,omitempty"`
	AllOf        []*SchemaRef  `json:"allOf,omitempty"`
	Not          *SchemaRef    `json:"not,omitempty"`
	Type         string        `json:"type,omitempty"`
	Format       string        `json:"format,omitempty"`
	Description  string        `json:"description,omitempty"`
	Enum         []interface{} `json:"enum,omitempty"`
	Default      interface{}   `json:"default,omitempty"`
	Example      interface{}   `json:"example,omitempty"`
	ExternalDocs interface{}   `json:"externalDocs,omitempty"`

	// Object-related, here for struct compactness
	AdditionalPropertiesAllowed *bool `json:"-" multijson:"additionalProperties,omitempty"`
	// Array-related, here for struct compactness
	UniqueItems bool `json:"uniqueItems,omitempty"`
	// Number-related, here for struct compactness
	ExclusiveMin bool `json:"exclusiveMinimum,omitempty"`
	ExclusiveMax bool `json:"exclusiveMaximum,omitempty"`
	// Properties
	Nullable  bool        `json:"nullable,omitempty"`
	ReadOnly  bool        `json:"readOnly,omitempty"`
	WriteOnly bool        `json:"writeOnly,omitempty"`
	XML       interface{} `json:"xml,omitempty"`

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

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

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

	// Object
	Required             []string              `json:"required,omitempty"`
	Properties           map[string]*SchemaRef `json:"properties,omitempty"`
	MinProps             uint64                `json:"minProperties,omitempty"`
	MaxProps             *uint64               `json:"maxProperties,omitempty"`
	AdditionalProperties *SchemaRef            `json:"-" multijson:"additionalProperties,omitempty"`
	Discriminator        string                `json:"discriminator,omitempty"`

	PatternProperties string `json:"patternProperties,omitempty"`
	// contains filtered or unexported fields
}

Schema is specified by OpenAPI/Swagger 3.0 standard.

func NewAllOfSchema

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

func NewAnyOfSchema

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

func NewArraySchema

func NewArraySchema() *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 (*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) MarshalJSON

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

func (*Schema) NewRef

func (schema *Schema) NewRef() *SchemaRef

func (*Schema) UnmarshalJSON

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

func (*Schema) Validate

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

func (*Schema) VisitJSON

func (schema *Schema) VisitJSON(value interface{}) 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) 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) 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 *SchemaRef) *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

type SchemaRef

type SchemaRef struct {
	Ref   string
	Value *Schema
}

func NewSchemaRef

func NewSchemaRef(ref string, value *Schema) *SchemaRef

func (*SchemaRef) MarshalJSON

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

func (*SchemaRef) UnmarshalJSON

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

func (*SchemaRef) Validate

func (value *SchemaRef) Validate(c context.Context) error

type SecurityRequirement

type SecurityRequirement map[string][]string

func NewSecurityRequirement

func NewSecurityRequirement() SecurityRequirement

func (SecurityRequirement) Authenticate

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

func (SecurityRequirement) Validate

func (security SecurityRequirement) Validate(c context.Context) error

type SecurityRequirements

type SecurityRequirements []SecurityRequirement

func NewSecurityRequirements

func NewSecurityRequirements() *SecurityRequirements

func (SecurityRequirements) Validate

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

func (*SecurityRequirements) With

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

type SecurityScheme

type SecurityScheme struct {
	ExtensionProps

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

func NewCSRFSecurityScheme

func NewCSRFSecurityScheme() *SecurityScheme

func NewJWTSecurityScheme

func NewJWTSecurityScheme() *SecurityScheme

func NewSecurityScheme

func NewSecurityScheme() *SecurityScheme

func (*SecurityScheme) MarshalJSON

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

func (*SecurityScheme) UnmarshalJSON

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

func (*SecurityScheme) Validate

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

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
}

func (*SecuritySchemeRef) MarshalJSON

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

func (*SecuritySchemeRef) UnmarshalJSON

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

func (*SecuritySchemeRef) Validate

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

type Server

type Server struct {
	URL         string                     `json:"url,omitempty"`
	Description string                     `json:"description,omitempty"`
	Variables   map[string]*ServerVariable `json:"variables,omitempty"`
}

Server is specified by OpenAPI/Swagger standard version 3.0.

func (Server) MatchRawURL

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

func (Server) ParameterNames

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

func (*Server) Validate

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

type ServerVariable

type ServerVariable struct {
	Enum        []interface{} `json:"enum,omitempty"`
	Default     interface{}   `json:"default,omitempty"`
	Description string        `json:"description,omitempty"`
}

ServerVariable is specified by OpenAPI/Swagger standard version 3.0.

func (*ServerVariable) Validate

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

type Servers

type Servers []*Server

Servers is specified by OpenAPI/Swagger standard version 3.0.

func (Servers) MatchURL

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

func (Servers) Validate

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

type Swagger

type Swagger struct {
	ExtensionProps
	OpenAPI      string               `json:"openapi"` // Required
	Info         Info                 `json:"info"`    // Required
	Servers      Servers              `json:"servers,omitempty"`
	Paths        Paths                `json:"paths,omitempty"`
	Components   Components           `json:"components,omitempty"`
	Security     SecurityRequirements `json:"security,omitempty"`
	ExternalDocs *ExternalDocs        `json:"externalDocs,omitempty"`
}

func (*Swagger) AddOperation

func (swagger *Swagger) AddOperation(path string, method string, operation *Operation)

func (*Swagger) AddServer

func (swagger *Swagger) AddServer(server *Server)

func (*Swagger) MarshalJSON

func (swagger *Swagger) MarshalJSON() ([]byte, error)

func (*Swagger) UnmarshalJSON

func (swagger *Swagger) UnmarshalJSON(data []byte) error

func (*Swagger) Validate

func (swagger *Swagger) Validate(c context.Context) error

type SwaggerLoader

type SwaggerLoader struct {
	IsExternalRefsAllowed  bool
	Context                context.Context
	LoadSwaggerFromURIFunc func(loader *SwaggerLoader, url *url.URL) (*Swagger, error)
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"

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

func main() {
	source := `{"info":{"description":"An API"}}`
	swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData([]byte(source))
	if err != nil {
		panic(err)
	}
	fmt.Print(swagger.Info.Description)
}
Output:

An API

func NewSwaggerLoader

func NewSwaggerLoader() *SwaggerLoader

func (*SwaggerLoader) LoadSwaggerFromData

func (swaggerLoader *SwaggerLoader) LoadSwaggerFromData(data []byte) (*Swagger, error)

func (*SwaggerLoader) LoadSwaggerFromFile

func (swaggerLoader *SwaggerLoader) LoadSwaggerFromFile(path string) (*Swagger, error)

func (*SwaggerLoader) LoadSwaggerFromURI

func (swaggerLoader *SwaggerLoader) LoadSwaggerFromURI(location *url.URL) (*Swagger, error)

func (*SwaggerLoader) LoadSwaggerFromYAMLData

func (swaggerLoader *SwaggerLoader) LoadSwaggerFromYAMLData(data []byte) (*Swagger, error)

func (*SwaggerLoader) ResolveRefsIn

func (swaggerLoader *SwaggerLoader) ResolveRefsIn(swagger *Swagger) (err error)

type Tag

type Tag struct {
	Name         string        `json:"name,omitempty"`
	Description  string        `json:"description,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}

Tag is specified by OpenAPI/Swagger 3.0 standard.

type Tags

type Tags []*Tag

Tags is specified by OpenAPI/Swagger 3.0 standard.

func (Tags) Get

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

Jump to

Keyboard shortcuts

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