-
-
Notifications
You must be signed in to change notification settings - Fork 526
fix(zod): fixed missing oneOf and common property combinations for zod
#2672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(zod): fixed missing oneOf and common property combinations for zod
#2672
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the Zod schema generation for OpenAPI schemas that combine oneOf/anyOf with common properties. Previously, common properties defined at the parent level were omitted from the generated schemas. The fix uses Zod's .and() method to properly merge the union schemas with the common properties.
Key changes:
- Modified the logic in
generateZodValidationSchemaDefinitionto handle common properties foroneOf/anyOfschemas - Generated schemas now use
.and()to combine unions with common properties instead of ignoring them
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| packages/zod/src/index.ts | Updated schema generation logic to handle oneOf/anyOf with common properties using .and() |
| samples/swr-with-zod/src/gen/endpoints/pets/pets.zod.ts | Regenerated schemas demonstrating the fix with common properties now included |
| samples/hono/hono-with-zod/src/petstore.zod.ts | Regenerated schemas demonstrating the fix with common properties now included |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), | |
| callingCode: zod.enum(['+33', '+420']).optional(), |
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
| name: zod.string(), | ||
| tag: zod.string().optional(), | ||
| email: zod.string().email().optional(), | ||
| callingCode: zod.enum(['+33', '+420', '+33']).optional(), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callingCode enum contains duplicate values ('+33' appears twice). This duplication is unnecessary and should be removed to maintain a clean enum definition.
Summary
fix
zodschema generation forOpenAPIschemas withoneOf/anyOfand common propertiesChanges
Combine
oneOf/anyOfwith common properties using.and()This fix handles OpenAPI schemas like:
Before
Common properties were missing:
After
Common properties are correctly combined using
.and():