openapiv3

package
v2.2.5+incompatible Latest Latest
Warning

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

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

Documentation

Overview

Package openapiv3 contains the algorithms and data structures used to generate OpenAPI v3 specifications from Goa designs.

Index

Constants

View Source
const OpenAPIVersion = "3.0.3"

OpenAPIVersion is the OpenAPI specification version targeted by this package.

Variables

This section is empty.

Functions

func Files

func Files(root *expr.RootExpr) ([]*codegen.File, error)

Files returns the OpenAPI v3 specification files in JSON and YAML formats.

Types

type CallbackRef

type CallbackRef struct {
	Ref   string
	Value map[string]*PathItem
}

CallbackRef represents an OpenAPI reference to a Callback object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*CallbackRef) MarshalJSON

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

func (*CallbackRef) MarshalYAML

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

func (*CallbackRef) UnmarshalJSON

func (r *CallbackRef) UnmarshalJSON(d []byte) error

func (*CallbackRef) UnmarshalYAML

func (r *CallbackRef) UnmarshalYAML(u func(interface{}) error) error

type Components

type Components struct {
	Schemas         map[string]*openapi.Schema    `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Parameters      map[string]*ParameterRef      `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Headers         map[string]*HeaderRef         `json:"headers,omitempty" yaml:"headers,omitempty"`
	RequestBodies   map[string]*RequestBodyRef    `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	Responses       map[string]*ResponseRef       `json:"responses,omitempty" yaml:"responses,omitempty"`
	SecuritySchemes map[string]*SecuritySchemeRef `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
	Examples        map[string]*ExampleRef        `json:"examples,omitempty" yaml:"examples,omitempty"`
	Links           map[string]*LinkRef           `json:"links,omitempty" yaml:"links,omitempty"`
	Callbacks       map[string]*CallbackRef       `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
	Extensions      map[string]interface{}        `json:"-" yaml:"-"`
}

Components represents an OpenAPI Components object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#componentsObject

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"`
	Extensions map[string]interface{} `json:"-" yaml:"-"`
}

Contact represents an OpenAPI Contact object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#contactObject

type Encoding

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

Encoding represents an OpenAPI Encoding object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#encodingObject

type EndpointBodies

type EndpointBodies struct {
	RequestBody    *openapi.Schema
	ResponseBodies map[int][]*openapi.Schema
}

EndpointBodies describes the request and response HTTP bodies of an endpoint using JSON schema. Each body may be described via a reference to a schema described in the "Components" section of the OpenAPI document or an actual JSON schema data structure. There may also be additional notes attached to each body definition to account for cases that are not directly supported in OpenAPI such as streaming. The possible response bodies are indexed by HTTP status, there may be more than one when the result type defined multiple views.

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 string                 `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
	Extensions    map[string]interface{} `json:"-" yaml:"-"`
}

Example represents an OpenAPI Example object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#exampleObject

type ExampleRef

type ExampleRef struct {
	Ref   string
	Value *Example
}

ExampleRef represents an OpenAPI reference to a Example object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*ExampleRef) MarshalJSON

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

func (*ExampleRef) MarshalYAML

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

func (*ExampleRef) UnmarshalJSON

func (r *ExampleRef) UnmarshalJSON(d []byte) error

func (*ExampleRef) UnmarshalYAML

func (r *ExampleRef) UnmarshalYAML(u func(interface{}) error) error
type Header struct {
	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          *openapi.Schema        `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Examples        map[string]*ExampleRef `json:"examples,omitempty" yaml:"examples,omitempty"`
	Content         map[string]*MediaType  `json:"content,omitempty" yaml:"content,omitempty"`
	Extensions      map[string]interface{} `json:"-" yaml:"-"`
}

Header represents an OpenAPI Header object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#headerObject

type HeaderRef

type HeaderRef struct {
	Ref   string
	Value *Header
}

HeaderRef represents an OpenAPI reference to a Header object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*HeaderRef) MarshalJSON

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

func (*HeaderRef) MarshalYAML

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

func (*HeaderRef) UnmarshalJSON

func (r *HeaderRef) UnmarshalJSON(d []byte) error

func (*HeaderRef) UnmarshalYAML

func (r *HeaderRef) UnmarshalYAML(u func(interface{}) error) error

type Info

type Info struct {
	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
	Extensions     map[string]interface{} `json:"-" yaml:"-"`
}

Info represents an OpenAPI Info object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#infoObject

type License

type License struct {
	Name       string                 `json:"name" yaml:"name"` // Required
	URL        string                 `json:"url,omitempty" yaml:"url,omitempty"`
	Extensions map[string]interface{} `json:"-" yaml:"-"`
}

License represents an OpenAPI License object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#licenseObject

type Link struct {
	OperationID  string                 `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	OperationRef string                 `json:"operationRef,omitempty" yaml:"operationRef,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"`
	Extensions   map[string]interface{} `json:"-" yaml:"-"`
}

Link represents an OpenAPI Link object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#linkObject

type LinkRef

type LinkRef struct {
	Ref   string
	Value *Link
}

LinkRef represents an OpenAPI reference to a Link object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*LinkRef) MarshalJSON

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

func (*LinkRef) MarshalYAML

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

func (*LinkRef) UnmarshalJSON

func (r *LinkRef) UnmarshalJSON(d []byte) error

func (*LinkRef) UnmarshalYAML

func (r *LinkRef) UnmarshalYAML(u func(interface{}) error) error

type MediaType

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

MediaType represents an OpenAPI Media Type object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#mediaTypeObject

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" yaml:"scopes"`
	Extensions       map[string]interface{} `json:"-" yaml:"-"`
}

OAuthFlow represents an OpenAPI OAuthFlow object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#oauthFlowObject

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"`
	Extensions        map[string]interface{} `json:"-" yaml:"-"`
}

OAuthFlows represents an OpenAPI OAuthFlows object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#oauthFlowsObject

type OpenAPI

type OpenAPI struct {
	OpenAPI      string                 `json:"openapi" yaml:"openapi"` // Required
	Info         *Info                  `json:"info" yaml:"info"`       // Required
	Servers      []*Server              `json:"servers,omitempty" yaml:"servers,omitempty"`
	Paths        map[string]*PathItem   `json:"paths" yaml:"paths"` // Required
	Components   *Components            `json:"components,omitempty" yaml:"components,omitempty"`
	Tags         []*openapi.Tag         `json:"tags,omitempty" yaml:"tags,omitempty"`
	Security     []map[string][]string  `json:"security,omitempty" yaml:"security,omitempty"`
	ExternalDocs *openapi.ExternalDocs  `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
	Extensions   map[string]interface{} `json:"-" yaml:"-"`
}

OpenAPI is a data structure that encodes the information needed to generate an OpenAPI specification as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md

func New

func New(root *expr.RootExpr) *OpenAPI

New returns the OpenAPI v3 specification for the given API. It returns nil if the design does not define HTTP endpoints.

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"`
	OperationID  string                  `json:"operationId,omitempty" yaml:"operationId,omitempty"`
	Parameters   []*ParameterRef         `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	RequestBody  *RequestBodyRef         `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Responses    map[string]*ResponseRef `json:"responses" yaml:"responses"` // Required
	Callbacks    map[string]*CallbackRef `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
	Deprecated   bool                    `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Security     []map[string][]string   `json:"security,omitempty" yaml:"security,omitempty"`
	Servers      []*Server               `json:"servers,omitempty" yaml:"servers,omitempty"`
	ExternalDocs *openapi.ExternalDocs   `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
	Extensions   map[string]interface{}  `json:"-" yaml:"-"`
}

Operation represents an OpenAPI Operation object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#operationObject

type Parameter

type Parameter struct {
	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          *openapi.Schema        `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         interface{}            `json:"example,omitempty" yaml:"example,omitempty"`
	Examples        map[string]*ExampleRef `json:"examples,omitempty" yaml:"examples,omitempty"`
	Content         map[string]*MediaType  `json:"content,omitempty" yaml:"content,omitempty"`
	Extensions      map[string]interface{} `json:"-" yaml:"-"`
}

Parameter represents an OpenAPI Parameter object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#parameterObject

type ParameterRef

type ParameterRef struct {
	Ref   string
	Value *Parameter
}

ParameterRef represents an OpenAPI reference to a Parameter object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*ParameterRef) MarshalJSON

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

func (*ParameterRef) MarshalYAML

func (r *ParameterRef) MarshalYAML() (interface{}, error)

func (*ParameterRef) UnmarshalJSON

func (r *ParameterRef) UnmarshalJSON(d []byte) error

func (*ParameterRef) UnmarshalYAML

func (r *ParameterRef) UnmarshalYAML(u func(interface{}) error) error

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"`
	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     []*Server              `json:"servers,omitempty" yaml:"servers,omitempty"`
	Parameters  []*ParameterRef        `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Extensions  map[string]interface{} `json:"-" yaml:"-"`
}

PathItem represents an OpenAPI Path Item object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#pathItemObject

type RequestBody

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

RequestBody represents an OpenAPI RequestBody object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#requestBodyObject

type RequestBodyRef

type RequestBodyRef struct {
	Ref   string
	Value *RequestBody
}

RequestBodyRef represents an OpenAPI reference to a RequestBody object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*RequestBodyRef) MarshalJSON

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

func (*RequestBodyRef) MarshalYAML

func (r *RequestBodyRef) MarshalYAML() (interface{}, error)

func (*RequestBodyRef) UnmarshalJSON

func (r *RequestBodyRef) UnmarshalJSON(d []byte) error

func (*RequestBodyRef) UnmarshalYAML

func (r *RequestBodyRef) UnmarshalYAML(u func(interface{}) error) error

type Response

type Response struct {
	Description *string                `json:"description,omitempty" yaml:"description,omitempty"`
	Headers     map[string]*HeaderRef  `json:"headers,omitempty" yaml:"headers,omitempty"`
	Content     map[string]*MediaType  `json:"content,omitempty" yaml:"content,omitempty"`
	Links       map[string]*LinkRef    `json:"links,omitempty" yaml:"links,omitempty"`
	Extensions  map[string]interface{} `json:"-" yaml:"-"`
}

Response represents an OpenAPI Response object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#responseObject

type ResponseRef

type ResponseRef struct {
	Ref   string
	Value *Response
}

ResponseRef represents an OpenAPI reference to a Response object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*ResponseRef) MarshalJSON

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

func (*ResponseRef) MarshalYAML

func (r *ResponseRef) MarshalYAML() (interface{}, error)

func (*ResponseRef) UnmarshalJSON

func (r *ResponseRef) UnmarshalJSON(d []byte) error

func (*ResponseRef) UnmarshalYAML

func (r *ResponseRef) UnmarshalYAML(u func(interface{}) error) error

type SecurityScheme

type SecurityScheme struct {
	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"`
	Extensions   map[string]interface{} `json:"-" yaml:"-"`
}

SecurityScheme represents an OpenAPI SecurityScheme object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#securitySchemeObject

type SecuritySchemeRef

type SecuritySchemeRef struct {
	Ref   string
	Value *SecurityScheme
}

SecuritySchemeRef represents an OpenAPI reference to a SecurityScheme object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject

func (*SecuritySchemeRef) MarshalJSON

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

func (*SecuritySchemeRef) MarshalYAML

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

func (*SecuritySchemeRef) UnmarshalJSON

func (r *SecuritySchemeRef) UnmarshalJSON(d []byte) error

func (*SecuritySchemeRef) UnmarshalYAML

func (r *SecuritySchemeRef) UnmarshalYAML(u func(interface{}) error) error

type Server

type Server struct {
	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 represents an OpenAPI Server object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#serverObject

type ServerVariable

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

ServerVariable represents an OpenAPI Server Variable object as defined in https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#serverVariableObject

Jump to

Keyboard shortcuts

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