Documentation
¶
Overview ¶
Package spec is the provider-neutral OpenAPI IR: ordered slices only, not changed after build.
Index ¶
- Constants
- Variables
- func DeriveOperationID(method, path string) string
- func StatusCode(status string) (int, bool)
- type Additional
- type AdditionalMode
- type Bound
- type Callback
- type ComponentRef
- type Components
- type Discriminator
- type Document
- type Encoding
- type Extension
- type Field
- type Header
- type Info
- type Limits
- type Mapping
- type MediaType
- type Named
- type OAuthFlow
- type Operation
- type Origin
- type Parameter
- type Property
- type Ref
- type RequestBody
- type RequiredScheme
- type Response
- type Schema
- type Scope
- type SecurityRequirement
- type SecurityScheme
- type Server
- type ServerVariable
- type TypeSet
- type Value
- type ValueKind
- type Version
Constants ¶
const ( InPath = "path" InQuery = "query" InHeader = "header" InCookie = "cookie" InQueryString = "querystring" )
Variables ¶
var MethodOrder = []string{"GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE", "QUERY"}
MethodOrder is the order operations of one path item come in; 3.2 additional operations follow.
Functions ¶
func DeriveOperationID ¶
DeriveOperationID names an operation without operationId: GET /users/{id} gives getUsersId.
func StatusCode ¶
StatusCode reads a status code from a response key: the key when it is a number, the first digit times 100 when it has three characters and starts with a digit, as a range such as 4XX does. It reads none from default or from another key.
Types ¶
type Additional ¶
type Additional struct {
Mode AdditionalMode
Schema *Schema
}
type AdditionalMode ¶
type AdditionalMode int
const ( AdditionalUnset AdditionalMode = iota AdditionalAllowed AdditionalDenied AdditionalSchema )
type Callback ¶
type Callback struct {
Name string
Operations []*Operation
Ref *ComponentRef
}
Callback holds the operations of all its expressions; each operation's Path is its expression.
type ComponentRef ¶
ComponentRef records the $ref an object came from; Name is set for a component target.
type Components ¶
type Components struct {
Schemas []Named[*Schema]
Responses []Named[*Response]
Parameters []Named[*Parameter]
RequestBodies []Named[*RequestBody]
Headers []Named[*Header]
SecuritySchemes []*SecurityScheme
}
Components lists every reusable object in source order. Usages elsewhere share these pointers.
type Discriminator ¶
Discriminator has every mapping value resolved, bare names too; Default is 3.2 defaultMapping.
type Document ¶
type Document struct {
Version Version
Info Info
Servers []Server
Operations []*Operation
Webhooks []*Operation
Components Components
Security []SecurityRequirement
Extensions []Extension
}
Document is a parsed spec. Operations keep paths in source order and methods in MethodOrder.
type Limits ¶
type Limits struct {
Minimum *Bound
Maximum *Bound
MultipleOf *json.Number
MinLength *int64
MaxLength *int64
MinItems *int64
MaxItems *int64
MinProperties *int64
MaxProperties *int64
UniqueItems bool
}
Limits keeps numbers as written; 3.0 boolean and 3.1 numeric exclusive bounds look the same.
type OAuthFlow ¶
type OAuthFlow struct {
Kind string
AuthorizationURL string
TokenURL string
RefreshURL string
Scopes []Scope
}
OAuthFlow is one oauth2 flow; Kind is its key, such as implicit or clientCredentials.
type Operation ¶
type Operation struct {
ID string
IsIDDerived bool
Method string
Path string
IsWebhook bool
Summary string
Description string
Deprecated bool
Tags []string
// Path-level params come first; an operation param with the same in and name replaces one.
Params []*Parameter
Body *RequestBody
Responses []*Response
Callbacks []*Callback
// Security is the effective list: the operation's own when it sets one, else the document's.
Security []SecurityRequirement
Servers []Server
Extensions []Extension
Origin Origin
}
Operation is one method on a path, webhook or callback expression.
type Origin ¶
Origin is an object's JSON pointer in the parsed document and its position in the source file.
type Parameter ¶
type Parameter struct {
Name string
In string
Description string
Required bool
Deprecated bool
AllowEmptyValue bool
Style string
Explode bool
AllowReserved bool
Schema *Schema
Contents []*MediaType
Extensions []Extension
Ref *ComponentRef
Origin Origin
}
Parameter has Style and Explode resolved to their defaults when the spec leaves them out.
type RequestBody ¶
type RequiredScheme ¶
type Response ¶
type Response struct {
Status string
Description string
Headers []*Header
Contents []*MediaType
Extensions []Extension
Ref *ComponentRef
Origin Origin
}
Response is one entry of an operation's responses. Status is empty on a component response.
type Schema ¶
type Schema struct {
Ref *Ref
Types TypeSet
Nullable bool
Format string
Title string
Description string
Pattern string
ContentEncoding string
ContentMediaType string
Required []string
Properties []*Property
AdditionalProperties Additional
PropertyNames *Schema
Items *Schema
PrefixItems []*Schema
AllOf []*Schema
OneOf []*Schema
AnyOf []*Schema
Not *Schema
If *Schema
Then *Schema
Else *Schema
Discriminator *Discriminator
Enum []Value
Const *Value
Default *Value
Examples []Value
Limits Limits
ReadOnly bool
WriteOnly bool
Deprecated bool
Extensions []Extension
Origin Origin
}
Schema is one schema; on a $ref usage Ref is set and keywords next to the $ref stay here.
type SecurityRequirement ¶
type SecurityRequirement struct {
Schemes []RequiredScheme
}
SecurityRequirement is one alternative: every scheme in it applies. No schemes means anonymous.
type SecurityScheme ¶
type Server ¶
type Server struct {
URL string
Name string
Description string
Variables []ServerVariable
}
type ServerVariable ¶
type TypeSet ¶
type TypeSet uint8
TypeSet holds the allowed JSON types; Null stays only when alone, else it becomes Nullable.
type Value ¶
type Value struct {
Kind ValueKind
Str string
Num json.Number
Bool bool
Items []Value
Fields []Field
}
Value is a JSON value; only the field for its Kind is set, and numbers keep their written form.