Documentation
¶
Overview ¶
Package openapi decodes the subset of an OpenAPI 3 document the importer reads. Anything not listed here (servers, security, examples, xml hints) is ignored. The types are mutable on purpose: workarounds patch a loaded document before it is normalised into definitions.
Index ¶
Constants ¶
const ( InPath = "path" InQuery = "query" InHeader = "header" )
Parameter locations.
const ( TypeString = "string" TypeInteger = "integer" TypeNumber = "number" TypeBoolean = "boolean" TypeArray = "array" TypeObject = "object" )
JSON schema type names.
const SchemaRefPrefix = "#/components/schemas/"
SchemaRefPrefix is how a `$ref` names a component schema.
Variables ¶
This section is empty.
Functions ¶
func SortedKeys ¶
SortedKeys returns the keys of a map in sorted order, for deterministic output.
Types ¶
type Example ¶
type Example struct {
Value json.RawMessage `json:"value"`
}
Example is one named example of a media type's content. TMDB's document keeps the only true shape of its request bodies here.
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema"`
Examples map[string]*Example `json:"examples"`
}
MediaType is the schema of one media type of a body or response.
type Operation ¶
type Operation struct {
OperationID string `json:"operationId"`
Tags []string `json:"tags"`
Summary string `json:"summary"`
Description string `json:"description"`
Deprecated bool `json:"deprecated"`
Parameters []*Parameter `json:"parameters"`
RequestBody *RequestBody `json:"requestBody"`
Responses map[string]*Response `json:"responses"`
}
Operation is one HTTP method on one path.
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"`
Description string `json:"description"`
Required bool `json:"required"`
Deprecated bool `json:"deprecated"`
Style string `json:"style"`
Explode *bool `json:"explode"`
Schema *Schema `json:"schema"`
}
Parameter is a path, query or header parameter.
func (*Parameter) DeepObject ¶
DeepObject reports whether an object parameter is sent as one key per field, name[field]=value, rather than as one JSON string.
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get"`
Post *Operation `json:"post"`
Put *Operation `json:"put"`
Delete *Operation `json:"delete"`
Patch *Operation `json:"patch"`
}
PathItem holds the operations of one path. HEAD and OPTIONS are not imported: the servers use them only for cache probes and CORS.
type RequestBody ¶
type RequestBody struct {
Required bool `json:"required"`
Content map[string]*MediaType `json:"content"`
}
RequestBody maps media types to their schema.
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]*MediaType `json:"content"`
}
Response is one status code of an operation. A response that is a `$ref` into components/responses (Emby's error codes) carries no content, and decodes to one with none.
type Schema ¶
type Schema struct {
Ref string `json:"$ref"`
Type string `json:"type"`
Format string `json:"format"`
Description string `json:"description"`
Nullable bool `json:"nullable"`
Enum []json.RawMessage `json:"enum"`
Properties map[string]*Schema `json:"properties"`
// Required names the properties an object must carry.
Required []string `json:"required"`
Items *Schema `json:"items"`
AdditionalProperties json.RawMessage `json:"additionalProperties"`
AllOf []*Schema `json:"allOf"`
OneOf []*Schema `json:"oneOf"`
AnyOf []*Schema `json:"anyOf"`
}
Schema is a JSON schema object, as far as the two specs use it.
func (*Schema) Additional ¶
Additional returns the additionalProperties schema. ok is false when the schema does not allow additional properties; a bare `true` or `{}` yields an empty schema.
func (*Schema) EnumValues ¶
EnumValues returns the enum members as strings. Both specs only use string enums; anything else is rendered through its JSON form.
type Spec ¶
type Spec struct {
OpenAPI string `json:"openapi"`
Info struct {
Title string `json:"title"`
Version string `json:"version"`
} `json:"info"`
Paths map[string]*PathItem `json:"paths"`
Components struct {
Schemas map[string]*Schema `json:"schemas"`
} `json:"components"`
}
Spec is an OpenAPI 3 document.