fix(generator): accept wire-equivalent encodings when selecting a union branch - #82
Merged
lightsofapollo merged 3 commits intoSep 25, 2026
Merged
Conversation
…on branch Union deserializers keep a branch only if re-serializing it reproduces the input. An integer in a `number` field (re-encoded as `1.0`) and an explicit `null` for an optional field (skipped on output) both failed that check, so every Cloudflare DNS record was rejected. oneOf compared with strict equality, and anyOf treated an input null as lost. Both now fall back to a comparison that treats those encodings as equal, but only when no branch reproduces the input exactly, so inputs that decoded before keep their branch and ambiguity is still reported.
|
@gilesw is attempting to deploy a commit to the lbl-rd Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
incorporating these changes into #83 - Thanks for the report + pr ! |
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
Union deserializers keep a branch only when re-serializing it reproduces the input. Two encodings that lose no information failed that check:
numberfield:"ttl": 1decodes intof64and re-encodes as1.0nullfor an optional field:"comment": nulldecodes toNone, which is skipped on outputoneOfcompared with strict==, so it failed on both;anyOfalready tolerated the numeric case but treated an inputnullas lost. Together they reject every record of the Cloudflare DNS API, which types its integers asnumberand returnsnullfor optional fields. For example,GET /zones/{zone_id}/dns_records/{dns_record_id}fails with:This PR keeps exact matching as the first pass. Only when no branch reproduces the input exactly does it accept a branch whose encoding differs solely by those two forms. Several equivalent
oneOfbranches are still reported as ambiguous.Generated compatibility
gen-diff.shreports 0 public items added or removed across the corpus.Validation
tests/union_branch_wire_equivalence_test.rs, a reduced Cloudflare-shapedallOf+anyOf+oneOfrecord. Three cases failed before the change. A guard case checks that aoneOfofintegervsnumberbranches still selectsintegerfor1andnumberfor1.5.tools_arrayunion snapshots change only in the generated deserializer.cargo fmt --checkcargo clippy --all-features -- -D warningscargo nextest run --all-features(681 run, all pass after the snapshot update), pluscargo test --doc --all-featuresandcargo docwith-Dwarningsscripts/spec-compile.sh anthropic openai: both PASS + ROUNDTRIPtests/corpus-manifest.txt;--checkis cleanNotes for reviewers
oneOfdeserializers now carry the same inline comparison helpers thatanyOfdeserializers already emit. That is most of thegen-diff.shchurn (38 specs; for example vercel +83k/−27k lines, cloudflare +17k/−7k). If you would prefer it, I'm happy to follow up by emitting these helpers once pertypes.rsas a private module, in the same way astri_state_serde. That would shrink output below today's size for both union kinds. I kept this PR to the behavior change.quote!attempt blocks,no_match, andpreserves_complete_json_inputinsrc/generator.rs; then the new test.numbertypes.