Repository navigation
fix: preserve Rust untagged-union member payloads - #174
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
adamcavendish
force-pushed
the
adamcavendish/rust-union-selection
branch
from
November 11, 2026 07:13
ce2e8e8 to
e1e2988
Compare
- Match retained scalar enum and structural facts before choosing a Rust union member, preventing unconstrained integer fields from swallowing later payloads. - Share firstMatch, strict, and explicit raw policies across reqwest, ureq, and aioduct while retaining typed variants and untagged serialization by default. - Count authored concrete candidates before opaque fallbacks and deserialize the selected member once, retaining nested errors and recursive boundaries. - Memoize recursive shape/node results during selection to avoid exponential subtree scans without changing candidate order or caching across decoded values. - Keep exact large-integer comparisons, nullable finite constraints, native byte arrays, and concrete entries in open recursive dictionaries during selection. - Emit union declarations and serde/utoipa methods structurally; normalize owned derive paths, including absolute names, without duplicate trait implementations. - Propagate tagged model emission errors with their original model/source context instead of silently dropping failed output. - Retain native model and HTTP consumer regressions, exact renders, and all three Rust golden suites without changing other languages or broader model codecs.
adamcavendish
force-pushed
the
adamcavendish/rust-union-selection
branch
from
November 11, 2026 10:20
e1e2988 to
07cd3e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix enum-aware untagged-union member selection in all three Rust backends:
reqwest, ureq, and aioduct. Correctly select the declared member and retain its
payload through properties, containers, recursive models, and HTTP responses.
Problem
Serde's derived untagged dispatch tries members whose constrained numeric fields
are still ordinary Rust integers. For a union of
revision: enum [1]andrevision: enum [2],{"revision":2,"second_value":"two"}previously selected thefirst member and re-encoded as
{"revision":2}. Direct member decoding worked;the union silently discarded the actual member's payload.
Behavior
firstMatch(default)strictrawRaw(serde_json::Value)and preserve known, unmatched, or null JSON.Matching consumes shared IR facts: required wire keys, scalar finite constraints,
nested arrays/maps, null boundaries, and productive recursive references. Numeric
enum comparisons retain integer precision above 2^53. Recursive checks share
shape/node results within one selection, avoiding exponential subtree scans
without changing candidate order or sharing cached results across decoded values.
Common union derives and per-type overrides accept equivalent short,
crate-qualified, and absolute Serde/utoipa paths without duplicating owned
implementations. Tagged model emission failures preserve the underlying
diagnostic and model context rather than silently omitting the model.
Compatibility and boundaries
unchanged. Deserialization no longer accepts a member whose retained enum or
structural constraints do not match. Explicit raw mode changes the union API.
still applies after selection; ordinary model serialization/validation is not
redesigned. The shared Rust generator config gains
untagged_union_strategy.NullorRawvariant is added to typed enums. Explicit nullableuse sites retain
Option<Union>; named root-nullable union representation andautomatic reference nullability are unchanged.
multi-member
allOfredesign remain separate. Use raw mode to retain arbitraryunion JSON rather than relying on a typed member to preserve unknown fields.
added shared-matcher metadata; Java, Kotlin, Go, and TypeScript are unchanged.