Skip to content

Fix recursive union flattening#2891

Merged
schani merged 1 commit into
masterfrom
fix-recursive-union-flattening
Jul 7, 2026
Merged

Fix recursive union flattening#2891
schani merged 1 commit into
masterfrom
fix-recursive-union-flattening

Conversation

@schani

@schani schani commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • make flattenUnions recursively unify nested unions while memoizing normalized union member keys to close cycles
  • add a high-level code comment explaining why the local normalized-union memo is needed
  • preserve the old fallback for nested intersections so intersection resolution can still handle them in a later pass
  • add the issue Does not generate from opds2 schema #2187 minimized schema as a normal schema fixture input, with a JSON sample
  • skip that regression schema for Kotlin/Kotlin-Jackson, cJSON, C++, Elixir, and TypeScript-Zod schema fixtures because those fixtures already have limitations around top-level primitive/union/recursive alias cases
  • the plain TypeScript schema fixture still runs the schema and sample

Fixes #2187
Fixes #1376

Verified real-world crash schemas

These are the two large schemas from #2890 that originally motivated this crash investigation. Both now generate successfully with this PR:

Validation

  • npm run build
  • QUICKTEST=true FIXTURE=schema-typescript,schema-typescript-zod npm test -- test/inputs/schema/recursive-union-flattening.schema
  • QUICKTEST=true FIXTURE=schema-kotlin,schema-kotlin-jackson npm test -- test/inputs/schema/recursive-union-flattening.schema
  • QUICKTEST=true FIXTURE=schema-cjson npm test -- test/inputs/schema/recursive-union-flattening.schema
  • QUICKTEST=true FIXTURE=schema-cplusplus npm test -- test/inputs/schema/recursive-union-flattening.schema
  • QUICKTEST=true FIXTURE=schema-elixir npm test -- test/inputs/schema/recursive-union-flattening.schema attempted locally but blocked because mix is not installed; skip verified by inspection and CI will validate with Elixir installed
  • node dist/index.js --src-lang schema /tmp/bug.min.schema --lang typescript --no-render
  • node dist/index.js --src-lang schema /tmp/bug.schema --lang typescript --no-render
  • QUICKTEST=true FIXTURE=typescript npm test -- test/inputs/json/samples/pokedex.json
  • node dist/index.js --src-lang schema https://raw.githubusercontent.com/opds-community/specs/master/schema/feed.schema.json --lang typescript --out /tmp/qt-issues/opds.ts
  • node dist/index.js --src-lang schema /tmp/qt-issues/fhir.schema.json --lang rust --no-render
  • node dist/index.js --src-lang schema /tmp/qt-issues/fhir.schema.json --lang rust --out /tmp/qt-issues/fhir.rs

C# schema-output comparison vs master

Generated C# for all 65 schemas under test/inputs/schema using both this PR and master.

  • PR: 65/65 schemas generated successfully.
  • master: 64/65 schemas generated successfully; recursive-union-flattening.schema fails with the original stack-overflow bug.
  • Among the 64 schemas generated by both branches, 63 outputs are byte-for-byte identical.
  • The only existing-schema output difference is vega-lite.schema: this PR collapses a duplicate recursive SpecClass/Spec split into a single recursive Spec type, plus removes one merged doc-comment fragment.

C# JSON-output comparison vs master

Generated C# for all 210 JSON files under test/inputs/json using both this PR and master.

  • PR: 210/210 JSON inputs generated successfully.
  • master: 210/210 JSON inputs generated successfully.
  • All 210 generated C# outputs are byte-for-byte identical between this PR and master.

@schani
schani force-pushed the fix-recursive-union-flattening branch 7 times, most recently from 081f00c to 952d5e9 Compare July 7, 2026 22:22
@schani
schani force-pushed the fix-recursive-union-flattening branch from 952d5e9 to 5353e8d Compare July 7, 2026 22:36
@schani
schani merged commit acc460e into master Jul 7, 2026
22 checks passed
@schani
schani deleted the fix-recursive-union-flattening branch July 7, 2026 23:08
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.

Does not generate from opds2 schema Maximum call stack size exceeded when generating Rust from large FHIR JSON Schema

1 participant