Skip to main content

ref_wrapper_object

Function ref_wrapper_object 

Source
pub fn ref_wrapper_object(schema: &mut Schema)
Expand description

Schema transform (for #[schemars(transform = ...)]): inserts a top-level "type": "object" alongside whatever the schema already holds.

Applied to single-variant #[serde(untagged)] enums. schemars emits such an enum as a single-variant anyOf, which the json-schema builder then flattens (merging the lone variant’s $ref into the parent) down to a bare $ref. The SDK code generators (Go, TS) inline a bare top-level $ref instead of emitting a reference, which breaks the JSON-Schema roundtrip tests. Adding a sibling "type": "object" yields the {type: object, $ref} ref-wrapper shape the generators already round-trip cleanly (the same shape flatten_schema produces for a flattened struct field), and which the builder’s guarantees allow (type + $ref siblings are fine; only anyOf + $ref is not).