-
-
Notifications
You must be signed in to change notification settings - Fork 89
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): support @default
for BigInt
values
#1486
Conversation
Zod schemas fail to generate when using a `BigInt` type and a `@default` field, since generated Zod files use a `number` literal instead of a `BigInt` literal for the default value.
WalkthroughWalkthroughThe recent changes to the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant SchemaGen
participant ZodPluginTest
User->>SchemaGen: Call makeFieldSchema with BigInt field
SchemaGen->>SchemaGen: Check field type
alt Field type is BigInt
SchemaGen->>SchemaGen: Set default using BigInt notation
else Field type is not BigInt
SchemaGen->>SchemaGen: Set default normally
end
SchemaGen-->>User: Return schema
User->>ZodPluginTest: Run tests with new BigInt field
ZodPluginTest->>ZodPluginTest: Validate creation and update schemas
ZodPluginTest-->>User: Test results
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 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 as PR comments)
Additionally, you can add CodeRabbit Configration 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.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
packages/schema/src/plugins/zod/utils/schema-gen.ts (1)
155-161
: The changes correctly address the issue withBigInt
default values by using theBigInt
constructor. This is a good approach as it avoids the need for ES2020.Consider adding a comment explaining why the
BigInt
constructor is used instead of then
notation for better clarity.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/schema/src/plugins/zod/utils/schema-gen.ts (1 hunks)
- tests/integration/tests/plugins/zod.test.ts (2 hunks)
Thank you for making the fix @aloisklink ! The change looks great. I'm merging it and will include it in the upcoming v2.2 release. |
Zod schemas fail to generate when using a
BigInt
type and a@default
field, since the generated Zod.schema.ts
files use anumber
literal instead of aBigInt
for the default value.Example
Currently, a ZenStack schema like:
would get converted to the following, which throws a TypeScript error
Now, it would instead be converted to:
Failing test