Documentation
¶
Overview ¶
Package openapi provides a comprehensive Go implementation of the OpenAPI 3.1 specification.
Index ¶
- type Callback
- type Components
- type Contact
- type Discriminator
- type Encoding
- type Example
- type ExternalDocumentation
- type Header
- type Info
- type License
- type Link
- type MediaType
- type OAuthFlow
- type OAuthFlows
- type OpenAPI
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type Schema
- type SchemaType
- func (t SchemaType) Contains(s string) bool
- func (t SchemaType) IsArray() bool
- func (t SchemaType) IsEmpty() bool
- func (t SchemaType) IsNullable() bool
- func (t SchemaType) MarshalJSON() ([]byte, error)
- func (t SchemaType) MarshalYAML() (interface{}, error)
- func (t SchemaType) String() string
- func (t SchemaType) Strings() []string
- func (t *SchemaType) UnmarshalJSON(data []byte) error
- func (t *SchemaType) UnmarshalYAML(value *yaml.Node) error
- type SecurityRequirement
- type SecurityScheme
- type Server
- type ServerVariable
- type Tag
- type TagGroup
- type XML
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Components ¶
type Components struct {
Schemas map[string]*Schema `json:"schemas,omitempty" yaml:"schemas,omitempty"`
Responses map[string]*Response `json:"responses,omitempty" yaml:"responses,omitempty"`
Parameters map[string]*Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Examples map[string]*Example `json:"examples,omitempty" yaml:"examples,omitempty"`
RequestBodies map[string]*RequestBody `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
Headers map[string]*Header `json:"headers,omitempty" yaml:"headers,omitempty"`
SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
Links map[string]*Link `json:"links,omitempty" yaml:"links,omitempty"`
Callbacks map[string]*Callback `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
PathItems map[string]*PathItem `json:"pathItems,omitempty" yaml:"pathItems,omitempty"`
}
Components holds reusable objects for the specification.
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"`
}
Contact information for the API.
type Discriminator ¶
type Discriminator struct {
Mapping map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
PropertyName string `json:"propertyName" yaml:"propertyName"`
}
Discriminator supports polymorphism.
type Encoding ¶
type Encoding struct {
Headers map[string]*Header `json:"headers,omitempty" yaml:"headers,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
Style string `json:"style,omitempty" yaml:"style,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}
Encoding property for multipart media types.
type Example ¶
type Example 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"`
Value any `json:"value,omitempty" yaml:"value,omitempty"`
ExternalValue string `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
}
Example object for example values.
type ExternalDocumentation ¶
type ExternalDocumentation struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
URL string `json:"url" yaml:"url"`
}
ExternalDocumentation allows referencing an external resource.
type Header ¶
type Header struct {
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
Examples map[string]*Example `json:"examples,omitempty" yaml:"examples,omitempty"`
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Style string `json:"style,omitempty" yaml:"style,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"`
AllowReserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}
Header follows the structure of Parameter but without name and in fields.
type Info ¶
type Info struct {
Title string `json:"title" yaml:"title"`
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"`
}
Info provides metadata about the API.
type License ¶
type License struct {
Name string `json:"name" yaml:"name"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"`
}
License information for the API.
type Link ¶
type Link struct {
RequestBody any `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
Parameters map[string]any `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Server *Server `json:"server,omitempty" yaml:"server,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
OperationRef string `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}
Link represents a possible design-time link for a response.
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Examples map[string]*Example `json:"examples,omitempty" yaml:"examples,omitempty"`
Encoding map[string]Encoding `json:"encoding,omitempty" yaml:"encoding,omitempty"`
}
MediaType provides schema and examples for the media type.
type OAuthFlow ¶
type OAuthFlow struct {
Scopes map[string]string `json:"scopes" yaml:"scopes"`
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
}
OAuthFlow configuration details for a supported OAuth flow.
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"`
}
OAuthFlows allows configuration of the supported OAuth flows.
type OpenAPI ¶
type OpenAPI struct {
Paths map[string]PathItem `json:"paths" yaml:"paths"`
Webhooks map[string]*PathItem `json:"webhooks,omitempty" yaml:"webhooks,omitempty"`
Components *Components `json:"components,omitempty" yaml:"components,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
Info Info `json:"info" yaml:"info"`
OpenAPI string `json:"openapi" yaml:"openapi"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
Security []SecurityRequirement `json:"security,omitempty" yaml:"security,omitempty"`
Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty"`
TagGroups []TagGroup `json:"x-tagGroups,omitempty" yaml:"x-tagGroups,omitempty"`
}
OpenAPI represents the root document object.
type Operation ¶
type Operation struct {
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
Responses map[string]Response `json:"responses" yaml:"responses"`
Callbacks map[string]Callback `json:"callbacks,omitempty" yaml:"callbacks,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"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Security []SecurityRequirement `json:"security,omitempty" yaml:"security,omitempty"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
}
Operation describes a single API operation on a path.
type Parameter ¶
type Parameter struct {
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
Examples map[string]*Example `json:"examples,omitempty" yaml:"examples,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
In string `json:"in,omitempty" yaml:"in,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Style string `json:"style,omitempty" yaml:"style,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"`
}
Parameter describes a single operation parameter.
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"`
Get *Operation `json:"get,omitempty" yaml:"get,omitempty"`
Post *Operation `json:"post,omitempty" yaml:"post,omitempty"`
Put *Operation `json:"put,omitempty" yaml:"put,omitempty"`
Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
Patch *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
Options *Operation `json:"options,omitempty" yaml:"options,omitempty"`
Head *Operation `json:"head,omitempty" yaml:"head,omitempty"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}
PathItem describes operations available on a single path.
type RequestBody ¶
type RequestBody struct {
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
}
RequestBody describes a request body.
type Response ¶
type Response struct {
Headers map[string]*Header `json:"headers,omitempty" yaml:"headers,omitempty"`
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
Links map[string]*Link `json:"links,omitempty" yaml:"links,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}
Response describes a single response from an API operation.
type Schema ¶
type Schema struct {
AdditionalProperties any `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Default any `json:"default,omitempty" yaml:"default,omitempty"`
Const any `json:"const,omitempty" yaml:"const,omitempty"`
ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
Not *Schema `json:"not,omitempty" yaml:"not,omitempty"`
Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`
Deprecated *bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
Discriminator *Discriminator `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`
WriteOnly *bool `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
ReadOnly *bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
MaxLength *int `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
XML *XML `json:"xml,omitempty" yaml:"xml,omitempty"`
UniqueItems *bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
MaxProperties *int `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
MinLength *int `json:"minLength,omitempty" yaml:"minLength,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
MinProperties *int `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
MinItems *int `json:"minItems,omitempty" yaml:"minItems,omitempty"`
MaxItems *int `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
Format string `json:"format,omitempty" yaml:"format,omitempty"`
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`
Type *SchemaType `json:"type,omitempty" yaml:"type,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
OneOf []*Schema `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"`
AnyOf []*Schema `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
AllOf []*Schema `json:"allOf,omitempty" yaml:"allOf,omitempty"`
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
}
Schema represents a JSON Schema.
type SchemaType ¶
type SchemaType struct {
// contains filtered or unexported fields
}
SchemaType represents the type field in a JSON Schema, which can be either a single string (e.g., "string") or an array of strings (e.g., ["string", "null"]).
func NewSchemaType ¶
func NewSchemaType(s string) *SchemaType
NewSchemaType creates a SchemaType pointer from a single type string.
func NewSchemaTypes ¶
func NewSchemaTypes(s []string) *SchemaType
NewSchemaTypes creates a SchemaType pointer from multiple type strings.
func (SchemaType) Contains ¶
func (t SchemaType) Contains(s string) bool
Contains returns true if the given type is present.
func (SchemaType) IsArray ¶
func (t SchemaType) IsArray() bool
IsArray returns true if the type is an array of types.
func (SchemaType) IsEmpty ¶
func (t SchemaType) IsEmpty() bool
IsEmpty returns true if no type is set.
func (SchemaType) IsNullable ¶
func (t SchemaType) IsNullable() bool
IsNullable returns true if "null" is one of the types.
func (SchemaType) MarshalJSON ¶
func (t SchemaType) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (SchemaType) MarshalYAML ¶
func (t SchemaType) MarshalYAML() (interface{}, error)
MarshalYAML implements yaml.Marshaler.
func (SchemaType) String ¶
func (t SchemaType) String() string
String returns the type as a single string. If the type is an array, returns the first element. Returns empty string if no type is set.
func (SchemaType) Strings ¶
func (t SchemaType) Strings() []string
Strings returns the type as a slice of strings. If the type is a single string, returns a slice containing that string.
func (*SchemaType) UnmarshalJSON ¶
func (t *SchemaType) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*SchemaType) UnmarshalYAML ¶
func (t *SchemaType) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.
type SecurityRequirement ¶
SecurityRequirement lists required security schemes to execute an operation.
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type" yaml:"type"` // "apiKey", "http", "oauth2", "openIdConnect"
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"` // for apiKey
In string `json:"in,omitempty" yaml:"in,omitempty"` // for apiKey: "query", "header", "cookie"
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"` // for http: "bearer", "basic", etc.
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"` // for http bearer
Flows *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"` // for oauth2
OpenIDConnectURL string `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"` // for openIdConnect
}
SecurityScheme defines a security scheme for the API.
type Server ¶
type Server struct {
Variables map[string]ServerVariable `json:"variables,omitempty" yaml:"variables,omitempty"`
URL string `json:"url" yaml:"url"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}
Server represents a server.
type ServerVariable ¶
type ServerVariable struct {
Default string `json:"default" yaml:"default"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Enum []string `json:"enum,omitempty" yaml:"enum,omitempty"`
}
ServerVariable represents a server variable for server URL template substitution.
type Tag ¶
type Tag struct {
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
Name string `json:"name" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}
Tag adds metadata to a single tag.
type TagGroup ¶
type TagGroup struct {
Name string `json:"name" yaml:"name"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
}
TagGroup groups tags for documentation tools like Redoc.
type XML ¶
type XML struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
Attribute bool `json:"attribute,omitempty" yaml:"attribute,omitempty"`
Wrapped bool `json:"wrapped,omitempty" yaml:"wrapped,omitempty"`
}
XML metadata for array/object schemas.