Documentation
¶
Overview ¶
Package runtime holds the helpers generated code imports. It uses the standard library only.
Index ¶
- Constants
- Variables
- func ContentType(h http.Header) string
- func ContentTypeError(mediaType string) error
- func DecodeBytes(body io.Reader, isRequired bool) ([]byte, error)
- func DecodeCookie(cookies []*http.Cookie, p Param, dst any) error
- func DecodeForm(body io.Reader, dst any, isRequired bool, enc Encoding) error
- func DecodeHeader(h http.Header, p Param, dst any) error
- func DecodeHeaders(h http.Header, dst any) error
- func DecodeJSON(body io.Reader, dst any, isRequired bool, ...) error
- func DecodeMultipart(r *http.Request, dst any, maxMemory int64, enc Encoding) error
- func DecodeMultipartBody(body io.Reader, contentType string, dst any, enc Encoding) error
- func DecodePath(raw string, p Param, dst any) error
- func DecodeQuery(q Query, p Param, dst any) error
- func DecodeQueryString(raw string, p Param, dst any) error
- func DecodeText(body io.Reader, isRequired bool) (string, error)
- func DecodeTextValue(body io.Reader, dst any, isRequired bool) error
- func DiscriminatorError(_ []byte, err error) error
- func EncodeCookie(v any, p Param) ([]*http.Cookie, error)
- func EncodeForm(v any, enc Encoding) (string, error)
- func EncodeHeader(v any, p Param) (string, error)
- func EncodePath(v any, p Param) (string, error)
- func EncodeQuery(v any, p Param) (string, error)
- func EncodeText(v any) (string, error)
- func ErrorMessage(v any, path, fallback string) string
- func Headers(h http.Header, v any) http.Header
- func IsJSON(mediaType string) bool
- func IsSequential(mediaType string) bool
- func MarshalAdditional[T any](fields any, extra map[string]T, known ...string) ([]byte, error)
- func MarshalOneOf(shared any, set ...any) ([]byte, error)
- func MarshalUnion(shared any, set ...any) ([]byte, error)
- func MarshalUnionText(data []byte, err error) ([]byte, error)
- func MarshalVariants(shared any, u Union, variants ...any) ([]byte, error)
- func MediaRange(mediaType string) string
- func MultipartSize(v any, enc Encoding) (int64, string, error)
- func OperationID(ctx context.Context) string
- func Ptr[T any](v T) *T
- func SetErrorMessage(dst any, path, message string) error
- func UnescapePath(r *http.Request, v string) string
- func UnmarshalAdditional[T any](data []byte, fields any, extra *map[string]T, known ...string) error
- func UnmarshalAdditionalForm[T any](form *multipart.Form, fields any, extra *map[string]T, known ...string) error
- func UnmarshalUnion(data []byte, u Union) error
- func UnmarshalUnionForm(form *multipart.Form, fields any, u Union) error
- func UnmarshalUnionText(raw []byte, decode func(data []byte) error) error
- func WithOperationID(ctx context.Context, id string) context.Context
- func WriteMultipart(mw *multipart.Writer, v any, enc Encoding) error
- type Date
- type Email
- type Encoding
- type File
- type FormUnmarshaler
- type Kind
- type Nullable
- type Object
- type Param
- type Presence
- type PresenceChecker
- type Prop
- type PropertyEncoding
- type Query
- type Setter
- type Shape
- type Style
- type Union
- type Variant
Constants ¶
const DateFormat = time.DateOnly
DateFormat is the layout of an OpenAPI date (RFC 3339 full-date).
const DefaultMultipartMemory = 32 << 20
DefaultMultipartMemory is how much of a multipart form stays in memory before parts spill to disk.
const SupportsGeneratorV1 = true
SupportsGeneratorV1 is set while this runtime has everything code from generator API level 1 uses. Generated files refer to it, so a runtime too old or too new for them fails to compile.
Variables ¶
var ( ErrInvalidDate = errors.New("invalid date") ErrAdditionalProperty = errors.New("invalid additional property") ErrNoVariant = errors.New("no union variant matches") ErrAmbiguous = errors.New("more than one union variant matches") ErrUnknownDiscriminator = errors.New("unknown discriminator value") ErrNotObject = errors.New("not a JSON object") ErrParamMissing = errors.New("parameter is required") ErrParamValue = errors.New("invalid parameter value") ErrHeaderValue = errors.New("invalid response header") ErrBodyEmpty = errors.New("request body is required") ErrBodyValue = errors.New("invalid body value") ErrContentType = errors.New("unsupported content type") )
Functions ¶
func ContentType ¶
ContentType is the media type of a request or response body, without its parameters. A parameter that does not parse, such as a charset without a value, leaves the media type.
func ContentTypeError ¶
ContentTypeError is the error of a body in a media type the operation does not take.
func DecodeBytes ¶
DecodeBytes reads a body as it is.
func DecodeCookie ¶
DecodeCookie decodes a cookie into dst, a pointer to its type; a form cookie is percent-encoded.
func DecodeForm ¶
DecodeForm decodes an application/x-www-form-urlencoded body into dst, a pointer. Keys with brackets nest: address[city]=Berlin, items[0]=a. Into an untyped target, a value that reads as a number or a boolean becomes one. A field enc declares JSON is read as JSON.
func DecodeHeader ¶
DecodeHeader decodes a header into dst, a pointer to the parameter's type.
func DecodeHeaders ¶
DecodeHeaders reads h into dst, a pointer to a struct of typed headers whose fields name their header in a json tag, each read as Headers writes it. A header that is not there leaves its field as it is.
func DecodeJSON ¶
func DecodeJSON(body io.Reader, dst any, isRequired bool, unmarshal func(data []byte, v any) error) error
DecodeJSON decodes a JSON body into dst, a pointer, with unmarshal. An empty body is an error when the body is required, and leaves dst as it is otherwise.
func DecodeMultipart ¶
DecodeMultipart decodes a multipart/form-data body into dst, a pointer to a struct. Fields of type File, *File or []File take the files of their name; a part that holds JSON fills a field of a struct, slice or map type; every other part is read as form text. maxMemory is how much stays in memory, DefaultMultipartMemory when 0. A type with UnmarshalForm reads the form itself. A part enc declares JSON is read as JSON.
func DecodeMultipartBody ¶
DecodeMultipartBody is DecodeMultipart for a body without its request, held in memory whole.
func DecodePath ¶
DecodePath decodes a path segment into dst, a pointer to the parameter's type.
func DecodeQuery ¶
DecodeQuery decodes a query parameter into dst, a pointer to the parameter's type. A parameter that is not there sets its default, else leaves dst as it is, unless it is required. A value that does not unescape is ErrParamValue.
func DecodeQueryString ¶
DecodeQueryString decodes raw, the whole query, into dst: percent-encoded JSON or a form.
func DecodeText ¶
DecodeText reads a text body.
func DecodeTextValue ¶
DecodeTextValue reads a text body into what dst points to, by its type, as EncodeText writes it.
func DiscriminatorError ¶
DiscriminatorError is the discriminator error of a MarshalVariants result, nil for any other.
func EncodeCookie ¶
EncodeCookie writes v as cookies, one per item when exploded; a form cookie is percent-encoded.
func EncodeForm ¶
EncodeForm writes v, a struct or a map, as a url-encoded form, each property as enc says.
func EncodeHeader ¶
EncodeHeader writes v as a header value.
func EncodePath ¶
EncodePath writes v as a path segment.
func EncodeQuery ¶
EncodeQuery writes v as the query parameter p, name=value pairs joined by &, and "" for a nil value. It percent-encodes as RFC 6570 expands a form-style query: a separator goes as it is and the same byte inside a name or value escaped, a space as %20. With IsReserved, the reserved characters a query holds and %XX escapes stay as they are.
func EncodeText ¶
EncodeText writes v, a scalar, as a text body carries it; another value is ErrContentType.
func ErrorMessage ¶
ErrorMessage returns the value at path in the JSON of v, or fallback when there is none. A path is dotted property names; a name ending in [] takes the first item of that array. A value that is no string is written as JSON.
func Headers ¶
Headers adds the fields of v, a struct of typed headers, to h and returns it, made when nil. A nil, unwritable or optional zero field is left out. Its header tag may say explode or json.
func IsSequential ¶
IsSequential reports a media type whose body is a sequence of frames: text/event-stream and the line-delimited JSON types, with or without parameters.
func MarshalAdditional ¶
MarshalAdditional writes fields, a struct whose additional properties are tagged json:"-", as a JSON object, then adds the entries of extra in key order. Keys in known, the struct's own property names, are left out of extra.
func MarshalOneOf ¶
MarshalOneOf is MarshalUnion for a oneOf, where more than one set variant is an error.
func MarshalUnion ¶
MarshalUnion writes the set variants of a union merged with shared, its own properties or nil. When a part is no object, the first set variant is written alone; nothing set writes null.
func MarshalUnionText ¶
MarshalUnionText writes data, the JSON of a union of scalars, as text without string quotes.
func MarshalVariants ¶
MarshalVariants is MarshalOneOf or MarshalUnion per union of u, filling or checking discriminators.
func MediaRange ¶
MediaRange is the range of one type a media type falls in, text/* for text/csv.
func MultipartSize ¶
MultipartSize writes v as a multipart form without reading its files, and returns the boundary it used with the length of the form, -1 when a file does not know its size.
func OperationID ¶
OperationID returns the operation name ctx holds, or "" when it holds none.
func SetErrorMessage ¶
SetErrorMessage stores message at path in dst, a pointer, by decoding the JSON the path describes into it.
func UnescapePath ¶
UnescapePath unescapes v, a path value a router cut from r.URL.RawPath when the request has one.
func UnmarshalAdditional ¶
func UnmarshalAdditional[T any](data []byte, fields any, extra *map[string]T, known ...string) error
UnmarshalAdditional decodes data into fields, then every member whose key is not in known into extra, keeping the entries extra already has.
func UnmarshalAdditionalForm ¶
func UnmarshalAdditionalForm[T any](form *multipart.Form, fields any, extra *map[string]T, known ...string) error
UnmarshalAdditionalForm reads form into fields, then every name not in known into extra.
func UnmarshalUnion ¶
UnmarshalUnion decodes data into the variants of u it matches: one for oneOf, every match for anyOf. docs/types.md in the mockzilla-codegen repository has the order variants are tried in.
func UnmarshalUnionForm ¶
UnmarshalUnionForm reads form into the shared fields, then into the variants it matches.
func UnmarshalUnionText ¶
UnmarshalUnionText decodes raw with a union's UnmarshalJSON, as a number or boolean first.
func WithOperationID ¶
WithOperationID returns a copy of ctx that holds the name of the operation being called.
func WriteMultipart ¶
WriteMultipart writes v, a struct, to mw as a multipart form and closes mw, which ends the form: File fields as file parts with their name and content type, application/octet-stream without one, lists as one part per item, structs and maps as JSON parts, bytes as base64, and everything else as text. A property enc declares a media type for is written in it. A nil slice or map is left out, and a zero field tagged omitempty or omitzero, as JSON leaves them out.
Types ¶
type Date ¶
Date is a calendar date, written as 2006-01-02 in JSON and text.
func (Date) MarshalJSON ¶
MarshalJSON is needed because the embedded time.Time has its own.
func (Date) MarshalText ¶
func (*Date) UnmarshalJSON ¶
UnmarshalJSON leaves d unchanged on null, like encoding/json does for other types.
func (*Date) UnmarshalText ¶
type Email ¶
type Email string
Email holds an email address. Decoding accepts any string; Validate checks it.
type Encoding ¶
type Encoding map[string]PropertyEncoding
Encoding is how a form body writes each property, by name, as its encoding object says.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is binary content from bytes, a reader or a multipart form. A reader can be read once.
func DecodeFile ¶
DecodeFile hands the body of r to a File that streams it, under the request's media type and with its content length as the size. It reads one byte ahead to tell an empty body.
func NewFileFromMultipart ¶
func NewFileFromMultipart(h *multipart.FileHeader) File
func NewFileReader ¶
NewFileReader wraps r; size is -1 when unknown.
func (File) ContentType ¶
func (File) MarshalJSON ¶
MarshalJSON writes the content as base64, like encoding/json does for []byte.
func (*File) UnmarshalJSON ¶
type FormUnmarshaler ¶
FormUnmarshaler is a type that reads a form itself, as a generated union in a form body does.
type Kind ¶
type Kind uint8
Kind is a set of JSON value kinds. A union variant lists the kinds it takes; a value has one.
const ( KindNull Kind = 1 << iota KindBool // KindInteger is a number without a fraction or exponent. KindInteger KindNumber KindString KindArray KindObject KindAny = KindNull | KindBool | KindInteger | KindNumber | KindString | KindArray | KindObject )
type Nullable ¶
type Nullable[T any] struct { // contains filtered or unexported fields }
Nullable is a value that may be absent or null. Its zero value is absent.
func (Nullable[T]) Get ¶
Get returns the value and true, or the zero value and false when it is absent or null.
func (Nullable[T]) MarshalJSON ¶
MarshalJSON writes the value, or null when it holds none.
func (Nullable[T]) Or ¶
func (n Nullable[T]) Or(def T) T
Or returns the value, or def when it is absent or null.
func (*Nullable[T]) UnmarshalJSON ¶
UnmarshalJSON reads a value, or null.
type Object ¶
Object is an object schema: its properties sorted by key, what other keys hold, and IsClosed.
type Param ¶
type Param struct {
Name string
Style Style
IsExplode bool
IsRequired bool
IsJSON bool
IsReserved bool
Default string
}
Param describes one parameter: its name, how it is written, and whether it must be there. IsJSON is set for content application/json; Default is the JSON a decoder sets when it is not there. IsReserved is allowReserved: a query value or form cookie keeps the reserved characters.
type Presence ¶
Presence holds the objects of request bodies, sorted by name; IsChecked adds checks to defaults.
func (Presence) Form ¶
Form checks a url-encoded form against the object p names and returns the form to decode.
type PresenceChecker ¶
type PresenceChecker interface {
JSON(body io.Reader, p Prop) (io.Reader, error)
Form(body io.Reader, p Prop, enc Encoding) (io.Reader, error)
Multipart(r *http.Request, p Prop, maxMemory int64, enc Encoding) error
}
PresenceChecker checks which keys a request body has and fills its defaults before decoding.
type Prop ¶
type Prop struct {
Key string
IsRequired bool
IsNullable bool
Default string
Object string
Items *Prop
Values *Prop
}
Prop is one value of a body: a property under its Key, a list item, a map value or the body.
type PropertyEncoding ¶
PropertyEncoding is a property written in ContentType, or as a query parameter of Style when set.
type Query ¶
Query is the query of a request by key: each key unescaped, each value still percent-encoded, so a list is split at its commas before its items are unescaped.
func ParseQuery ¶
ParseQuery splits raw, the query of a request, at & into its keys. A key that does not unescape is left out; a value is unescaped when its parameter is decoded.
type Setter ¶
type Setter interface {
// contains filtered or unexported methods
}
Setter decodes a variant field from JSON or from a form.
type Union ¶
type Union struct {
IsAnyOf bool
Discriminator string
IsLiteral bool
Variants []Variant
Also []Union
}
Union describes a union to UnmarshalUnion. Shared are the property names the union holds next to its variants, which no variant counts as unknown. Also are more unions the value is at once. IsLiteral says the discriminator values are JSON booleans or numbers, not strings.
type Variant ¶
type Variant struct {
Name string
Kind Kind
Values []string
IsDefault bool
IsAbsent bool
Required []string
Known []string
IsClosed bool
Shapes []Shape
Into Setter
}
Variant describes one member of a union to UnmarshalUnion: the JSON kinds it takes, the discriminator values that pick it, and for objects its property names (Known nil takes any key). IsDefault picks it for a value no variant lists, IsAbsent for an object without the property. A member that is itself a union lists the objects it can be in Shapes and ranks by the best one.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package httpclient builds and sends the requests of a generated client and reads its responses.
|
Package httpclient builds and sends the requests of a generated client and reads its responses. |
|
Package httpserver holds the errors, error handlers, operation middleware and response writing of a generated server.
|
Package httpserver holds the errors, error handlers, operation middleware and response writing of a generated server. |
|
Package mask hides sensitive values, for logs and other output.
|
Package mask hides sensitive values, for logs and other output. |
|
Package mcptool holds what generated MCP tools call: their input, result and error.
|
Package mcptool holds what generated MCP tools call: their input, result and error. |
|
Package validation checks values against the constraints of a spec and collects what fails.
|
Package validation checks values against the constraints of a spec and collects what fails. |