-
-
Notifications
You must be signed in to change notification settings - Fork 106
fix(zod): Required fields with a default value should be optional in Typed JSON cases #2044
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
Conversation
📝 WalkthroughWalkthroughThe changes refactor the logic in the Changes
Sequence Diagram(s)sequenceDiagram
participant T as Transformer
participant F as Field Metadata
participant S as Schema String
T->>F: Receive field information
alt Single Alternative
T-->>S: Directly assign the alternative to schema string
else Multiple Alternatives
T-->>S: Join alternatives into schema string
end
T->>S: Check if field.isRequired is false
alt Field is Optional
T-->>S: Append ".optional()" to schema string
end
T-->>F: Return constructed schema string
Possibly related PRs
Suggested Reviewers
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
⏰ Context from checks skipped due to timeout of 90000ms (5)
🔇 Additional comments (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Thank you @diesal11 . The change looks good to me. It'll be part of the next release!
I believe this is just an edge case with Typed JSON fields again, but it did surface what appears to be a legitimate bug in the zod generator code. So I've tidied that section up slightly to fix the issue and improve readability a touch.
Apologies for not catching this with the last PR.