Skip to main content

Module binding_schema

Module binding_schema 

Source
Expand description

Checks a custom binding’s fields against the outputs schema its type’s descriptor carries.

The schemas come from utoipa, through the extension SDK: objects with properties and required, $refs into $defs, oneOf for an optional struct, enum for a unit enum, and the numeric and string bounds Rust’s types imply. The check reads exactly the keywords below. A schema that uses any other keyword refuses the binding, naming the keyword, so a binding is never accepted against a rule the check skipped.

One rule is stricter than JSON Schema: an object field its schema doesn’t name is refused unless additionalProperties allows it, so a misspelled output is caught. A field one allOf branch names, as #[serde(flatten)] writes, counts as named in every branch.

The check is hand-written rather than the jsonschema crate’s because alien-core builds for wasm32-wasip1, and that crate pulls in reqwest, fancy-regex and idna.

Constants§

FLATTENED_MAP
Why flattens_a_map_beside_fields refuses an outputs schema.
FLATTENED_OPTION
Why flattens_alternatives refuses an outputs schema.

Functions§

flattens_a_map_beside_fields
Whether an outputs schema flattens a map beside a struct’s fields anywhere: utoipa writes it as an allOf where one branch allows any other field and another names its own. The check reads each branch alone, so the struct’s branch would refuse every key of the map. A struct that itself flattens a struct names its fields through its own allOf, not properties.
flattens_alternatives
Whether an outputs schema flattens an Option or an enum anywhere: in the outputs or in any type they use. utoipa writes #[serde(flatten)] Option<S> as an allOf branch with a oneOf of null and S, and a flattened enum as one with a oneOf of its variants. Which fields an object of it carries depends on the value, so the check can’t tell a misspelled field from one of them.
output_names
The outputs a type’s outputs schema names, which a custom binding of the type carries as fields: its root properties and those of its allOf branches, through $refs, as #[serde(flatten)] writes them.