specification

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSecurity added in v0.0.12

func GetSecurity(secSchemes openapi3.SecuritySchemes, secRequirements openapi3.SecurityRequirements) ([][]Security, error)

Types

type Components added in v0.0.11

type Components struct {
	Schemas   ComponentsSchemas
	Responses Map[Ref[Response]]

	// ---------------- Parameters ----------------
	QueryParameters  Map[Ref[QueryParameter]]
	HeaderParameters Map[Ref[HeaderParameter]]
	PathParameters   Map[Ref[PathParameter]]
	CookieParameters Map[Ref[CookieParameter]]

	RequestBodies   Map[Ref[RequestBody]]
	Headers         Map[Ref[Header]]
	SecuritySchemes SecuritySchemes
	Links           Map[Ref[Link]]
	PathItems       Map[Ref[PathItem]]
}

func NewComponents added in v0.0.11

func NewComponents(spec openapi3.Components) Components

type ComponentsSchemas added in v0.0.14

type ComponentsSchemas = Map[Ref[Schema]]

type Contact added in v0.0.14

type Contact struct {
	Name  string
	URL   string
	Email string
}

func NewContact added in v0.0.14

func NewContact(c *openapi3.Contact) Contact

type CookieParameter added in v0.0.14

type CookieParameter struct {
	NoRef[CookieParameter]

	Name        string
	Description string
	Required    bool
	Deprecated  bool

	Style   string
	Explode Optional[bool]

	Schema Ref[Schema]
}

func NewCookieParameter added in v0.0.14

func NewCookieParameter(p *openapi3.Parameter, schemas ComponentsSchemas) *CookieParameter

func (*CookieParameter) Value added in v0.0.14

func (c *CookieParameter) Value() *CookieParameter

type HTTPMethod added in v0.0.14

type HTTPMethod string

HTTPMethod - http.MethodGet, http.MethodPost, ...

type HTTPMethodTitle added in v0.0.14

type HTTPMethodTitle string

HTTPMethodTitle - Get, Post, ...

type Header struct {
	NoRef[Header]

	Description string
	Required    bool
	Deprecated  bool

	Schema Ref[Schema]
}

func NewHeader

func NewHeader(s *openapi3.Header, schemas ComponentsSchemas) *Header

func (*Header) Value added in v0.0.14

func (h *Header) Value() *Header

type HeaderOld added in v0.0.14

type HeaderOld struct {
	Spec *openapi3.Header
	Ref  string

	Name      string
	SchemaRef *openapi3.SchemaRef

	Description string
	Required    bool
	Deprecated  bool
}

func Headers

func Headers(hs openapi3.Headers) (out []HeaderOld)

func NewHeaderOld added in v0.0.14

func NewHeaderOld(name string, h *openapi3.HeaderRef) HeaderOld

type HeaderParameter

type HeaderParameter struct {
	NoRef[HeaderParameter]

	Name        string
	Description string
	Required    bool
	Deprecated  bool

	Style   string
	Explode Optional[bool]

	Schema Ref[Schema]
}

func NewHeaderParameter added in v0.0.14

func NewHeaderParameter(p *openapi3.Parameter, schemas ComponentsSchemas) *HeaderParameter

func (*HeaderParameter) Value added in v0.0.14

func (h *HeaderParameter) Value() *HeaderParameter

type HeaderParameterOld added in v0.0.14

type HeaderParameterOld struct {
	RefName     string
	Name        string
	Description string
	Required    bool
	Schema      Ref[Schema]
}

type Info added in v0.0.10

type Info struct {
	Title          string
	Summary        string
	Description    string
	TermsOfService string
	Contact        Contact
	License        License
	Version        string
}

func NewInfo added in v0.0.10

func NewInfo(s *openapi3.Info) Info

type License added in v0.0.14

type License struct {
	Name       string
	Identifier string
	URL        string
}

func NewLicense added in v0.0.14

func NewLicense(l *openapi3.License) License
type Link struct {
	NoRef[Link]
}
func NewLink(s *openapi3.Link) *Link

func (*Link) Value added in v0.0.14

func (l *Link) Value() *Link

type Map added in v0.0.14

type Map[T any] struct {
	List []*Object[T]
	// contains filtered or unexported fields
}

func NewMap added in v0.0.14

func NewMap[T any, U any](m map[string]U, fn func(U) T) Map[T]

func NewMapEmpty added in v0.0.14

func NewMapEmpty[T any](size int) Map[T]

func NewMapPrefix added in v0.0.14

func NewMapPrefix[T any, U any](m map[string]U, fn func(U) T, prefix RefKey) Map[T]

func NewMapRefSelf added in v0.0.14

func NewMapRefSelf[T any, U any](m map[string]U, fn func(U) (ref string, _ Ref[T]), prefix RefKey) Map[Ref[T]]

func NewMapRefSelfSource added in v0.0.14

func NewMapRefSelfSource[T any, U any](m map[string]U, fn func(U, Map[Ref[T]]) (ref string, _ Ref[T]), source interface {
	Get(string) (*Object[Ref[T]], bool)
}, prefix RefKey) Map[Ref[T]]

func NewMapRefSource added in v0.0.14

func NewMapRefSource[T any, U any](m map[string]U, fn func(U) (ref string, _ Ref[T]), source interface {
	Get(string) (*Object[Ref[T]], bool)
}, prefix RefKey) Map[Ref[T]]

func (*Map[T]) Add added in v0.0.14

func (m *Map[T]) Add(name string, v T)

func (Map[T]) Get added in v0.0.14

func (m Map[T]) Get(k string) (*Object[T], bool)

func (*Map[T]) Has added in v0.0.14

func (m *Map[T]) Has(k string) bool

type MediaType added in v0.0.14

type MediaType struct {
	Schema Ref[Schema]
}

func NewMediaType added in v0.0.14

func NewMediaType(s *openapi3.MediaType, components ComponentsSchemas) *MediaType

type NoRef added in v0.0.14

type NoRef[T any] struct{}

func (NoRef[T]) Ref added in v0.0.14

func (NoRef[T]) Ref() *Object[Ref[T]]

type OAuthFlow added in v0.0.14

type OAuthFlow struct {
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           Map[string]
}

func NewOAuthFlow added in v0.0.14

func NewOAuthFlow(s *openapi3.OAuthFlow) OAuthFlow

type OAuthFlows added in v0.0.14

type OAuthFlows struct {
	Implicit          Optional[OAuthFlow]
	Password          Optional[OAuthFlow]
	ClientCredentials Optional[OAuthFlow]
	AuthorizationCode Optional[OAuthFlow]
}

func NewOAuthFlows added in v0.0.14

func NewOAuthFlows(s *openapi3.OAuthFlows) OAuthFlows

type Object added in v0.0.14

type Object[T any] struct {
	Name string
	V    T
}

type Operation

type Operation struct {
	PathItem *PathItem

	Path Path

	Tags        []string
	Summary     string
	Description string
	OperationID string

	Parameters OperationParameters

	RequestBody Optional[Ref[RequestBody]]

	HTTPMethod HTTPMethod
	Method     HTTPMethodTitle

	Operation *openapi3.Operation

	Security SecurityRequirements

	DefaultResponse *ResponseOld
	Responses       []*ResponseOld
}

func NewOperation

func NewOperation(pi *PathItem, rawPath string, method httpMethod, operation *openapi3.Operation, specSecurityReqs SecurityRequirements, legacyComponents openapi3.Components, securitySchemes SecuritySchemes, components Components) (*Operation, error)

type OperationParameters added in v0.0.14

type OperationParameters struct {
	Query   Map[Ref[QueryParameter]]
	Headers Map[Ref[HeaderParameter]]
	Path    Map[Ref[PathParameter]]
	Cookie  Map[Ref[CookieParameter]]
}

func NewOperationParameters added in v0.0.14

func NewOperationParameters(pathParams, operationParams openapi3.Parameters, components Components) OperationParameters

type Optional added in v0.0.14

type Optional[T any] struct {
	IsSet bool
	Value T
}

func NewOptional added in v0.0.14

func NewOptional[T any](v T) Optional[T]

func NewOptionalEmpty added in v0.0.14

func NewOptionalEmpty[T any]() Optional[T]

func NewOptionalPtr added in v0.0.14

func NewOptionalPtr[T any](v *T) Optional[T]

type Path

type Path struct {
	Raw  string
	Dirs []*PathDir
	Refs Map[*PathDir]
}

func NewPath

func NewPath(raw string) Path

type PathDir

type PathDir struct {
	V          string
	IsVariable bool
	Param      Ref[PathParameter]
}

type PathDirOld added in v0.0.14

type PathDirOld struct {
	Raw      Prefix
	ParamRef *PathParameterOld
}

type PathItem

type PathItem struct {
	NoRef[PathItem]

	RawPath    string // TODO
	Operations []*Operation

	// Deprecated // TODO
	Path     PathOld2
	PathOld  PathOld
	PathItem *openapi3.PathItem
}

func NewPathItem added in v0.0.14

func NewPathItem(path string) *PathItem

type PathOld

type PathOld string

PathOld always starts with '/'

func NewPathOld

func NewPathOld(s string) (PathOld, error)

func (PathOld) Cut

func (p PathOld) Cut() (Prefix, PathOld, bool)

func (PathOld) Name

func (p PathOld) Name(fn func(Prefix) string, sep string) string

func (PathOld) String

func (p PathOld) String() string

type PathOld2 added in v0.0.14

type PathOld2 struct {
	Spec   string
	Dirs   []*PathDirOld
	Params PathParameters
}

func NewPathOld2 added in v0.0.14

func NewPathOld2(s string) (zero PathOld2, _ error)

type PathParameter

type PathParameter struct {
	NoRef[PathParameter]

	Name        string
	Description string
	Deprecated  bool

	Style   string
	Explode Optional[bool]

	Schema Ref[Schema]
}

func NewPathParameter added in v0.0.14

func NewPathParameter(p *openapi3.Parameter, schemas ComponentsSchemas) *PathParameter

func (*PathParameter) Value added in v0.0.14

func (p *PathParameter) Value() *PathParameter

type PathParameterOld added in v0.0.14

type PathParameterOld struct {
	RefName     string
	Name        string
	Description string
	Schema      Ref[Schema]
}

type PathParameters

type PathParameters []*PathParameterOld

func (PathParameters) Get

func (ps PathParameters) Get(name string) (*PathParameterOld, bool)

type Prefix

type Prefix string

Prefix always starts with '/'

func (Prefix) IsVariable

func (p Prefix) IsVariable() bool

func (Prefix) Name

func (p Prefix) Name() string

type QueryParameter

type QueryParameter struct {
	NoRef[QueryParameter]

	Name            string
	Description     string
	Required        bool
	Deprecated      bool
	AllowEmptyValue bool

	Style         string
	Explode       Optional[bool]
	AllowReserved bool

	Schema Ref[Schema]
}

func NewQueryParameter added in v0.0.14

func NewQueryParameter(p *openapi3.Parameter, schemas ComponentsSchemas) *QueryParameter

func (*QueryParameter) Value added in v0.0.14

func (q *QueryParameter) Value() *QueryParameter

type QueryParameterOld added in v0.0.14

type QueryParameterOld struct {
	RefName     string
	Name        string
	Description string
	Required    bool
	Schema      Ref[Schema]
}

type Ref added in v0.0.14

type Ref[T any] interface {
	Ref() *Object[Ref[T]]
	Value() *T
}

func NewRefCookieParam added in v0.0.14

func NewRefCookieParam(p *openapi3.ParameterRef, components Components) Ref[CookieParameter]

func NewRefHeaderParam added in v0.0.14

func NewRefHeaderParam(p *openapi3.ParameterRef, components Components) Ref[HeaderParameter]

func NewRefPathParam added in v0.0.14

func NewRefPathParam(p *openapi3.ParameterRef, components Components) Ref[PathParameter]

func NewRefQueryParam added in v0.0.14

func NewRefQueryParam(p *openapi3.ParameterRef, components Components) Ref[QueryParameter]

func NewSchemaRef added in v0.0.14

func NewSchemaRef(schema *openapi3.SchemaRef, components ComponentsSchemas) Ref[Schema]

type RefKey added in v0.0.14

type RefKey string

type RefObject added in v0.0.14

type RefObject[T any] struct {
	V *Object[Ref[T]]
}

func NewRefObject added in v0.0.14

func NewRefObject[T any](v *Object[Ref[T]]) *RefObject[T]

func NewRefObjectSource added in v0.0.14

func NewRefObjectSource[T any](key string, source interface {
	Get(string) (*Object[Ref[T]], bool)
}) *RefObject[T]

func (*RefObject[T]) Ref added in v0.0.14

func (r *RefObject[T]) Ref() *Object[Ref[T]]

func (*RefObject[T]) Value added in v0.0.14

func (r *RefObject[T]) Value() *T

type RequestBody added in v0.0.14

type RequestBody struct {
	NoRef[RequestBody]

	Description string
	Content     Map[*MediaType]
	Required    bool
}

func NewRequestBody added in v0.0.14

func NewRequestBody(r *openapi3.RequestBody, components ComponentsSchemas) *RequestBody

func (*RequestBody) Value added in v0.0.14

func (r *RequestBody) Value() *RequestBody

type Response

type Response struct {
	NoRef[Response]

	Description string
	Headers     Map[Ref[Header]]
	Content     Map[*MediaType]
	Links       Map[Ref[Link]]
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(s *openapi3.Response, components Components) *Response

func (*Response) Value added in v0.0.14

func (r *Response) Value() *Response

type ResponseOld added in v0.0.14

type ResponseOld struct {
	StatusCode string
	Operation  *Operation
	Spec       *openapi3.Response

	RefName string
	Headers []HeaderOld
}

func NewResponseOld added in v0.0.14

func NewResponseOld(responseStatusCode string, o *Operation, r *openapi3.ResponseRef) *ResponseOld

type Schema

type Schema struct {
	NoRef[Schema]
	// Ref         string
	Type        string
	Items       Ref[Schema]
	Properties  []SchemaProperty
	AllOf       []Ref[Schema]
	Description string

	Schema *openapi3.Schema
}

func NewSchema

func NewSchema(schema *openapi3.Schema, components ComponentsSchemas) *Schema

func (*Schema) Value added in v0.0.14

func (s *Schema) Value() *Schema

type SchemaProperty added in v0.0.11

type SchemaProperty struct {
	Name   string
	Schema Ref[Schema]
}

type Security added in v0.0.12

type Security struct {
	Requirement []string
	Scheme      openapi3.SecurityScheme
}

type SecurityRequirement added in v0.0.14

type SecurityRequirement struct {
	Scheme       *SecurityScheme
	Requirements []string
}

func NewSecurityRequirement added in v0.0.14

func NewSecurityRequirement(k string, v []string, schemes SecuritySchemes) SecurityRequirement

func NewSecurityRequirements added in v0.0.14

func NewSecurityRequirements(s openapi3.SecurityRequirements, schemes SecuritySchemes) []SecurityRequirement

type SecurityRequirements added in v0.0.14

type SecurityRequirements []SecurityRequirement

type SecurityScheme added in v0.0.14

type SecurityScheme struct {
	NoRef[SecurityScheme]

	// Any
	Type        SecuritySchemeType
	Description string

	// apiKey
	Name string
	In   SecuritySchemeIn

	// http
	Scheme       string
	BearerFormat string

	// oauth2
	Flows OAuthFlows

	// openIdConnect
	OpenIDConnectURL string
}

func NewSecurityScheme added in v0.0.14

func NewSecurityScheme(s *openapi3.SecurityScheme) *SecurityScheme

func (*SecurityScheme) Value added in v0.0.14

func (s *SecurityScheme) Value() *SecurityScheme

type SecuritySchemeIn added in v0.0.14

type SecuritySchemeIn string
const (
	SecuritySchemeInQuery  SecuritySchemeIn = "query"
	SecuritySchemeInHeader SecuritySchemeIn = "header"
	SecuritySchemeInCookie SecuritySchemeIn = "cookie"
)

type SecuritySchemeType added in v0.0.14

type SecuritySchemeType string
const (
	SecuritySchemeTypeApiKey        SecuritySchemeType = "apiKey"
	SecuritySchemeTypeHTTP          SecuritySchemeType = "http"
	SecuritySchemeTypeMutualTLS     SecuritySchemeType = "mutualTLS"
	SecuritySchemeTypeOAuth2        SecuritySchemeType = "oauth2"
	SecuritySchemeTypeOpenIDConnect SecuritySchemeType = "openIdConnect"
)

type SecuritySchemes added in v0.0.14

type SecuritySchemes = Map[Ref[SecurityScheme]]

type Server added in v0.0.14

type Server struct {
	URL         string
	Description string
	Variables   Map[ServerVariable]
}

func NewServer added in v0.0.14

func NewServer(s *openapi3.Server) Server

func NewServers added in v0.0.14

func NewServers(ss openapi3.Servers) []Server

type ServerVariable added in v0.0.14

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

func NewServerVariable added in v0.0.14

func NewServerVariable(sv *openapi3.ServerVariable) ServerVariable

type Spec

type Spec struct {
	OpenAPI string
	Info    Info
	Servers []Server

	PathItems  []*PathItem
	Operations []*Operation

	Components Components

	Security []SecurityRequirement
}

func ParseSwagger

func ParseSwagger(spec *openapi3.Swagger) (*Spec, error)

Jump to

Keyboard shortcuts

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