fix(openapi-typescript): redundant nested unions from type arrays with anyOf/allOf - #2855
Open
sovrin-tio wants to merge 2 commits into
Open
fix(openapi-typescript): redundant nested unions from type arrays with anyOf/allOf#2855sovrin-tio wants to merge 2 commits into
sovrin-tio wants to merge 2 commits into
Conversation
…rray recursion transformSchemaObjectCore spreads the full schema object into each per-type recursive call, so a sibling anyOf/allOf is transformed once per primitive type member and again at the top level, yielding redundant nested unions like ((string | null) | null) | string | null. Extend the existing `oneOf: undefined` guard to anyOf/allOf, but only for primitive members. object/array members need the composition, since stripping it collapses the core to Record<string, never> and widens the union.
that branch stripped only oneOf, so a sibling anyOf/allOf still stacked. Both branches now share one transformTypeMember helper.
🦋 Changeset detectedLatest commit: f1420f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
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.
Changes
Each member of a
typearray gets its own recursivetransformSchemaObjectcall, spreadfrom the full schema object. A sibling
anyOfcomes along for the ride and getstransformed inside every member, on top of the top-level pass:
{ "type": ["string","null"], "anyOf": [{"type":"string","format":"ipv4"},{"type":"null"}] }allOfhas the same problem.{"type":["string","null"],"allOf":[{"type":"string"}]}gave
((string) | null) & string, now(string | null) & string.There are two of these loops, one for schemas with a
oneOfand one for everything else.The
oneOfloop already blankedoneOfbefore recursing but notanyOf/allOf, soschemas carrying both were still broken. Both loops now call the same
transformTypeMemberhelper.How to Review
anyOf/allOfare stripped only for primitive members. Object and array members keepthem: there the composition carries the shape, and stripping leaves
Record<string, never>/unknown[], which widens the union. Tests cover both.One example line changes, narrower than before:
The
oneOfhalf changes no example output — no schema inexamples/hits thatcombination. Unit-tested only.
Checklist
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)