Documentation
¶
Overview ¶
Package openapi20 provides Go types for Swagger/OpenAPI Specification v2.0 Based on https://swagger.io/specification/v2/
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Contact ¶
type Contact struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
Extensions map[string]any `json:"-"`
}
Contact contains contact information for the API
func (Contact) MarshalJSON ¶
func (*Contact) UnmarshalJSON ¶
type ExternalDocumentation ¶
type ExternalDocumentation struct {
Description string `json:"description,omitempty"`
URL string `json:"url"`
Extensions map[string]any `json:"-"`
}
ExternalDocumentation allows referencing an external resource for extended documentation
func (ExternalDocumentation) MarshalJSON ¶
func (e ExternalDocumentation) MarshalJSON() ([]byte, error)
func (*ExternalDocumentation) UnmarshalJSON ¶
func (e *ExternalDocumentation) UnmarshalJSON(data []byte) error
type Header ¶
type Header struct {
Type string `json:"type"` // string, number, integer, boolean, array
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Default any `json:"default,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
MinLength *int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
MinItems *int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Enum []any `json:"enum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty"`
Extensions map[string]any `json:"-"`
}
Header represents a header in a response
func (Header) MarshalJSON ¶
func (*Header) UnmarshalJSON ¶
type Info ¶
type Info struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty"`
License *License `json:"license,omitempty"`
Extensions map[string]any `json:"-"`
}
Info provides metadata about the API
func (Info) MarshalJSON ¶
func (*Info) UnmarshalJSON ¶
type Items ¶
type Items struct {
Type string `json:"type,omitempty"` // string, number, integer, boolean, array
Format string `json:"format,omitempty"`
Items *Items `json:"items,omitempty"` // for nested arrays
CollectionFormat string `json:"collectionFormat,omitempty"`
Default any `json:"default,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
MinLength *int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
MinItems *int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Enum []any `json:"enum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty"`
Extensions map[string]any `json:"-"`
}
Items describes the type of items in an array parameter Used for non-body parameters with type=array
func (Items) MarshalJSON ¶
func (*Items) UnmarshalJSON ¶
type License ¶
type License struct {
Name string `json:"name"`
URL string `json:"url,omitempty"`
Extensions map[string]any `json:"-"`
}
License contains license information for the API
func (License) MarshalJSON ¶
func (*License) UnmarshalJSON ¶
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
OperationID string `json:"operationId,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
Responses *Responses `json:"responses"`
Schemes []string `json:"schemes,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Security []SecurityRequirement `json:"security,omitempty"`
Extensions map[string]any `json:"-"`
}
Operation describes a single API operation on a path
func (Operation) MarshalJSON ¶
func (*Operation) UnmarshalJSON ¶
type Parameter ¶
type Parameter struct {
// Reference field
Ref string `json:"$ref,omitempty"`
// Common fields
Name string `json:"name,omitempty"`
In string `json:"in,omitempty"` // query, header, path, formData, body
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
// Body parameter fields
Schema *Schema `json:"schema,omitempty"`
// Non-body parameter fields
Type string `json:"type,omitempty"` // string, number, integer, boolean, array, file
Format string `json:"format,omitempty"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"` // csv, ssv, tsv, pipes, multi
Default any `json:"default,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
MinLength *int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
MinItems *int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Enum []any `json:"enum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty"`
Extensions map[string]any `json:"-"`
}
Parameter describes a single operation parameter. In Swagger 2.0, parameters can be: - Body parameters (in=body, with schema) - Non-body parameters (in=query/header/path/formData, with type, format, items, etc.)
func NewParameterReference ¶
NewParameterReference creates a parameter that is actually a reference
func (*Parameter) IsBodyParameter ¶
IsBodyParameter returns true if this is a body parameter
func (*Parameter) IsReference ¶
IsReference checks if this parameter is actually a reference ($ref)
func (Parameter) MarshalJSON ¶
func (*Parameter) UnmarshalJSON ¶
type PathItem ¶
type PathItem struct {
Ref string `json:"$ref,omitempty"`
Get *Operation `json:"get,omitempty"`
Put *Operation `json:"put,omitempty"`
Post *Operation `json:"post,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Options *Operation `json:"options,omitempty"`
Head *Operation `json:"head,omitempty"`
Patch *Operation `json:"patch,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
Extensions map[string]any `json:"-"`
}
PathItem describes the operations available on a single path
func (PathItem) MarshalJSON ¶
func (*PathItem) UnmarshalJSON ¶
type Paths ¶
Paths holds the relative paths to the individual endpoints and their operations
func (Paths) MarshalJSON ¶
func (*Paths) UnmarshalJSON ¶
type Response ¶
type Response struct {
// Reference field
Ref string `json:"$ref,omitempty"`
// Response fields
Description string `json:"description,omitempty"`
Schema *Schema `json:"schema,omitempty"`
Headers map[string]*Header `json:"headers,omitempty"`
Examples map[string]any `json:"examples,omitempty"`
Extensions map[string]any `json:"-"`
}
Response describes a single response from an API Operation
func NewResponseReference ¶
NewResponseReference creates a response that is actually a reference
func (*Response) IsReference ¶
IsReference checks if this response is actually a reference ($ref)
func (Response) MarshalJSON ¶
func (*Response) UnmarshalJSON ¶
type Responses ¶
type Responses struct {
Default *Response `json:"-"`
StatusCode map[string]*Response `json:"-"`
Extensions map[string]any `json:"-"`
}
Responses is a container for the expected responses of an operation
func (Responses) MarshalJSON ¶
func (*Responses) UnmarshalJSON ¶
type Schema ¶
type Schema struct {
// Reference
Ref string `json:"$ref,omitempty"`
// JSON Schema keywords
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Default any `json:"default,omitempty"`
Format string `json:"format,omitempty"`
// Type - can be string or array of strings in Swagger 2.0
Type string `json:"type,omitempty"`
// Enum and validation
Enum []any `json:"enum,omitempty"`
// Numeric validation
MultipleOf *float64 `json:"multipleOf,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
// String validation
MaxLength *int `json:"maxLength,omitempty"`
MinLength *int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
// Array validation
MaxItems *int `json:"maxItems,omitempty"`
MinItems *int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Items *Schema `json:"items,omitempty"`
// Object validation
MaxProperties *int `json:"maxProperties,omitempty"`
MinProperties *int `json:"minProperties,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // Can be boolean schema
// Composition keywords - Swagger 2.0 only supports allOf
AllOf []*Schema `json:"allOf,omitempty"`
// Swagger 2.0 specific
Discriminator string `json:"discriminator,omitempty"` // Property name (string in 2.0, object in 3.0)
ReadOnly bool `json:"readOnly,omitempty"`
XML *XML `json:"xml,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
Example any `json:"example,omitempty"`
Extensions map[string]any `json:"-"`
// contains filtered or unexported fields
}
Schema represents a JSON Schema subset for Swagger 2.0. This type supports both object schemas and boolean schemas (true/false). In Swagger 2.0, additionalProperties can be a boolean or a schema object.
func NewBooleanSchema ¶
NewBooleanSchema creates a boolean schema
func NewSchemaReference ¶
NewSchemaReference creates a schema that is actually a reference
func (*Schema) BooleanValue ¶
BooleanValue returns the boolean value if this is a boolean schema
func (*Schema) IsBooleanSchema ¶
IsBooleanSchema returns true if this is a boolean schema (true or false)
func (*Schema) IsReference ¶
IsReference checks if this schema is actually a reference ($ref)
func (Schema) MarshalJSON ¶
func (*Schema) UnmarshalJSON ¶
type SecurityRequirement ¶
SecurityRequirement lists the required security schemes to execute an operation. Each key is a security scheme name, and the value is a list of required scopes.
type SecurityScheme ¶
type SecurityScheme struct {
// Type of security scheme: basic, apiKey, or oauth2
Type string `json:"type"`
// Description of the security scheme
Description string `json:"description,omitempty"`
// apiKey specific fields
Name string `json:"name,omitempty"` // Name of the header or query parameter
In string `json:"in,omitempty"` // Location: "header" or "query"
// oauth2 specific fields
Flow string `json:"flow,omitempty"` // implicit, password, application, accessCode
AuthorizationUrl string `json:"authorizationUrl,omitempty"` // Required for implicit and accessCode flows
TokenUrl string `json:"tokenUrl,omitempty"` // Required for password, application, and accessCode flows
Scopes map[string]string `json:"scopes,omitempty"` // Available scopes for OAuth2
Extensions map[string]any `json:"-"`
}
SecurityScheme defines a security scheme in Swagger 2.0. Types can be: "basic", "apiKey", or "oauth2"
func (*SecurityScheme) IsAPIKey ¶
func (ss *SecurityScheme) IsAPIKey() bool
IsAPIKey returns true if this is an API key authentication scheme
func (*SecurityScheme) IsBasic ¶
func (ss *SecurityScheme) IsBasic() bool
IsBasic returns true if this is a basic authentication scheme
func (*SecurityScheme) IsOAuth2 ¶
func (ss *SecurityScheme) IsOAuth2() bool
IsOAuth2 returns true if this is an OAuth2 authentication scheme
func (SecurityScheme) MarshalJSON ¶
func (ss SecurityScheme) MarshalJSON() ([]byte, error)
func (*SecurityScheme) UnmarshalJSON ¶
func (ss *SecurityScheme) UnmarshalJSON(data []byte) error
type Swagger ¶
type Swagger struct {
Swagger string `json:"swagger"`
Info *Info `json:"info"`
Host string `json:"host,omitempty"`
BasePath string `json:"basePath,omitempty"`
Schemes []string `json:"schemes,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Paths *Paths `json:"paths"`
Definitions map[string]*Schema `json:"definitions,omitempty"`
Parameters map[string]*Parameter `json:"parameters,omitempty"`
Responses map[string]*Response `json:"responses,omitempty"`
SecurityDefinitions map[string]*SecurityScheme `json:"securityDefinitions,omitempty"`
Security []SecurityRequirement `json:"security,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
Extensions map[string]any `json:"-"`
}
Swagger is the root object of a Swagger 2.0 document
func (Swagger) MarshalJSON ¶
func (*Swagger) UnmarshalJSON ¶
type Tag ¶
type Tag struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
Extensions map[string]any `json:"-"`
}
Tag adds metadata to a single tag that is used by the Operation Object
func (Tag) MarshalJSON ¶
func (*Tag) UnmarshalJSON ¶
type XML ¶
type XML struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Prefix string `json:"prefix,omitempty"`
Attribute bool `json:"attribute,omitempty"`
Wrapped bool `json:"wrapped,omitempty"`
Extensions map[string]any `json:"-"`
}
XML provides metadata for XML representation