Skip to content

fix(generator): preserve union input and nullable results - #83

Merged
lightsofapollo merged 7 commits into
mainfrom
fix/union-wire-equivalence-guard-b2y
Sep 25, 2026
Merged

lightsofapollo merged 7 commits into
mainfrom
fix/union-wire-equivalence-guard-b2y

Conversation

@lightsofapollo

@lightsofapollo lightsofapollo commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This branch starts from #82 and retains @gilesw's original commits. It fixes two issues found while reviewing and running the full corpus:

  • The wire-equivalent oneOf/anyOf fallback no longer accepts a branch that adds a serialized key. A required, defaulted mode field previously accepted {} and re-encoded it as {"mode":""}.
  • A property whose anyOf branches allow null is now generated as nullable. Cloudflare returned valid result: null values that the previous Rust model could not deserialize. For oneOf, the property admits null only when exactly one branch does.

Generated-runtime regressions, existing union expectations, and the 56-spec corpus manifest are updated. This PR can replace #82 as the merge candidate; it includes all three commits from that PR.

Verification

  • Standard PR CI on the current head is green: tests, fmt, clippy, docs, MSRV, corpus diff, spec smoke, SDK compatibility, and install smoke.
  • Local full scripts/spec-compile.sh: 55 passed, 0 generation/compile/roundtrip failures; 28,139 of 29,045 component schemas exercised with 103,031 samples. Gitea was skipped as Swagger 2.0. Microsoft Graph generated successfully but is generate-only in this script.
  • Separate local cargo check of the generated Microsoft Graph crate passed on a machine with sufficient memory.
  • Focused generated-runtime union tests and Cloudflare's 19,461-sample roundtrip passed.

The manual GitHub full-spec job stopped with exit 143 during Cloudflare in three attempts, without a Rust diagnostic. Removing debug symbols and incremental artifacts did not resolve it, so that workflow experiment was reverted. The runner-capacity issue is tracked as openapi-generator-bh9; the successful local full run provides the complete compile result for this PR.

Tracking

The correctness fixes are tracked as openapi-generator-b2y and openapi-generator-v1s. Consolidating the repeated generated comparison helper is tracked as openapi-generator-wwr.

gilesw and others added 4 commits September 25, 2026 10:47
…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.
@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openapi-to-rust Ready Ready Preview Sep 25, 2026 6:03pm UTC

Request Review

Treat nullable anyOf branches as admitting null and respect oneOf uniqueness when inferring property nullability. Cover Cloudflare-style required null results and refresh generated corpus expectations.
Compile generated scratch crates without debug symbols or incremental artifacts so Cloudflare can fit on a standard GitHub runner.
@lightsofapollo lightsofapollo changed the title fix(generator): preserve complete input in wire-equivalent union matching fix(generator): preserve union input and nullable results Sep 25, 2026
@lightsofapollo
lightsofapollo merged commit 4a89594 into main Sep 25, 2026
14 checks passed

This branch was successfully deployed

1 active deployment
Preview — 91cf25e7 Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants