fix(zod): fall back to z.union() when discriminated union members are ZodIntersection#3813
fix(zod): fall back to z.union() when discriminated union members are ZodIntersection#3813
z.union() when discriminated union members are ZodIntersection#3813Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
TL;DR — This PR is a WIP placeholder with no code changes yet. It was opened by Copilot to address #3811, which reports TypeScript errors when using Key changes
Summary | 0 files | 1 commit | base: |
There was a problem hiding this comment.
This is a draft WIP PR with zero code changes — the only commit ("Initial plan") contains no file modifications. There is nothing to review yet. Will re-review once implementation commits are pushed.
Task list (3/3 completed)
- Read the PR diff and metadata
- Analyze the PR content and identify issues
- Submit review
… intersections When discriminated union members have allOf schemas, they generate ZodIntersection which does not support .extend(). Detect this case by storing isIntersection: true in the symbol meta and fall back to z.union() in tryBuildDiscriminatedUnion. - Add isIntersection field to ZodMeta type - Set isIntersection: true in intersection() handler of all three walkers - Set isIntersection: false in union() handler (manual meta) of all three walkers - Merge ctx.meta with isIntersection flag in processor exportAst calls - Check querySymbol meta for isIntersection in tryBuildDiscriminatedUnion - Add test specs and snapshots for the discriminator-allof-member scenario Agent-Logs-Url: https://github.com/hey-api/openapi-ts/sessions/1c6f992d-8feb-49c9-9cc6-7830259cfe5c
z.union() when discriminated union members are ZodIntersection
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3813 +/- ##
==========================================
- Coverage 39.84% 39.82% -0.02%
==========================================
Files 530 530
Lines 19475 19481 +6
Branches 5802 5814 +12
==========================================
Hits 7759 7759
- Misses 9485 9489 +4
- Partials 2231 2233 +2
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/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |

Calling
.extend()on aZodIntersection(produced byallOfschemas) is a TypeScript error. When a discriminated union's member schemas useallOfinheritance, the generatedz.discriminatedUnion(...).extend(...)pattern fails to type-check.Before (broken):
After (fixed):
Changes
shared/types.ts— addisIntersection: booleantoZodMetashared/meta.ts— includeisIntersection: falseindefaultMeta/composeMetav3/v4/mini walker.ts— setisIntersection: truein theintersection()handler; addisIntersection: falseto manually constructed union meta objectsv3/v4/mini processor.ts— mergectx.meta(carriesresource/resourceId) with{ isIntersection: true }when exporting intersection schemas, so the flag is stored on the registered symbolshared/discriminated-union.ts— before calling.extend(), query the ref symbol's meta; ifisIntersection === true, returnnullto triggerz.union()fallbackdiscriminator-allof-member.yamlspecs for OpenAPI 3.0.x and 3.1.x with corresponding snapshots asserting thez.union()outputWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/opt/hostedtoolcache/node/24.15.0/x64/bin/node /opt/hostedtoolcache/node/24.15.0/x64/bin/node /home/REDACTED/work/openapi-ts/openapi-ts/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/jest-worker/processChild.js packages/shared/nuxt-module-build build /systemd-executor dules/.bin/../vue-tsc/bin/vue-tsc.js submodules | head -n 10 packages/shared/src/openApi/shared/transforms/index.ts cal/bin/bash packages/shared/sh packages/shared/-c packages/shared/next build bash --no�� --noprofile napi-ts/packages/openapi-ts/src/plugins/ tools/pnpm/10.33.0/bin/node(dns block)/opt/hostedtoolcache/node/24.15.0/x64/bin/node /opt/hostedtoolcache/node/24.15.0/x64/bin/node /home/REDACTED/work/openapi-ts/openapi-ts/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/jest-worker/processChild.js(dns block)If you need me to access, download, or install something from one of these locations, you can either: