Skip to content

Conversation

@thesandlord
Copy link
Contributor

@thesandlord thesandlord commented Jan 23, 2026

Description

Refs: Related to fern-platform PR #6485

Fixes OpenAPI oneOf schemas with discriminator being incorrectly parsed as undiscriminated unions when the discriminant property is defined in each variant schema (which is the standard OpenAPI pattern).

Changes Made

  • Modified OneOfSchemaConverter.ts to always parse oneOf with discriminator as a discriminated union, regardless of whether the discriminant property exists in variant schemas
  • Added filterDiscriminantFromSchema() method to remove redeclared discriminant properties from variant schemas, keeping the union properly discriminated without duplicate properties
  • When a variant schema contains the discriminant property, it's now filtered out and the schema is converted as an inlined type with the original type ID
  • Updated test snapshots to reflect the new discriminated union output format

Context

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:

  1. Always converts oneOf with discriminator as a discriminated union
  2. Filters out the discriminant property from variant schemas when it's redeclared
  3. Preserves the original type IDs so SDK type names remain unchanged

Testing

  • Existing unit tests pass (v3-importer-commons)
  • Snapshot tests updated for v3-sdks.test.ts
  • Snapshot tests updated for openapi-from-flag.test.ts
  • Lint checks passing

Human Review Checklist

  • Verify the filterDiscriminantFromSchema logic correctly handles the required array
  • Check if schemas with allOf compositions are handled correctly when filtering
  • Verify the unionVariantsContainLiteral function can be removed (now unused)
  • Confirm generated SDKs work correctly with the filtered variant schemas

Link to Devin run: https://app.devin.ai/sessions/f05a2106646045aa9c97af3bf986fbec
Requested by: Sandeep Dinesh (@thesandlord)

Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@thesandlord thesandlord requested a review from dsinghvi January 23, 2026 00:24
devin-ai-integration bot and others added 4 commits January 23, 2026 00:28
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
…scriminated unions

When OpenAPI specs redeclare the discriminant property in variant schemas,
filter it out instead of converting to an undiscriminated union. This keeps
the discriminated union semantics while avoiding duplicate discriminant properties.

Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
Co-Authored-By: Sandeep Dinesh <sandeep@buildwithfern.com>
@thesandlord thesandlord enabled auto-merge (squash) January 28, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants