feat(transformers): generate proper transformers for discriminated unions#3298
Conversation
…ions Add support for generating runtime transformers for OpenAPI discriminated unions (oneOf/anyOf with discriminator). Previously, the transformers plugin would emit "schema is too complex" warnings and skip transformer generation for these schemas. Changes: - Add detectDiscriminatedUnion() to identify discriminated union patterns in the IR schema (logicalOperator: 'or' with 'and' items containing const discriminator values) - Add processDiscriminatedUnion() to generate if-else chains that switch on the discriminator property value and call variant-specific transformers - Add comprehensive test spec covering oneOf, anyOf, nested objects with dates, arrays of discriminated unions, and nested discriminated unions The generated transformers now properly: - Transform date-time fields to Date objects in each variant - Transform int64 fields to BigInt in each variant - Handle optional date fields with null checks - Handle nested objects containing dates - Handle arrays of discriminated unions - Handle containers with nested discriminated union fields Fixes hey-api#1636, hey-api#1613 https://claude.ai/code/session_015NvA9dsXMVRLR18NMorwgd
|
|
|
@claude is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
|
|
Interesting - I see Copilot in a similar area in #3296 ? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3298 +/- ##
==========================================
- Coverage 34.91% 34.74% -0.17%
==========================================
Files 401 401
Lines 22237 22346 +109
Branches 1429 1429
==========================================
+ Hits 7763 7765 +2
- Misses 14470 14577 +107
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@hey-api/codegen-core
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/types
@hey-api/vite-plugin
commit: |
|
Yeah, GitHub was down again. I'll rerun it later and see what it comes up with and we can compare. Are you using Zod btw? There are other issues around this, we could use Zod as a transformer. Would that be desirable for you too? |
Ye - all Zod |
|
@lukeramsden which transforms do you need? dates? bigint? Other? |
|
@lukeramsden does this preview build work for you? #3301 |
dates is the main one |
will try to check if i get time but the test cases in this PR (#3298) are representative of my usecase so if the preview build works for those then all good |
Add support for generating runtime transformers for OpenAPI discriminated
unions (oneOf/anyOf with discriminator). Previously, the transformers plugin
would emit "schema is too complex" warnings and skip transformer generation
for these schemas.
Changes:
in the IR schema (logicalOperator: 'or' with 'and' items containing
const discriminator values)
on the discriminator property value and call variant-specific transformers
dates, arrays of discriminated unions, and nested discriminated unions
The generated transformers now properly:
Fixes #1636, #1613
Had Claude do a first pass at this because this is something we run in to in our codebase. Started from a fairly detailed prompt describing the specific issue I was having. Not super familiar with your codebase so let me know if this is the right approach :)