openapi

package module
v0.0.0-...-37cd533 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 14 Imported by: 0

README

OpenAPI Specification object model

GoDoc Build Status codecov


This is a fork of https://github.com/nasa9084/go-openapi. It was changed to add support for:

  • JSON marshalling.
  • Omitting empty fields.

This package is still under development, so the API will be changed without any notification

Overview

This is an implementation of OpenAPI Specification 3.0 object model with some usable functions.

Synopsis

package main

import (
    "fmt"

    "github.com/bentranter/go-openapi"
)

func main() {
    doc, _ := openapi.LoadFile("path/to/spec")
    fmt.Print(doc.Version)
}

Status

  • Model definition
  • Load OpenAPI 3.0 spec file
  • Resolve Reference object
    • Resolve #/component reference
    • Resolve other file reference
  • Validation
    • Validate spec values
      • test for validation
        • Document
        • Info
        • Contact
        • License
        • Server
        • ServerVariable
        • Paths
        • PathItem
        • Operation
        • Parameter
        • RequestBody
        • Responses
        • Response
        • Callbacks
        • Callback
        • Schema
        • Example
        • MediaType
        • Header
        • Link
        • Encoding
        • Discriminator
        • XML
        • Components
        • SecurityScheme
        • OAuthFlows
        • OAuthFlow
        • SecurityRequirement
        • Tag
        • ExternalDocumentation
    • Validate HTTP Request
    • Validate HTTP Response

Documentation

Index

Constants

View Source
const (
	// ErrUnsupportedVersion is returned when the openapi version
	// is unsupported by this package.
	ErrUnsupportedVersion errString = "the OAS version is not supported"
	// ErrInvalidFlowType is returned when the OAuth flow type is invalid
	// or not set to the object.
	ErrInvalidFlowType errString = "invalid flow type"
	// ErrRequiredMustTrue is returned when the value of parameter.required is
	// false when parameter.in is path.
	ErrRequiredMustTrue errString = "required must be true if parameter.in is path"
	// ErrAllowEmptyValueNotValid is returned when allowEmptyValue is specified
	// but parameter.in is not query.
	ErrAllowEmptyValueNotValid errString = "allowEmptyValue is valid only for query parameters"
	// ErrInvalidStatusCode is returned when specified status code is not
	// valid as HTTP status code.
	ErrInvalidStatusCode errString = "status code is invalid"
	// ErrMissingRootDocument is returned when validating securityRequirement
	// object but root document is not set.
	ErrMissingRootDocument errString = "missing root document for security requirement"
)

Variables

View Source
var (
	ErrMapKeyFormat      = ErrFormatInvalid{Target: "map key"}
	ErrPathFormat        = ErrFormatInvalid{Target: "path"}
	ErrRuntimeExprFormat = ErrFormatInvalid{Target: "key", Format: "RuntimeExpression"}
)

central error variables relating format

View Source
var (
	// ErrTooManyHeaderContent is returned when the length of header.content
	// is more than 2.
	ErrTooManyHeaderContent = errTooManyContentEntry{/* contains filtered or unexported fields */}
	// ErrTooManyParameterContent is returned when the length of parameter.content
	// is more than 2.
	ErrTooManyParameterContent = errTooManyContentEntry{/* contains filtered or unexported fields */}
)
View Source
var (
	// ErrOperationIDDuplicated is returned when some operation ids are
	// duplicated but operation ids cannot be duplicated.
	ErrOperationIDDuplicated = errDuplicated{/* contains filtered or unexported fields */}
	// ErrParameterDuplicated is returned when some parameters are duplicated
	// but cannot be duplicated.
	ErrParameterDuplicated = errDuplicated{/* contains filtered or unexported fields */}
	// ErrPathsDuplicated is returned when some paths are duplicated.
	ErrPathsDuplicated = errDuplicated{/* contains filtered or unexported fields */}
)
View Source
var (
	ParameterInList      = []string{string(InQuery), string(InHeader), string(InPath), string(InCookie)}
	SecuritySchemeInList = []string{string(InQuery), string(InHeader), string(InCookie)}
)

InType Lists for ErrOneOf

View Source
var ErrTypeAssertion = errors.New("type assertion error")

ErrTypeAssertion is raised when the type assertion error is occurred.

SecuritySchemeTypeList is a list of valid values of securityScheme.Type.

Functions

This section is empty.

Types

type Callback

type Callback map[string]*PathItem

Callback Object

func ResolveCallback

func ResolveCallback(root *Document, ref string) (*Callback, error)

ResolveCallback resolves a callback reference string.

func (Callback) Validate

func (callback Callback) Validate() error

Validate the values of Callback object.

type Components

type Components struct {
	Schemas         map[string]*Schema         `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Responses       map[string]*Response       `json:"responses,omitempty" yaml:"responses,omitempty"`
	Parameters      map[string]*Parameter      `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Examples        map[string]*Example        `json:"examples,omitempty" yaml:"examples,omitempty"`
	RequestBodies   map[string]*RequestBody    `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty" `
	Headers         map[string]*Header         `json:"headers,omitempty" yaml:"headers,omitempty"`
	SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty" `
	Links           map[string]*Link           `json:"links,omitempty" yaml:"links,omitempty"`
	Callbacks       map[string]*Callback       `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
}

Components Object

func (Components) Validate

func (components Components) Validate() error

Validate the values of Components object.

type Contact

type Contact struct {
	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 Object

func (Contact) Validate

func (contact Contact) Validate() error

Validate the values of Contact object.

type Discriminator

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

Discriminator Object

func (Discriminator) Validate

func (discriminator Discriminator) Validate() error

Validate the values of Descriminator object.

type Document

type Document struct {
	Version      string                 `json:"openapi" yaml:"openapi"`
	Info         *Info                  `json:"info,omitempty" yaml:"info,omitempty"`
	Servers      []*Server              `json:"servers,omitempty" yaml:"servers,omitempty"`
	Paths        Paths                  `json:"paths,omitempty" yaml:"paths,omitempty"`
	Components   *Components            `json:"components,omitempty" yaml:"components,omitempty"`
	Security     []*SecurityRequirement `json:"security,omitempty" yaml:"security,omitempty"`
	Tags         []*Tag                 `json:"tags,omitempty" yaml:"tags,omitempty"`
	ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}

Document represents a OpenAPI Specification document.

func Load

func Load(b []byte) (*Document, error)

Load OpenAPI Specification v3.0 spec.

func LoadFile

func LoadFile(filename string) (*Document, error)

LoadFile OpenAPI Specification v3.0 spec file.

func (Document) Validate

func (doc Document) Validate() error

Validate the values of spec.

func (*Document) Walk

func (doc *Document) Walk(walkFn WalkFunc) error

type Encoding

type Encoding struct {
	ContentType   string             `json:"contentType,omitempty" yaml:"contentType,omitempty"`
	Headers       map[string]*Header `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 Object

func (Encoding) Validate

func (encoding Encoding) Validate() error

Validate the values of Encoding object.

type ErrFormatInvalid

type ErrFormatInvalid struct {
	Target string
	Format string
}

ErrFormatInvalid is returned some error caused by string format is occurred.

func (ErrFormatInvalid) Error

func (fe ErrFormatInvalid) Error() string

type ErrMustEmpty

type ErrMustEmpty struct {
	Type string
}

ErrMustEmpty returned when the securityRequirement is not empty but must be empty.

func (ErrMustEmpty) Error

func (srmee ErrMustEmpty) Error() string

type ErrMustOneOf

type ErrMustOneOf struct {
	Object      string
	ValidValues []string
}

ErrMustOneOf is returned some value must be one of given list, but not one.

func (ErrMustOneOf) Error

func (ooe ErrMustOneOf) Error() string

type ErrNotDeclared

type ErrNotDeclared struct {
	Name string
}

ErrNotDeclared is returned when the securityScheme name is not defined in components object in the document.

func (ErrNotDeclared) Error

func (snde ErrNotDeclared) Error() string

type ErrRequired

type ErrRequired struct {
	Target string
}

ErrRequired is returned when missing some required parameter

func (ErrRequired) Error

func (re ErrRequired) Error() string

type Example

type Example struct {
	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 interface{} `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

Example Object

func ResolveExample

func ResolveExample(root *Document, ref string) (*Example, error)

ResolveExample resolves an example reference string.

type ExternalDocumentation

type ExternalDocumentation struct {
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	URL         string `json:"url,omitempty" yaml:"url,omitempty"`
}

ExternalDocumentation Object

func (ExternalDocumentation) Validate

func (externalDocumentation ExternalDocumentation) Validate() error

Validate the values of ExternalDocumentaion object.

type Header struct {
	Description     string `json:"description" yaml:"description"`
	Required        bool   `json:"required,omitempty" yaml:"required,omitempty"`
	Deprecated      string `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	AllowEmptyValue bool   `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,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"`
	Schema        *Schema             `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example       interface{}         `json:"example,omitempty" yaml:"example,omitempty"`
	Examples      map[string]*Example `json:"examples,omitempty" yaml:"examples,omitempty"`

	Content map[string]*MediaType `json:"content,omitempty" yaml:"content,omitempty"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

Header Object

func ResolveHeader

func ResolveHeader(root *Document, ref string) (*Header, error)

ResolveHeader resolves a header reference string.

func (Header) Validate

func (header Header) Validate() error

Validate the values of Header object.

type InType

type InType string

InType represents where the parameter or the securityScheme is in.

const (
	InQuery  InType = "query"
	InHeader InType = "header"
	InPath   InType = "path"
	InCookie InType = "cookie"
)

InTypes

type Info

type Info struct {
	Title          string   `json:"title,omitempty" yaml:"title,omitempty"`
	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,omitempty" yaml:"version,omitempty"`
}

Info Object

func (Info) Validate

func (info Info) Validate() error

Validate the values of Info object.

type License

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

License Object

func (License) Validate

func (license License) Validate() error

Validate the values of License object.

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

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

Link Object

func ResolveLink(root *Document, ref string) (*Link, error)

ResolveLink resolves a link reference string.

func (Link) Validate

func (link Link) Validate() error

Validate the values of Link object.

type MediaType

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

MediaType Object

func (MediaType) Validate

func (mediaType MediaType) Validate() error

Validate the values of MediaType object. This function DOES NOT check whether the encoding object is in schema or not.

type OAuthFlow

type OAuthFlow struct {
	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,omitempty" yaml:"scopes,omitempty"`
	// contains filtered or unexported fields
}

OAuthFlow Object

func (*OAuthFlow) SetFlowType

func (oauthFlow *OAuthFlow) SetFlowType(typ string)

SetFlowType sets oauth flow type.

func (OAuthFlow) Validate

func (oauthFlow OAuthFlow) Validate() error

Validate the values of OAuthFlow object.

type OAuthFlows

type OAuthFlows struct {
	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 Object

func (OAuthFlows) Validate

func (oauthFlows OAuthFlows) Validate() error

Validate the values of OAuthFlows Object.

type Operation

type Operation struct {
	Tags         []string               `json:"tags,omitempty" yaml:"tags,omitempty"`
	Summary      string                 `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description  string                 `json:"description,omitempty" yaml:"description,omitempty"`
	ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
	OperationID  string                 `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Parameters   []*Parameter           `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody  *RequestBody           `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses    Responses              `json:"responses,omitempty" yaml:"responses,omitempty"`
	Callbacks    map[string]*Callback   `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
	Deprecated   bool                   `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Security     []*SecurityRequirement `json:"security,omitempty" yaml:"security,omitempty"`
	Servers      []*Server              `json:"servers,omitempty" yaml:"servers,omitempty"`
}

Operation Object

func (*Operation) SuccessResponse

func (operation *Operation) SuccessResponse() (*Response, int, bool)

SuccessResponse returns a success response object. If there are 2 or more success responses (like created and ok), it's not sure which is returned. If only match the default response or 2XX response, returned status code will be 0.

func (Operation) Validate

func (operation Operation) Validate() error

Validate the values of Operation object.

type Parameter

type Parameter struct {
	Name            string `json:"name,omitempty" yaml:"name,omitempty"`
	In              InType `json:"in,omitempty" yaml:"in,omitempty"`
	Description     string `json:"description,omitempty" yaml:"description,omitempty"`
	Required        bool   `json:"required,omitempty" yaml:"required,omitempty"`
	Deprecated      string `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	AllowEmptyValue bool   `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,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"`
	Schema        *Schema             `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example       interface{}         `json:"example,omitempty" yaml:"example,omitempty"`
	Examples      map[string]*Example `json:"examples,omitempty" yaml:"examples,omitempty"`

	Content map[string]*MediaType `json:"content,omitempty" yaml:"content,omitempty"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

Parameter Object

func ResolveParameter

func ResolveParameter(root *Document, ref string) (*Parameter, error)

ResolveParameter resolves a response reference string.

func (Parameter) Validate

func (parameter Parameter) Validate() error

Validate the values of Parameter object. This function DOES NOT check whether the name field correspond to the associated path or not.

type PathItem

type PathItem struct {
	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`

	Summary     string       `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string       `json:"description,omitempty" yaml:"description,omitempty"`
	Get         *Operation   `json:"get,omitempty" yaml:"get,omitempty"`
	Put         *Operation   `json:"put,omitempty" yaml:"put,omitempty"`
	Post        *Operation   `json:"post,omitempty" yaml:"post,omitempty"`
	Delete      *Operation   `json:"delete,omitempty" yaml:"delete,omitempty"`
	Options     *Operation   `json:"options,omitempty" yaml:"options,omitempty"`
	Head        *Operation   `json:"head,omitempty" yaml:"head,omitempty"`
	Patch       *Operation   `json:"patch,omitempty" yaml:"patch,omitempty"`
	Trace       *Operation   `json:"trace,omitempty" yaml:"trace,omitempty"`
	Servers     []*Server    `json:"servers,omitempty" yaml:"servers,omitempty"`
	Parameters  []*Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

PathItem Object

func (PathItem) GetOperationByID

func (pathItem PathItem) GetOperationByID(operationID string) *Operation

GetOperationByID returns an operation object which matches given operationId. If the pathItem object has duplicated operationId, this function returns one which match first.

func (*PathItem) GetOperationByMethod

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

GetOperationByMethod returns a operation object associated with given method. The method is case-insensitive, converted to upper case in this function. If the method is invalid, this function will return nil.

func (PathItem) Operations

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

Operations returns a map containing operation object as a value associated with a HTTP method as a key. If an operation is nil, it won't be added returned map, so the size of returned map is not same always.

func (PathItem) Validate

func (pathItem PathItem) Validate() error

Validate the values of PathItem object.

type Paths

type Paths map[string]*PathItem

Paths Object

func (Paths) GetOperationByID

func (paths Paths) GetOperationByID(operationID string) *Operation

GetOperationByID returns an operation by operationId. If the paths object has two or more operations which matches given operationId, this function returns the operation matched first. So you should call Validate() before using this function.

func (Paths) Validate

func (paths Paths) Validate() error

Validate the values of Paths object.

type RequestBody

type RequestBody struct {
	Description string                `json:"description,omitempty" yaml:"description,omitempty"`
	Content     map[string]*MediaType `json:"content,omitempty" yaml:"content,omitempty"`
	Required    bool                  `json:"required,omitempty" yaml:"required,omitempty"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

RequestBody Object

func ResolveRequestBody

func ResolveRequestBody(root *Document, ref string) (*RequestBody, error)

ResolveRequestBody resolves a requestBody reference string.

func (RequestBody) Validate

func (requestBody RequestBody) Validate() error

Validate the values of RequestBody object.

type Response

type Response struct {
	Description string                `json:"description,omitempty" yaml:"description,omitempty"`
	Headers     map[string]*Header    `json:"headers,omitempty" yaml:"headers,omitempty"`
	Content     map[string]*MediaType `json:"content,omitempty" yaml:"content,omitempty"`
	Links       map[string]*Link      `json:"links,omitempty" yaml:"links,omitempty"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

Response Object

func ResolveResponse

func ResolveResponse(root *Document, ref string) (*Response, error)

ResolveResponse resolves a response reference string.

func (Response) Validate

func (response Response) Validate() error

Validate the value of Response object.

type Responses

type Responses map[string]*Response

Responses Object

func (Responses) Validate

func (responses Responses) Validate() error

Validate the values of Responses object.

type Schema

type Schema struct {
	Title            string   `json:"title,omitempty" yaml:"title,omitempty"`
	MultipleOf       int      `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
	Maximum          int      `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	ExclusiveMaximum bool     `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	Minimum          int      `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	ExclusiveMinimum bool     `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
	MaxLength        int      `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	MinLength        int      `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	Pattern          string   `json:"pattern,omitempty" yaml:"pattern,omitempty"`
	MaxItems         int      `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	MinItems         int      `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxProperties    int      `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
	MinProperties    int      `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	Required         []string `json:"required,omitempty" yaml:"required,omitempty"`
	Enum             []string `json:"enum,omitempty" yaml:"enum,omitempty"`

	Type                 string             `json:"type,omitempty" yaml:"type,omitempty"`
	AllOf                []*Schema          `json:"allOf,omitempty" yaml:"allOf,omitempty"`
	OneOf                []*Schema          `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
	AnyOf                []*Schema          `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
	Not                  *Schema            `json:"not,omitempty" yaml:"not,omitempty"`
	Items                *Schema            `json:"items,omitempty" yaml:"items,omitempty"`
	Properties           map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	AdditionalProperties *Schema            `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
	Description          string             `json:"description,omitempty" yaml:"description,omitempty"`
	Format               string             `json:"format,omitempty" yaml:"format,omitempty"`
	Default              string             `json:"default,omitempty" yaml:"default,omitempty"`

	Nullable      bool                   `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	Discriminator *Discriminator         `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`
	ReadOnly      bool                   `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	WriteOnly     bool                   `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	XML           *XML                   `json:"xml,omitempty" yaml:"xml,omitempty"`
	ExternalDocs  *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
	Example       interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Deprecated    bool                   `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`

	Extension map[string]interface{} `json:"extension,omitempty" yaml:",inline"`
}

Schema Object

func ResolveSchema

func ResolveSchema(root *Document, ref string) (*Schema, error)

ResolveSchema resolves a schema reference string.

func (Schema) Validate

func (schema Schema) Validate() error

Validate the values of Schema object.

type SecurityRequirement

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

SecurityRequirement Object

func (SecurityRequirement) Get

func (secReq SecurityRequirement) Get(name string) []string

Get returns required security schemes. If there is not given name, this function returns nil.

func (SecurityRequirement) Names

func (secReq SecurityRequirement) Names() []string

Names returns the keys of security requirements. The returned slice is sorted.

func (*SecurityRequirement) UnmarshalJSON

func (secReq *SecurityRequirement) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*SecurityRequirement) UnmarshalYAML

func (secReq *SecurityRequirement) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

func (SecurityRequirement) Validate

func (secReq SecurityRequirement) Validate() error

Validate the values of SecurityRequirement object.

type SecurityScheme

type SecurityScheme struct {
	Type             SecuritySchemeType `json:"type,omitempty" yaml:"type,omitempty"`
	Description      string             `json:"description,omitempty" yaml:"description,omitempty"`
	Name             string             `json:"name,omitempty" yaml:"name,omitempty"`
	In               InType             `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"`

	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

SecurityScheme Object

func ResolveSecurityScheme

func ResolveSecurityScheme(root *Document, ref string) (*SecurityScheme, error)

ResolveSecurityScheme resolves a securityScheme reference string.

func (SecurityScheme) Validate

func (secScheme SecurityScheme) Validate() error

Validate the values of SecurityScheme object.

type SecuritySchemeType

type SecuritySchemeType string

SecuritySchemeType represents a securityScheme.type value.

const (
	APIKeyType        SecuritySchemeType = "apiKey"
	HTTPType          SecuritySchemeType = "http"
	OAuth2Type        SecuritySchemeType = "oauth2"
	OpenIDConnectType SecuritySchemeType = "openIdConnect"
)

SecuritySchemeTypes

type Server

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

Server Object

func (Server) Validate

func (server Server) Validate() error

Validate the values of Server object.

type ServerVariable

type ServerVariable struct {
	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 Object

func (ServerVariable) Validate

func (sv ServerVariable) Validate() error

Validate the values of Server Variable object.

type Tag

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

Tag Object

func (Tag) Validate

func (tag Tag) Validate() error

Validate the values of Tag object.

type WalkFunc

type WalkFunc func(doc *Document, method, path string, pathItem *PathItem, op *Operation) error

type XML

type XML struct {
	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 Object

func (XML) Validate

func (xml XML) Validate() error

Validate the values of XML object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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