openapi

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Components

type Components struct {
	Schemas         orderedtypes.Map[string, Schema]      `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	Parameters      orderedtypes.Map[string, Parameter]   `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Responses       orderedtypes.Map[string, Response]    `json:"responses,omitempty" yaml:"responses,omitempty"`
	RequestBodies   orderedtypes.Map[string, RequestBody] `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
	SecuritySchemes orderedtypes.Map[string, Security]    `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
}

type Content

type Content struct {
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	Schema      Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
}

type FullPath

type FullPath struct {
	URL       string
	Method    string
	Operation Operation
}

type Info

type Info struct {
	Title   string `json:"title,omitempty" yaml:"title,omitempty"`
	Version string `json:"version,omitempty" yaml:"version,omitempty"`
}

type OpenAPI

type OpenAPI struct {
	Version    string                         `json:"version,omitempty" yaml:"version,omitempty"`
	Tags       []Tag                          `json:"tags" yaml:"tags"`
	Info       Info                           `json:"info,omitempty" yaml:"info,omitempty"`
	Paths      orderedtypes.Map[string, Path] `json:"paths,omitempty" yaml:"paths,omitempty"`
	Components Components                     `json:"components,omitempty" yaml:"components,omitempty"`
	// contains filtered or unexported fields
}

func Parse

func Parse(filepath string) (*OpenAPI, error)

func (*OpenAPI) GetRef

func (o *OpenAPI) GetRef(path string) any

func (OpenAPI) GroupedPaths

func (o OpenAPI) GroupedPaths() []PathGroup

type Operation

type Operation struct {
	Tags        []string                             `json:"tags,omitempty" yaml:"tags,omitempty"`
	Deprecated  bool                                 `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Summary     *string                              `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string                               `json:"description,omitempty" yaml:"description,omitempty"`
	RequestBody *RequestBody                         `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
	Parameters  []Parameter                          `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	Responses   orderedtypes.Map[string, *Response]  `json:"responses,omitempty" yaml:"responses,omitempty"`
	Security    []orderedtypes.Map[string, []string] `json:"security,omitempty" yaml:"security,omitempty"`
}

func (*Operation) DescriptionAsHTML

func (op *Operation) DescriptionAsHTML() string

func (Operation) HasBody

func (op Operation) HasBody() bool

func (Operation) HasParameters

func (op Operation) HasParameters() bool

func (Operation) HasResponseInfo

func (op Operation) HasResponseInfo() bool

func (Operation) SortedResponses

func (p Operation) SortedResponses() []ResponseAndStatus

type Parameter

type Parameter struct {
	Name            string            `json:"name,omitempty" yaml:"name,omitempty"`
	In              ParameterLocation `json:"in,omitempty" yaml:"in,omitempty"`
	Description     string            `json:"description,omitempty" yaml:"description,omitempty"`
	Required        bool              `json:"required,omitempty" yaml:"required,omitempty"`
	Deprecated      bool              `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	AllowEmptyValue bool              `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
	Schema          *Schema           `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         any               `json:"example,omitempty" yaml:"example,omitempty"`
	Ref             string            `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	ResolvedRefName string            `json:"-" yaml:"-"`
}

type ParameterLocation

type ParameterLocation string
const (
	ParameterQuery  ParameterLocation = "query"
	ParameterHeader ParameterLocation = "header"
	ParameterPath   ParameterLocation = "path"
	ParameterCookie ParameterLocation = "cookie"
)

type Path

type Path struct {
	Get    *Operation `json:"get,omitempty" yaml:"get,omitempty"`
	Post   *Operation `json:"post,omitempty" yaml:"post,omitempty"`
	Patch  *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
	Put    *Operation `json:"put,omitempty" yaml:"put,omitempty"`
	Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
}

func (Path) Methods

func (p Path) Methods() iter.Seq2[string, *Operation]

type PathGroup

type PathGroup struct {
	Tag   Tag
	Paths []FullPath
}

type RequestBody

type RequestBody struct {
	Content orderedtypes.Map[string, *Content] `json:"content,omitempty" yaml:"content,omitempty"`
	Ref     string                             `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}

type Response

type Response struct {
	Description     string                            `json:"description,omitempty" yaml:"description,omitempty"`
	Content         orderedtypes.Map[string, Content] `json:"content,omitempty" yaml:"content,omitempty"`
	Ref             string                            `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	ResolvedRefName string                            `json:"-" yaml:"-"`
}

type ResponseAndStatus

type ResponseAndStatus struct {
	Response
	Status string
}

type Schema

type Schema struct {
	Type                 any                               `json:"type,omitempty" yaml:"type,omitempty"`
	Items                *Schema                           `json:"items,omitempty" yaml:"items,omitempty"`
	Required             []string                          `json:"required,omitempty" yaml:"required,omitempty"`
	Properties           *orderedtypes.Map[string, Schema] `json:"properties,omitempty" yaml:"properties,omitempty"`
	AdditionalProperties *Schema                           `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
	PatternProperties    *orderedtypes.Map[string, Schema] `json:"patternProperties,omitempty" yaml:"patternProperties,omitempty"`
	Description          string                            `json:"description,omitempty" yaml:"description,omitempty"`
	Ref                  string                            `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	ResolvedRefName      string                            `json:"-" yaml:"-"`
	Example              any                               `json:"example,omitempty" yaml:"example,omitempty"`
	Examples             []orderedtypes.Any                `json:"examples,omitempty" yaml:"examples,omitempty"`
	AnyOf                []Schema                          `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
	Enum                 []any                             `json:"enum,omitempty" yaml:"enum,omitempty"`
}

func (*Schema) DescriptionAsHTML

func (s *Schema) DescriptionAsHTML() string

func (*Schema) GenerateExample added in v0.3.0

func (s *Schema) GenerateExample() orderedtypes.Any

func (Schema) JSON

func (s Schema) JSON() string

func (Schema) TypeName

func (s Schema) TypeName() string

type Security

type Security struct {
	Type        SecurityType `json:"type,omitempty" yaml:"type,omitempty"`
	Description string       `json:"description,omitempty" yaml:"description,omitempty"`

	// applies to apiKey
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	In   string `json:"in,omitempty" yaml:"in,omitempty"`

	// applies to http
	Scheme       string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
	BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`

	// applies to oauth2
	Flows SecurityFlows `json:"flows,omitempty" yaml:"flows,omitempty"`

	// applies to openIdConnect
	OpenIdConnectURL string `json:"openIdConnectURL,omitempty" yaml:"openIdConnectURL,omitempty"`
}

func (*Security) DescriptionAsHTML

func (s *Security) DescriptionAsHTML() string

type SecurityFlow

type SecurityFlow 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           *orderedtypes.Map[string, string] `json:"scopes,omitempty" yaml:"scopes,omitempty"`
}

type SecurityFlows

type SecurityFlows struct {
	Implicit          *SecurityFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
	Password          *SecurityFlow `json:"password,omitempty" yaml:"password,omitempty"`
	ClientCredentials *SecurityFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
	AuthorizationCode *SecurityFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}

func (*SecurityFlows) Iter

func (sf *SecurityFlows) Iter() iter.Seq2[string, *SecurityFlow]

type SecurityType

type SecurityType string
const (
	SecurityOAuth2        SecurityType = "oauth2"
	SecurityApiKey        SecurityType = "apiKey"
	SecurityHttp          SecurityType = "http"
	SecurityMutualTLS     SecurityType = "mutualTLS"
	SecurityOpenIdConnect SecurityType = "openIdConnect"
)

type Tag

type Tag struct {
	Name string `json:"name" yaml:"name"`
}

Jump to

Keyboard shortcuts

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