openapi

package
v0.54.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package openapi represents OpenAPI v3 Specification in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Servers    []Server
	Operations []*Operation
	Webhooks   []Webhook
	Components *Components
}

API represents parsed OpenAPI spec.

type Components

type Components struct {
	Schemas       map[string]*jsonschema.Schema
	Responses     map[string]*Response
	Parameters    map[string]*Parameter
	Examples      map[string]*Example
	RequestBodies map[string]*RequestBody
}

Components represent parsed components of OpenAPI spec.

type Encoding added in v0.33.0

type Encoding struct {
	ContentType   string
	Headers       map[string]*Header
	Style         ParameterStyle
	Explode       bool
	AllowReserved bool

	location.Pointer `json:"-" yaml:"-"`
}

Encoding is Encoding Type Object.

type Example

type Example struct {
	Ref string

	Summary       string
	Description   string
	Value         jsonschema.Example
	ExternalValue string

	location.Pointer `json:"-" yaml:"-"`
}

Example is an OpenAPI Example.

type Header = Parameter

Header is an OpenAPI Header definition.

type MediaType added in v0.31.0

type MediaType struct {
	Schema   *jsonschema.Schema
	Example  json.RawMessage
	Examples map[string]*Example
	Encoding map[string]*Encoding

	location.Pointer `json:"-" yaml:"-"`
}

MediaType is Media Type Object.

type OAuthFlow

type OAuthFlow struct {
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           map[string]string // name -> description

	location.Pointer `json:"-" yaml:"-"`
}

OAuthFlow is configuration details for a supported OAuth Flow.

type OAuthFlows

type OAuthFlows struct {
	Implicit          *OAuthFlow
	Password          *OAuthFlow
	ClientCredentials *OAuthFlow
	AuthorizationCode *OAuthFlow

	location.Pointer `json:"-" yaml:"-"`
}

OAuthFlows allows configuration of the supported OAuth Flows.

type Operation

type Operation struct {
	OperationID string // optional
	Summary     string // optional
	Description string // optional
	Deprecated  bool   // optional

	HTTPMethod  string
	Path        Path
	Parameters  []*Parameter
	RequestBody *RequestBody // optional

	// Security requirements.
	Security []SecurityRequirement

	// Operation responses.
	// Map is always non-nil.
	//
	// Key can be:
	//  * HTTP Status code
	//  * default
	//  * 1XX, 2XX, 3XX, 4XX, 5XX
	Responses map[string]*Response

	location.Pointer `json:"-" yaml:"-"`
}

Operation is an OpenAPI Operation.

type Parameter

type Parameter struct {
	Ref string

	Name          string
	Description   string
	Deprecated    bool
	Schema        *jsonschema.Schema
	Content       *ParameterContent
	In            ParameterLocation
	Style         ParameterStyle
	Explode       bool
	Required      bool
	AllowReserved bool

	location.Pointer `json:"-" yaml:"-"`
}

Parameter is an OpenAPI Operation Parameter.

type ParameterContent added in v0.35.0

type ParameterContent struct {
	Name  string
	Media *MediaType
}

ParameterContent describes OpenAPI Parameter content field.

Parameter "content" field described as a map, and it MUST only contain one entry.

type ParameterLocation

type ParameterLocation string

ParameterLocation defines where OpenAPI parameter is located.

const (
	// LocationQuery is "query" parameter location.
	LocationQuery ParameterLocation = "query"
	// LocationHeader is "header" parameter location.
	LocationHeader ParameterLocation = "header"
	// LocationPath is "path" parameter location.
	LocationPath ParameterLocation = "path"
	// LocationCookie is "cookie" parameter location.
	LocationCookie ParameterLocation = "cookie"
)

func (ParameterLocation) Cookie

func (l ParameterLocation) Cookie() bool

Cookie whether parameter location is cookie.

func (ParameterLocation) Header

func (l ParameterLocation) Header() bool

Header whether parameter location is header.

func (ParameterLocation) Path

func (l ParameterLocation) Path() bool

Path whether parameter location is path.

func (ParameterLocation) Query

func (l ParameterLocation) Query() bool

Query whether parameter location is query.

type ParameterStyle

type ParameterStyle string

ParameterStyle is an OpenAPI Parameter style.

const (
	PathStyleSimple ParameterStyle = "simple"
	PathStyleLabel  ParameterStyle = "label"
	PathStyleMatrix ParameterStyle = "matrix"

	QueryStyleForm           ParameterStyle = "form"
	QueryStyleSpaceDelimited ParameterStyle = "spaceDelimited"
	QueryStylePipeDelimited  ParameterStyle = "pipeDelimited"
	QueryStyleDeepObject     ParameterStyle = "deepObject"

	HeaderStyleSimple ParameterStyle = "simple"

	CookieStyleForm ParameterStyle = "form"
)

https://swagger.io/docs/specification/serialization/

func (ParameterStyle) String

func (s ParameterStyle) String() string

String implements fmt.Stringer.

type Path

type Path []PathPart[*Parameter]

Path is an operation path.

func (Path) ID added in v0.43.1

func (p Path) ID() (path string)

ID returns path, but without parameter names.

For example, if path is "/users/{id}", ID returns "/users/{}".

func (Path) String

func (p Path) String() (path string)

String implements fmt.Stringer.

type PathPart

type PathPart[P any] struct {
	Raw   string
	Param P
}

PathPart is a part of an OpenAPI Operation Path.

func (PathPart[P]) IsParam added in v0.50.0

func (p PathPart[P]) IsParam() bool

IsParam returns true if part is a parameter.

type RequestBody

type RequestBody struct {
	Ref         string
	Description string
	Required    bool
	Content     map[string]*MediaType

	location.Pointer `json:"-" yaml:"-"`
}

RequestBody of an OpenAPI Operation.

type Response

type Response struct {
	Ref         string
	Description string
	Headers     map[string]*Header
	Content     map[string]*MediaType

	location.Pointer `json:"-" yaml:"-"`
}

Response is an OpenAPI Response definition.

type Security

type Security struct {
	Type             string
	Description      string
	Name             string
	In               string
	Scheme           string
	BearerFormat     string
	Flows            OAuthFlows
	OpenIDConnectURL string

	location.Pointer `json:"-" yaml:"-"`
}

Security is parsed security scheme.

type SecurityRequirement added in v0.44.0

type SecurityRequirement struct {
	Scopes   []string
	Name     string
	Security Security
}

SecurityRequirement is parsed security requirements.

type Server added in v0.50.0

type Server struct {
	Name        string // optional,extension
	Description string // optional
	Template    ServerURL
}

Server represents parsed OpenAPI Server Object.

type ServerURL added in v0.50.0

type ServerURL []PathPart[ServerVariable]

ServerURL is URL template with variables.

type ServerVariable added in v0.50.0

type ServerVariable struct {
	Name    string
	Default string
	Enum    []string
}

ServerVariable represents parsed OpenAPI Server Variable Object.

type Version added in v0.53.0

type Version struct {
	// Major is the major version number.
	Major int
	// Minor is the minor version number.
	Minor int
	// Patch is the patch version number.
	Patch int
}

Version represents OpenAPI version.

func (*Version) MarshalText added in v0.53.0

func (v *Version) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Version) String added in v0.53.0

func (v Version) String() string

String returns the string representation of the version.

func (*Version) UnmarshalText added in v0.53.0

func (v *Version) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Webhook added in v0.51.0

type Webhook struct {
	// Name of the webhook.
	Name string
	// Operations of the webhook's Path Item.
	Operations []*Operation

	location.Pointer `json:"-" yaml:"-"`
}

Webhook is an OpenAPI Webhook.

Directories

Path Synopsis
Package parser contains the parser for OpenAPI Spec.
Package parser contains the parser for OpenAPI Spec.

Jump to

Keyboard shortcuts

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