Skip to content

fix: keep object shape under conditional allOf; stop double-printing error sources - #113

Merged
lightsofapollo merged 2 commits into
mainfrom
fix/111-112-allof-conditionals-error-sources
Oct 29, 2026
Merged

lightsofapollo merged 2 commits into
mainfrom
fix/111-112-allof-conditionals-error-sources

Conversation

@lightsofapollo

Copy link
Copy Markdown
Contributor

Closes #111
Closes #112

#111 — conditional allOf turned objects into serde_json::Value

Root cause: analyze_allof_composition collapsed a single-member allOf to that member without checking the owner's own type: object / properties. A lone if/then member is untyped, so Cat became serde_json::Value; branch_resolves_to_object then saw a non-object branch and untagged Pet.

The same blind spot hit {type: object, properties: {...}, allOf: [$ref Base]}: it became pub type X = Base, silently dropping the owner's fields. This affects real specs: e.g. Cloudflare DnsRecordsDnsRecordBatchPatch lost its required id, and gcore DirectoryItem lost item_type/items_count.

Fix:

  • allOf members holding only if/then/else (+ annotations) are value rules, not shape, and are dropped from composition.
  • An owner with its own properties always keeps its object shape.
  • branch_resolves_to_object treats an allOf owner with type: object or own properties as an object.

The issue's spec now generates byte-identical output to the same spec without the allOf.

#112 — error chains printed causes twice

Root cause: #[from] variants also formatted the source with {0}. Fixed in generated HttpError::{Network, Middleware} and StreamingError::Json, plus this crate's GeneratorError, HttpError and server edit errors. The CLI and wasm playground printed only the top-level Display, so they now render the chain via a new error::error_chain helper (no lost context).

Behavior change: callers printing a generated HttpError with plain {} now see e.g. Network error; walk source() (or use a chain reporter) for the cause. Noted in CHANGELOG.

Tests

  • tests/allof_conditional_member_test.rs — issue repro, inline branch, owner props + $ref, owner props + untyped member, $ref + conditional alias, and generated-code equality vs. the spec without the rule. All 5 fail on main.
  • tests/error_source_display_test.rs — syn-parses every generated file (client, SSE/streaming) and the crate's own error modules and fails on any variant that formats its #[from]/#[source] field; plus a chain rendering check. Fails on main.
  • Full suite: 756 passed (nextest --profile ci --all-features) + doctests.
  • scripts/gen-diff.sh main: 56 specs change; 54 only in error message text, cloudflare + gcore also gain the dropped fields above. spec-compile.sh cloudflare gcore passes compile + round trip.
  • examples/generated/ (linked in double logging when printing error chains #112) regenerated; it was stale beyond this change.

🤖 Generated with Claude Code

…error sources

#111: an object schema whose allOf held only if/then/else rules collapsed to
serde_json::Value, untagging any discriminated oneOf it was a branch of. The
allOf shortcuts ignored the owner's own properties, so a single untyped or
$ref member replaced the whole schema (Cloudflare and gcore lost required and
optional fields this way). Conditional-only members no longer shape the
composed type, owners with their own properties keep their object shape, and
branch_resolves_to_object treats such owners as objects.

#112: error variants wrapping a source via #[from] also formatted it with {0},
so chain reporters printed every cause twice. Generated HttpError and
StreamingError, plus this crate's error types, now leave the source out of
their messages. The CLI and wasm playground render the full chain with the
new error::error_chain helper.

Closes #111
Closes #112

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 29, 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 Oct 29, 2026 8:46pm UTC

Request Review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lightsofapollo
lightsofapollo merged commit d5ff348 into main Oct 29, 2026
14 checks passed
@lightsofapollo
lightsofapollo deleted the fix/111-112-allof-conditionals-error-sources branch October 29, 2026 21:05

This branch was successfully deployed

1 active deployment
Preview — fcd78dc0 Deployed Oct 29, 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

1 participant