decode

package
v0.13.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package decode is how apikit reads an op's input and checks its output, against the schemas huma generates from the Go types. It is internal to apikit: hosts and their ops never see huma's validator or the message rules.

It owns huma's process-wide configuration, set in init. apikit imports this package, so the settings are in place before any schema is generated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckOutput

func CheckOutput(reg huma.Registry, t reflect.Type, out any) error

CheckOutput reports where out does not match the schema of type t: a nil slice encoded as null where the schema says list, an empty required field, an out-of-enum value. The op layer calls it in strict mode, so the OpenAPI built from the types cannot quietly lie about what an op returns.

func ExactlyOne

func ExactlyOne(fields []string) []*huma.Schema

ExactlyOne is the schema of a group of fields of which exactly one must be set, for an object's schema to carry in OneOf (or, for several groups, one per AllOf entry): a oneOf over each field being required. A JSON Schema reader sees the rule; apikit reads the group back from it, to say which fields to set.

func Input

func Input[In any](reg huma.Registry, raw []byte) (In, error)

Input validates raw against In's schema and decodes it. Structural problems are invalid_request, with one violation per location; a field path is the caller's (`invitations[1].role`), with no transport prefix. An empty body is an empty object, so an op whose fields are all optional can be called with none.

func InputTo

func InputTo[In any](reg huma.Registry, schema *huma.Schema, raw []byte) (In, error)

InputTo is Input against a schema given rather than reflected from In: an engine command's, built from what the engine describes at run time, with In a map of its args.

func IsEmpty

func IsEmpty(t reflect.Type) bool

IsEmpty reports the empty struct, struct{}.

func SchemaOf

func SchemaOf(reg huma.Registry, t reflect.Type) *huma.Schema

SchemaOf is t's schema: a reference into reg for a named type, which reg registers under the type's name. The empty struct — an op with no input or no output — has no name to register under, so its schema is an inline empty object rather than a nameless entry: a reference to "#/components/schemas/" with no name would resolve to the whole map. Any other unnamed struct is refused at registration (apikit.Register), for the same reason.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL