specification

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ExtTagGoType = "x-goag-go-type"

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

	Headers       Map[Ref[Header]]
	RequestBodies Map[Ref[RequestBody]]
	Responses     Map[Ref[Response]]

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

	SecuritySchemes SecuritySchemes
	Links           Map[Ref[Link]]
	PathItems       Map[Ref[PathItem]]
}

func NewComponents added in v0.0.11

func NewComponents(spec openapi3.Components, opts SchemaOptions) (zero Components, _ error)

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 Maybe[bool]

	Schema Ref[Schema]
}

func NewCookieParameter added in v0.0.14

func NewCookieParameter(p *openapi3.Parameter, schemas ComponentsSchemas, opts SchemaOptions) *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, opts SchemaOptions) *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 Maybe[bool]

	Schema Ref[Schema]
}

func NewHeaderParameter added in v0.0.14

func NewHeaderParameter(p *openapi3.Parameter, schemas ComponentsSchemas, opts SchemaOptions) *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[string, 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 Sourcer[T], 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 Sourcer[T], 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[string, T], bool)

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

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

type Maybe added in v0.1.5

type Maybe[T any] struct {
	Set   bool
	Value T
}

func Just added in v0.1.5

func Just[T any](v T) Maybe[T]

func NewMaybe added in v0.1.5

func NewMaybe[T any](v *T) Maybe[T]

func Nothing added in v0.1.5

func Nothing[T any]() Maybe[T]

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, opts SchemaOptions) *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[string, 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          Maybe[OAuthFlow]
	Password          Maybe[OAuthFlow]
	ClientCredentials Maybe[OAuthFlow]
	AuthorizationCode Maybe[OAuthFlow]
}

func NewOAuthFlows added in v0.0.14

func NewOAuthFlows(s *openapi3.OAuthFlows) OAuthFlows

type Object added in v0.0.14

type Object[K, T any] struct {
	Name K
	V    T
}

type Operation

type Operation struct {
	PathItem *PathItem

	Path Path

	Tags        []string
	Summary     string
	Description string
	OperationID string

	Parameters OperationParameters

	RequestBody Maybe[Ref[RequestBody]]

	HTTPMethod HTTPMethod
	Method     HTTPMethodTitle

	Operation *openapi3.Operation

	Security SecurityRequirements

	Responses Map[Ref[Response]]
}

func NewOperation

func NewOperation(pi *PathItem, rawPath string, method httpMethod, operation *openapi3.Operation, specSecurityReqs SecurityRequirements, legacyComponents openapi3.Components, securitySchemes SecuritySchemes, components Components, opts SchemaOptions) (*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, opts SchemaOptions) OperationParameters

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
	PathItem *openapi3.PathItem
}

func NewPathItem added in v0.0.14

func NewPathItem(path string) *PathItem

func (*PathItem) GetOperation added in v0.1.14

func (p *PathItem) GetOperation(m HTTPMethod) (*Operation, bool)

func (*PathItem) HasOperation added in v0.1.14

func (p *PathItem) HasOperation(m HTTPMethod) bool

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 Maybe[bool]

	Schema Ref[Schema]
}

func NewPathParameter added in v0.0.14

func NewPathParameter(p *openapi3.Parameter, schemas ComponentsSchemas, opts SchemaOptions) *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       Maybe[bool]
	AllowReserved bool

	Schema Ref[Schema]
}

func NewQueryParameter added in v0.0.14

func NewQueryParameter(p *openapi3.Parameter, schemas ComponentsSchemas, opts SchemaOptions) *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[string, Ref[T]]
	Value() *T
}

func NewRefCookieParam added in v0.0.14

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

func NewRefHeaderParam added in v0.0.14

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

func NewRefPathParam added in v0.0.14

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

func NewRefQueryParam added in v0.0.14

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

func NewSchemaRef added in v0.0.14

func NewSchemaRef(schema *openapi3.SchemaRef, components ComponentsSchemas, opts SchemaOptions) 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[string, Ref[T]]
}

func NewRefObject added in v0.0.14

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

func NewRefObjectSource added in v0.0.14

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

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

func (r *RefObject[T]) Ref() *Object[string, 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, opts SchemaOptions) *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]]

	UsedIn []ResponseUsedIn
}

func NewResponse

func NewResponse(s *openapi3.Response, components Components, opts SchemaOptions) *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 ResponseUsedIn added in v0.1.8

type ResponseUsedIn struct {
	Operation *Operation
	Status    string
}

type Schema

type Schema struct {
	NoRef[Schema]

	Type        string
	Format      string
	Items       Ref[Schema]
	Properties  []SchemaProperty
	AllOf       []Ref[Schema]
	Description string

	AdditionalProperties Maybe[Ref[Schema]]

	Custom Maybe[string]
}

func NewSchema

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

func (*Schema) Value added in v0.0.14

func (s *Schema) Value() *Schema

type SchemaOptions added in v0.1.18

type SchemaOptions struct {
	IgnoreCustomType bool
}

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 Sourcer added in v0.1.8

type Sourcer[T any] interface {
	Get(string) (*Object[string, Ref[T]], bool)
}

type SourcerFunc added in v0.1.8

type SourcerFunc[T any] func(string) (*Object[string, Ref[T]], bool)

func (SourcerFunc[T]) Get added in v0.1.8

func (s SourcerFunc[T]) Get(str string) (*Object[string, Ref[T]], bool)

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, opts SchemaOptions) (*Spec, error)

Jump to

Keyboard shortcuts

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