fix(cli): parse OpenAPI oneOf with discriminator as discriminated union #11704
+1,249
−752
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.
Description
Refs: Related to fern-platform PR #6485
Fixes OpenAPI
oneOfschemas withdiscriminatorbeing incorrectly parsed as undiscriminated unions when the discriminant property is defined in each variant schema (which is the standard OpenAPI pattern).Changes Made
OneOfSchemaConverter.tsto always parseoneOfwithdiscriminatoras a discriminated union, regardless of whether the discriminant property exists in variant schemasfilterDiscriminantFromSchema()method to remove redeclared discriminant properties from variant schemas, keeping the union properly discriminated without duplicate propertiesContext
The previous logic (from PR #6738) checked if variant schemas contained the discriminant property, and if they did, it would convert to
undiscriminatedUnion(). This was a workaround to avoid duplicate discriminant properties, but it lost the discriminated union semantics.The new approach:
oneOfwithdiscriminatoras a discriminated unionTesting
Human Review Checklist
filterDiscriminantFromSchemalogic correctly handles therequiredarrayallOfcompositions are handled correctly when filteringunionVariantsContainLiteralfunction can be removed (now unused)Link to Devin run: https://app.devin.ai/sessions/f05a2106646045aa9c97af3bf986fbec
Requested by: Sandeep Dinesh (@thesandlord)