{"modulePath":"github.com/mockzilla/mockzilla-codegen","version":"v1.0.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package runtime\n\nPackage runtime holds the helpers generated code imports. It uses the standard library only.\n\n## Constants\n\n```go\nconst DateFormat = time.DateOnly\n```\nDateFormat is the layout of an OpenAPI date (RFC 3339 full-date).\n\n```go\nconst DefaultMultipartMemory = 32 \u003c\u003c 20\n```\nDefaultMultipartMemory is how much of a multipart form stays in memory before parts spill to disk.\n\n```go\nconst SupportsGeneratorV1 = true\n```\nSupportsGeneratorV1 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.\n\n## Variables\n\n```go\nvar (\n\tErrInvalidDate        = errors.New(\"invalid date\")\n\tErrAdditionalProperty = errors.New(\"invalid additional property\")\n\n\tErrNoVariant            = errors.New(\"no union variant matches\")\n\tErrAmbiguous            = errors.New(\"more than one union variant matches\")\n\tErrUnknownDiscriminator = errors.New(\"unknown discriminator value\")\n\tErrNotObject            = errors.New(\"not a JSON object\")\n\n\tErrParamMissing = errors.New(\"parameter is required\")\n\tErrParamValue   = errors.New(\"invalid parameter value\")\n\tErrHeaderValue  = errors.New(\"invalid response header\")\n\tErrBodyEmpty    = errors.New(\"request body is required\")\n\tErrBodyValue    = errors.New(\"invalid body value\")\n\tErrContentType  = errors.New(\"unsupported content type\")\n)\n```\n\n## Functions\n\n```go\nfunc ContentType(h http.Header) string\n```\nContentType 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.\n\n```go\nfunc ContentTypeError(mediaType string) error\n```\nContentTypeError is the error of a body in a media type the operation does not take.\n\n```go\nfunc DecodeBytes(body io.Reader, isRequired bool) ([]byte, error)\n```\nDecodeBytes reads a body as it is.\n\n```go\nfunc DecodeCookie(cookies []*http.Cookie, p Param, dst any) error\n```\nDecodeCookie decodes a cookie into dst, a pointer to its type; a form cookie is percent-encoded.\n\n```go\nfunc DecodeForm(body io.Reader, dst any, isRequired bool, enc Encoding) error\n```\nDecodeForm 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.\n\n```go\nfunc DecodeHeader(h http.Header, p Param, dst any) error\n```\nDecodeHeader decodes a header into dst, a pointer to the parameter's type.\n\n```go\nfunc DecodeHeaders(h http.Header, dst any) error\n```\nDecodeHeaders 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.\n\n```go\nfunc DecodeJSON(body io.Reader, dst any, isRequired bool, unmarshal func(data []byte, v any) error) error\n```\nDecodeJSON 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.\n\n```go\nfunc DecodeMultipart(r *http.Request, dst any, maxMemory int64, enc Encoding) error\n```\nDecodeMultipart 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.\n\n```go\nfunc DecodeMultipartBody(body io.Reader, contentType string, dst any, enc Encoding) error\n```\nDecodeMultipartBody is DecodeMultipart for a body without its request, held in memory whole.\n\n```go\nfunc DecodePath(raw string, p Param, dst any) error\n```\nDecodePath decodes a path segment into dst, a pointer to the parameter's type.\n\n```go\nfunc DecodeQuery(q Query, p Param, dst any) error\n```\nDecodeQuery 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.\n\n```go\nfunc DecodeQueryString(raw string, p Param, dst any) error\n```\nDecodeQueryString decodes raw, the whole query, into dst: percent-encoded JSON or a form.\n\n```go\nfunc DecodeText(body io.Reader, isRequired bool) (string, error)\n```\nDecodeText reads a text body.\n\n```go\nfunc DecodeTextValue(body io.Reader, dst any, isRequired bool) error\n```\nDecodeTextValue reads a text body into what dst points to, by its type, as EncodeText writes it.\n\n```go\nfunc DiscriminatorError(_ []byte, err error) error\n```\nDiscriminatorError is the discriminator error of a MarshalVariants result, nil for any other.\n\n```go\nfunc EncodeCookie(v any, p Param) ([]*http.Cookie, error)\n```\nEncodeCookie writes v as cookies, one per item when exploded; a form cookie is percent-encoded.\n\n```go\nfunc EncodeForm(v any, enc Encoding) (string, error)\n```\nEncodeForm writes v, a struct or a map, as a url-encoded form, each property as enc says.\n\n```go\nfunc EncodeHeader(v any, p Param) (string, error)\n```\nEncodeHeader writes v as a header value.\n\n```go\nfunc EncodePath(v any, p Param) (string, error)\n```\nEncodePath writes v as a path segment.\n\n```go\nfunc EncodeQuery(v any, p Param) (string, error)\n```\nEncodeQuery writes v as the query parameter p, name=value pairs joined by \u0026, 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.\n\n```go\nfunc EncodeText(v any) (string, error)\n```\nEncodeText writes v, a scalar, as a text body carries it; another value is ErrContentType.\n\n```go\nfunc ErrorMessage(v any, path, fallback string) string\n```\nErrorMessage 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.\n\n```go\nfunc Headers(h http.Header, v any) http.Header\n```\nHeaders 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.\n\n```go\nfunc IsJSON(mediaType string) bool\n```\nIsJSON reports a JSON media type: application/json or one with a +json suffix.\n\n```go\nfunc IsSequential(mediaType string) bool\n```\nIsSequential reports a media type whose body is a sequence of frames: text/event-stream and the line-delimited JSON types, with or without parameters.\n\n```go\nfunc MarshalAdditional[T any](fields any, extra map[string]T, known ...string) ([]byte, error)\n```\nMarshalAdditional 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.\n\n```go\nfunc MarshalOneOf(shared any, set ...any) ([]byte, error)\n```\nMarshalOneOf is MarshalUnion for a oneOf, where more than one set variant is an error.\n\n```go\nfunc MarshalUnion(shared any, set ...any) ([]byte, error)\n```\nMarshalUnion 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.\n\n```go\nfunc MarshalUnionText(data []byte, err error) ([]byte, error)\n```\nMarshalUnionText writes data, the JSON of a union of scalars, as text without string quotes.\n\n```go\nfunc MarshalVariants(shared any, u Union, variants ...any) ([]byte, error)\n```\nMarshalVariants is MarshalOneOf or MarshalUnion per union of u, filling or checking discriminators.\n\n```go\nfunc MediaRange(mediaType string) string\n```\nMediaRange is the range of one type a media type falls in, text/\\* for text/csv.\n\n```go\nfunc MultipartSize(v any, enc Encoding) (int64, string, error)\n```\nMultipartSize 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.\n\n```go\nfunc OperationID(ctx context.Context) string\n```\nOperationID returns the operation name ctx holds, or \"\" when it holds none.\n\n```go\nfunc Ptr[T any](v T) *T\n```\nPtr returns a pointer to a copy of v.\n\n```go\nfunc SetErrorMessage(dst any, path, message string) error\n```\nSetErrorMessage stores message at path in dst, a pointer, by decoding the JSON the path describes into it.\n\n```go\nfunc UnescapePath(r *http.Request, v string) string\n```\nUnescapePath unescapes v, a path value a router cut from r.URL.RawPath when the request has one.\n\n```go\nfunc UnmarshalAdditional[T any](data []byte, fields any, extra *map[string]T, known ...string) error\n```\nUnmarshalAdditional decodes data into fields, then every member whose key is not in known into extra, keeping the entries extra already has.\n\n```go\nfunc UnmarshalAdditionalForm[T any](form *multipart.Form, fields any, extra *map[string]T, known ...string) error\n```\nUnmarshalAdditionalForm reads form into fields, then every name not in known into extra.\n\n```go\nfunc UnmarshalUnion(data []byte, u Union) error\n```\nUnmarshalUnion 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.\n\n```go\nfunc UnmarshalUnionForm(form *multipart.Form, fields any, u Union) error\n```\nUnmarshalUnionForm reads form into the shared fields, then into the variants it matches.\n\n```go\nfunc UnmarshalUnionText(raw []byte, decode func(data []byte) error) error\n```\nUnmarshalUnionText decodes raw with a union's UnmarshalJSON, as a number or boolean first.\n\n```go\nfunc WithOperationID(ctx context.Context, id string) context.Context\n```\nWithOperationID returns a copy of ctx that holds the name of the operation being called.\n\n```go\nfunc WriteMultipart(mw *multipart.Writer, v any, enc Encoding) error\n```\nWriteMultipart 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.\n\n## Types\n\n```go\ntype Date struct {\n\ttime.Time\n}\n```\nDate is a calendar date, written as 2006-01-02 in JSON and text.\n\n```go\nfunc NewDate(year int, month time.Month, day int) Date\n```\nNewDate returns the date at midnight UTC.\n\n```go\nfunc (d Date) MarshalJSON() ([]byte, error)\n```\nMarshalJSON is needed because the embedded time.Time has its own.\n\n```go\nfunc (d Date) MarshalText() ([]byte, error)\n```\n\n```go\nfunc (d Date) String() string\n```\n\n```go\nfunc (d *Date) UnmarshalJSON(b []byte) error\n```\nUnmarshalJSON leaves d unchanged on null, like encoding/json does for other types.\n\n```go\nfunc (d *Date) UnmarshalText(b []byte) error\n```\n\n```go\ntype Email string\n```\nEmail holds an email address. Decoding accepts any string; Validate checks it.\n\n```go\nfunc (e Email) Validate() error\n```\nValidate accepts a bare address only: \"a@example.com\", not \"A \\\u003ca@example.com\u003e\".\n\n```go\ntype Encoding map[string]PropertyEncoding\n```\nEncoding is how a form body writes each property, by name, as its encoding object says.\n\n```go\ntype File struct {\n\t// contains filtered or unexported fields\n}\n```\nFile is binary content from bytes, a reader or a multipart form. A reader can be read once.\n\n```go\nfunc DecodeFile(r *http.Request, isRequired bool) (File, error)\n```\nDecodeFile 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.\n\n```go\nfunc NewFile(data []byte, name, contentType string) File\n```\n\n```go\nfunc NewFileFromMultipart(h *multipart.FileHeader) File\n```\n\n```go\nfunc NewFileReader(r io.Reader, name, contentType string, size int64) File\n```\nNewFileReader wraps r; size is -1 when unknown.\n\n```go\nfunc (f File) Bytes() ([]byte, error)\n```\n\n```go\nfunc (f File) ContentType() string\n```\n\n```go\nfunc (f File) MarshalJSON() ([]byte, error)\n```\nMarshalJSON writes the content as base64, like encoding/json does for \\[]byte.\n\n```go\nfunc (f File) Name() string\n```\n\n```go\nfunc (f File) Reader() (io.ReadCloser, error)\n```\n\n```go\nfunc (f File) Size() int64\n```\nSize is -1 when a reader was given without one.\n\n```go\nfunc (f *File) UnmarshalJSON(b []byte) error\n```\n\n```go\ntype FormUnmarshaler interface {\n\tUnmarshalForm(form *multipart.Form) error\n}\n```\nFormUnmarshaler is a type that reads a form itself, as a generated union in a form body does.\n\n```go\ntype Kind uint8\n```\nKind is a set of JSON value kinds. A union variant lists the kinds it takes; a value has one.\n\n```go\nconst (\n\tKindNull Kind = 1 \u003c\u003c iota\n\tKindBool\n\t// KindInteger is a number without a fraction or exponent.\n\tKindInteger\n\tKindNumber\n\tKindString\n\tKindArray\n\tKindObject\n\n\tKindAny = KindNull | KindBool | KindInteger | KindNumber | KindString | KindArray | KindObject\n)\n```\n\n```go\nfunc (k Kind) String() string\n```\n\n```go\ntype Nullable[T any] struct {\n\t// contains filtered or unexported fields\n}\n```\nNullable is a value that may be absent or null. Its zero value is absent.\n\n```go\nfunc Null[T any]() Nullable[T]\n```\nNull returns a Nullable that is null.\n\n```go\nfunc Some[T any](v T) Nullable[T]\n```\nSome returns a Nullable that holds v.\n\n```go\nfunc (n Nullable[T]) Get() (T, bool)\n```\nGet returns the value and true, or the zero value and false when it is absent or null.\n\n```go\nfunc (n Nullable[T]) IsNull() bool\n```\nIsNull reports whether it is null.\n\n```go\nfunc (n Nullable[T]) IsSet() bool\n```\nIsSet reports whether it holds a value or null.\n\n```go\nfunc (n Nullable[T]) IsZero() bool\n```\nIsZero reports whether it is absent, which omitzero leaves out.\n\n```go\nfunc (n Nullable[T]) MarshalJSON() ([]byte, error)\n```\nMarshalJSON writes the value, or null when it holds none.\n\n```go\nfunc (n Nullable[T]) Or(def T) T\n```\nOr returns the value, or def when it is absent or null.\n\n```go\nfunc (n *Nullable[T]) UnmarshalJSON(data []byte) error\n```\nUnmarshalJSON reads a value, or null.\n\n```go\ntype Object struct {\n\tName     string\n\tProps    []Prop\n\tExtra    *Prop\n\tIsClosed bool\n}\n```\nObject is an object schema: its properties sorted by key, what other keys hold, and IsClosed.\n\n```go\ntype Param struct {\n\tName       string\n\tStyle      Style\n\tIsExplode  bool\n\tIsRequired bool\n\tIsJSON     bool\n\tIsReserved bool\n\tDefault    string\n}\n```\nParam 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.\n\n```go\ntype Presence struct {\n\tIsChecked bool\n\tObjects   []Object\n}\n```\nPresence holds the objects of request bodies, sorted by name; IsChecked adds checks to defaults.\n\n```go\nfunc (pr Presence) Form(body io.Reader, p Prop, enc Encoding) (io.Reader, error)\n```\nForm checks a url-encoded form against the object p names and returns the form to decode.\n\n```go\nfunc (pr Presence) JSON(body io.Reader, p Prop) (io.Reader, error)\n```\nJSON checks a JSON body against p, sets the defaults it lacks and returns the body to decode.\n\n```go\nfunc (pr Presence) Multipart(r *http.Request, p Prop, maxMemory int64, enc Encoding) error\n```\nMultipart parses the multipart form of r, checks it against the object p names and fills it.\n\n```go\ntype PresenceChecker interface {\n\tJSON(body io.Reader, p Prop) (io.Reader, error)\n\tForm(body io.Reader, p Prop, enc Encoding) (io.Reader, error)\n\tMultipart(r *http.Request, p Prop, maxMemory int64, enc Encoding) error\n}\n```\nPresenceChecker checks which keys a request body has and fills its defaults before decoding.\n\n```go\ntype Prop struct {\n\tKey        string\n\tIsRequired bool\n\tIsNullable bool\n\tDefault    string\n\tObject     string\n\tItems      *Prop\n\tValues     *Prop\n}\n```\nProp is one value of a body: a property under its Key, a list item, a map value or the body.\n\n```go\ntype PropertyEncoding struct {\n\tContentType string\n\tStyle       Style\n\tIsExplode   bool\n\tIsReserved  bool\n}\n```\nPropertyEncoding is a property written in ContentType, or as a query parameter of Style when set.\n\n```go\ntype Query map[string][]string\n```\nQuery 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.\n\n```go\nfunc ParseQuery(raw string) Query\n```\nParseQuery splits raw, the query of a request, at \u0026 into its keys. A key that does not unescape is left out; a value is unescaped when its parameter is decoded.\n\n```go\ntype Setter interface {\n\t// contains filtered or unexported methods\n}\n```\nSetter decodes a variant field from JSON or from a form.\n\n```go\nfunc Into[T any](dst *T) Setter\n```\nInto returns the Setter of the variant field dst, which sets it only when the union picks it.\n\n```go\ntype Shape struct {\n\tRequired []string\n\tKnown    []string\n\tIsClosed bool\n}\n```\nShape is one object a variant can be, with property names as Variant has them.\n\n```go\ntype Style string\n```\nStyle is how a parameter is written, as OpenAPI names them.\n\n```go\nconst (\n\tStyleSimple         Style = \"simple\"\n\tStyleLabel          Style = \"label\"\n\tStyleMatrix         Style = \"matrix\"\n\tStyleForm           Style = \"form\"\n\tStyleSpaceDelimited Style = \"spaceDelimited\"\n\tStylePipeDelimited  Style = \"pipeDelimited\"\n\tStyleDeepObject     Style = \"deepObject\"\n\tStyleCookie         Style = \"cookie\"\n)\n```\n\n```go\ntype Union struct {\n\tIsAnyOf       bool\n\tDiscriminator string\n\tIsLiteral     bool\n\tShared        []string\n\tVariants      []Variant\n\tAlso          []Union\n}\n```\nUnion 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.\n\n```go\ntype Variant struct {\n\tName      string\n\tKind      Kind\n\tValues    []string\n\tIsDefault bool\n\tIsAbsent  bool\n\tRequired  []string\n\tKnown     []string\n\tIsClosed  bool\n\tShapes    []Shape\n\tInto      Setter\n}\n```\nVariant 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.\n\n","path":"github.com/mockzilla/mockzilla-codegen/pkg/runtime","name":"runtime","synopsis":"Package runtime holds the helpers generated code imports.","isRedistributable":true}
