Skip to main content
Enums with unit variants encode as strings. Enums with fields can encode as objects with an explicit discriminator:
Inputs include {"kind":"search","query":"Rust"} and {"kind":"ping"}. The generated schema uses oneOf, const, and explicit required fields.

Tuple structs and untagged enums

Newtypes encode as their inner value, multiple tuple fields encode as fixed-length arrays, unit structs encode as null, and empty tuple structs encode as []. Tuple fields support validation and coercion. Names, defaults, flattening, and exclusion apply to named fields. Untagged enums try variants in declaration order and select the first one that passes synchronous validation. Failure returns union_no_match with structured errors for each branch; the schema uses anyOf. Asynchronous validation then checks the selected branch. Internally tagged enums use named fields or unit variants.

Flattening and extra fields

Flattening supports named models, Option/Box wrappers, and string-keyed BTreeMap/HashMap. Parsing consumes declared fields first, flattened fields next, and finally sends remaining keys to a capture map. Multiple flattened fixed objects are supported, with one field per level allowed to capture unknown keys. extra = "allow" requires an explicit #[model(extra)] map, whose values are also type-checked. Optional flattened fields become None when all their keys are absent; partially present objects are checked for required inner fields. Empty flattened input can trigger an explicit default. Error locations follow the flattened JSON paths. Input/output names of declared fields are preserved; overlapping extra keys return field_collision, and serialization also checks for key collisions when merging objects.