Documentation
¶
Overview ¶
Package openapi provides OpenAPI specification parsing utilities.
Index ¶
- func IsJSON(data []byte) bool
- func IsYAML(data []byte) bool
- func SubstituteEnvVars(data []byte) []byte
- func SubstituteEnvVarsInString(input string) string
- type Components
- type Contact
- type Example
- type ExternalDocs
- type Header
- type Info
- type License
- type MediaType
- type OAuthFlow
- type OAuthFlows
- type Operation
- type Parameter
- type Parser
- type PathItem
- type RequestBody
- type Response
- type Schema
- type SecurityRequirement
- type SecurityScheme
- type Server
- type ServerVariable
- type Spec
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SubstituteEnvVars ¶
SubstituteEnvVars replaces environment variable placeholders in data Supports ${VAR} and $VAR syntax
func SubstituteEnvVarsInString ¶
SubstituteEnvVarsInString substitutes environment variables in a string
Types ¶
type Components ¶
type Components struct {
Schemas map[string]*Schema `json:"schemas,omitempty"`
Responses map[string]*Response `json:"responses,omitempty"`
Parameters map[string]*Parameter `json:"parameters,omitempty"`
Examples map[string]*Example `json:"examples,omitempty"`
RequestBodies map[string]*RequestBody `json:"requestBodies,omitempty"`
Headers map[string]*Header `json:"headers,omitempty"`
SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty"`
Links map[string]interface{} `json:"links,omitempty"`
Callbacks map[string]interface{} `json:"callbacks,omitempty"`
}
Components represents OpenAPI components
type Contact ¶
type Contact struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
Contact represents OpenAPI contact object
type Example ¶
type Example struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Value interface{} `json:"value,omitempty"`
}
Example represents an OpenAPI example
type ExternalDocs ¶
type ExternalDocs struct {
Description string `json:"description,omitempty"`
URL string `json:"url"`
}
ExternalDocs represents external documentation
type Header ¶
type Header struct {
Description string `json:"description,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Header represents an OpenAPI header
type Info ¶
type Info struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty"`
License *License `json:"license,omitempty"`
Version string `json:"version"`
}
Info represents OpenAPI info object
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty"`
Example interface{} `json:"example,omitempty"`
Examples map[string]*Example `json:"examples,omitempty"`
}
MediaType represents an OpenAPI media type
type OAuthFlow ¶
type OAuthFlow struct {
AuthorizationURL string `json:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty"`
Scopes map[string]string `json:"scopes,omitempty"`
}
OAuthFlow represents an OAuth flow
type OAuthFlows ¶
type OAuthFlows struct {
Implicit *OAuthFlow `json:"implicit,omitempty"`
Password *OAuthFlow `json:"password,omitempty"`
ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
}
OAuthFlows represents OAuth flows
type Operation ¶
type Operation struct {
ID string `json:"operationId"`
Method string `json:"method"`
Path string `json:"path"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses map[string]*Response `json:"responses"`
Security []SecurityRequirement `json:"security,omitempty"`
}
Operation represents an OpenAPI operation
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // query, header, path, cookie
Description string `json:"description,omitempty"`
Required bool `json:"required"`
Schema *Schema `json:"schema,omitempty"`
Example interface{} `json:"example,omitempty"`
}
Parameter represents an OpenAPI parameter
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles parsing of OpenAPI specifications
func (*Parser) ParseFileWithEnv ¶
ParseFileWithEnv parses an OpenAPI spec with environment variable substitution
type PathItem ¶
type PathItem struct {
Ref string `json:"$ref,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,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"`
Trace *Operation `json:"trace,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
}
PathItem represents an OpenAPI path item
func (*PathItem) GetOperation ¶
GetOperation returns the operation for a given HTTP method
func (*PathItem) GetOperations ¶
GetOperations returns all operations for this path item
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"`
Required bool `json:"required"`
Content map[string]MediaType `json:"content"`
}
RequestBody represents an OpenAPI request body
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaType `json:"content,omitempty"`
Headers map[string]*Header `json:"headers,omitempty"`
}
Response represents an OpenAPI response
type Schema ¶
type Schema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Description string `json:"description,omitempty"`
Default interface{} `json:"default,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
Items *Schema `json:"items,omitempty"`
Ref string `json:"$ref,omitempty"`
Nullable bool `json:"nullable,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
WriteOnly bool `json:"writeOnly,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Example interface{} `json:"example,omitempty"`
// Validation keywords
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
ExclusiveMin bool `json:"exclusiveMinimum,omitempty"`
ExclusiveMax bool `json:"exclusiveMaximum,omitempty"`
MultipleOf *float64 `json:"multipleOf,omitempty"`
MinItems *int `json:"minItems,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
MinProperties *int `json:"minProperties,omitempty"`
MaxProperties *int `json:"maxProperties,omitempty"`
Pattern string `json:"pattern,omitempty"`
AllOf []*Schema `json:"allOf,omitempty"`
AnyOf []*Schema `json:"anyOf,omitempty"`
OneOf []*Schema `json:"oneOf,omitempty"`
Not *Schema `json:"not,omitempty"`
AdditionalProperties interface{} `json:"additionalProperties,omitempty"`
}
Schema represents an OpenAPI schema
type SecurityRequirement ¶
SecurityRequirement represents a security requirement
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
In string `json:"in,omitempty"`
Scheme string `json:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty"`
Flows *OAuthFlows `json:"flows,omitempty"`
OpenIDConnectURL string `json:"openIdConnectUrl,omitempty"`
}
SecurityScheme represents a security scheme
type Server ¶
type Server struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
Variables map[string]*ServerVariable `json:"variables,omitempty"`
}
Server represents an OpenAPI server
type ServerVariable ¶
type ServerVariable struct {
Enum []string `json:"enum,omitempty"`
Default string `json:"default"`
Description string `json:"description,omitempty"`
}
ServerVariable represents a server variable
type Spec ¶
type Spec struct {
OpenAPI string `json:"openapi"`
Info Info `json:"info"`
Servers []Server `json:"servers,omitempty"`
Paths map[string]*PathItem `json:"paths"`
Components *Components `json:"components,omitempty"`
Security []SecurityRequirement `json:"security,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Raw interface{} `json:"-"` // Raw parsed spec
}
Spec represents a parsed OpenAPI specification
func (*Spec) GetAllOperations ¶
GetAllOperations returns all operations from the spec
func (*Spec) GetBaseURL ¶
GetBaseURL returns the first server URL or empty string
type Tag ¶
type Tag struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}
Tag represents an OpenAPI tag