Fix recursive union flattening#2891
Merged
Merged
Conversation
schani
force-pushed
the
fix-recursive-union-flattening
branch
7 times, most recently
from
July 7, 2026 22:22
081f00c to
952d5e9
Compare
schani
force-pushed
the
fix-recursive-union-flattening
branch
from
July 7, 2026 22:36
952d5e9 to
5353e8d
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
flattenUnionsrecursively unify nested unions while memoizing normalized union member keys to close cyclesFixes #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:
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.tsnode dist/index.js --src-lang schema /tmp/qt-issues/fhir.schema.json --lang rust --out /tmp/qt-issues/fhir.rsValidation
npm run buildQUICKTEST=true FIXTURE=schema-typescript,schema-typescript-zod npm test -- test/inputs/schema/recursive-union-flattening.schemaQUICKTEST=true FIXTURE=schema-kotlin,schema-kotlin-jackson npm test -- test/inputs/schema/recursive-union-flattening.schemaQUICKTEST=true FIXTURE=schema-cjson npm test -- test/inputs/schema/recursive-union-flattening.schemaQUICKTEST=true FIXTURE=schema-cplusplus npm test -- test/inputs/schema/recursive-union-flattening.schemaQUICKTEST=true FIXTURE=schema-elixir npm test -- test/inputs/schema/recursive-union-flattening.schemaattempted locally but blocked becausemixis not installed; skip verified by inspection and CI will validate with Elixir installednode dist/index.js --src-lang schema /tmp/bug.min.schema --lang typescript --no-rendernode dist/index.js --src-lang schema /tmp/bug.schema --lang typescript --no-renderQUICKTEST=true FIXTURE=typescript npm test -- test/inputs/json/samples/pokedex.jsonnode 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.tsnode dist/index.js --src-lang schema /tmp/qt-issues/fhir.schema.json --lang rust --no-rendernode dist/index.js --src-lang schema /tmp/qt-issues/fhir.schema.json --lang rust --out /tmp/qt-issues/fhir.rsC# schema-output comparison vs master
Generated C# for all 65 schemas under
test/inputs/schemausing both this PR andmaster.recursive-union-flattening.schemafails with the original stack-overflow bug.vega-lite.schema: this PR collapses a duplicate recursiveSpecClass/Specsplit into a single recursiveSpectype, plus removes one merged doc-comment fragment.C# JSON-output comparison vs master
Generated C# for all 210 JSON files under
test/inputs/jsonusing both this PR andmaster.master.