fix(zod): union and intersection schema conversion#1157
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughRecursive conversion now increments structureDepth for child items in Union, DiscriminatedUnion, and Intersection branches; the single-element anyOf short-circuit was removed so unions always emit an Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as convert(schema, depth)
participant Union as Union Handler
participant Child as Child Converter
rect rgb(240,248,255)
Note over Caller,Child: Old behavior
Caller->>Union: convert(unionSchema, depth=0)
Union->>Child: convert(optionA, depth=0)
Union->>Child: convert(optionB, depth=0)
Union->>Caller: return anyOf[0] if length==1
end
rect rgb(255,245,240)
Note over Caller,Child: New behavior
Caller->>Union: convert(unionSchema, depth=0)
Union->>Child: convert(optionA, depth=1)
Union->>Child: convert(optionB, depth=1)
Union->>Caller: return { anyOf: [ ... ] } always
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug in the Zod to JSON Schema converter, specifically refining how union and intersection schemas are translated. The core improvement ensures that union types are always represented as Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes how Zod union and intersection schemas are converted. The changes correctly increment the structureDepth during recursive calls for unions and intersections, which is a great bug fix. Additionally, the logic for handling unions is updated to no longer simplify anyOf arrays that contain a single item. This improves consistency in the generated schema. My main feedback is to suggest updating the removed test cases to assert the new, correct behavior instead of deleting them, to maintain test coverage.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/experimental-publisher
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fastify
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
The previous implementation incorrectly simplified `anyOf` schemas with only one element. This commit removes that simplification. Additionally, the `structureDepth` was not being incremented when converting union and intersection schemas. This has been fixed to prevent stack overflows on complex schemas.
7d034bb to
75c8463
Compare
Summary by CodeRabbit
Refactor
Tests