fix(@effect/platform): flatten anyOf when accumulating same-content-type union payloads#6207
Open
Zelys-DFKH wants to merge 1 commit intoEffect-TS:mainfrom
Open
Conversation
…ype union payloads OpenApi.fromApi was emitting nested anyOf arrays for flat unions passed to setPayload when all members share the same content type. Each new member was wrapped via AST.Union.make([current, next]), creating left-nested Union nodes that the JSON Schema encoder preserved as nested anyOf. The fix replaces that call with HttpApiSchema.UnionUnifyAST, which already existed and is already used by the response-map accumulator for the same purpose. It flattens both sides via extractUnionTypes before creating the final Union node. Fixes Effect-TS#6052
🦋 Changeset detectedLatest commit: 15ea876 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
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 |
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.
Type
Description
OpenApi.fromApiemits nestedanyOfwhensetPayloadreceives a union where all members share the same content type. For example,Schema.Union(A, B, C)where all three are JSON structs producesanyOf: [ anyOf: [A, B], C ]instead of the expected flatanyOf: [A, B, C].Root cause
extractPayloadsaccumulates same-content-type members withAST.Union.make([current.ast, ast])on each pass. That builds a left-nested union tree —Union([Union([A, B]), C])— which the JSON Schema encoder faithfully reflects as nestedanyOf.Fix
One line: replace
AST.Union.make([current.ast, ast])withHttpApiSchema.UnionUnifyAST(current.ast, ast).UnionUnifyASTis already in the package and is already used for the same reason by the response-map accumulator (extractResponseMap, line 382). It flattens both sides throughextractUnionTypesbefore creating the Union node, so the result stays flat no matter how many members land on the same content type. The asymmetry between the two accumulators is what introduced the bug.Tests
Adds one test to
packages/platform/test/OpenApi.test.ts:Schema.Union(A, B, C)(three JSON structs) on a POST endpoint produces a flatanyOf: [A, B, C]in the generated spec, not nested.Related