-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Add support for zod@4 schemas #1666
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
base: next
Are you sure you want to change the base?
Conversation
c482776
to
8f56474
Compare
tests/helpers/zod.test.ts
Outdated
}); | ||
|
||
it('throws error on optional fields', () => { | ||
(version === 'v4' ? it.skip : it)('throws error on optional fields', () => { |
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.
as we transform the schema, we actually add missing fields in required
property, as we do in python
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.
hmm I don't think this is quite right, in Python it's fine because the property being omitted or explicitly set to null
results in the same type, None
, but in TS it's different.
so if we add properties that are .optional()
to the required
array, then the API will send them back as null
, which breaks the type promise because it'd be typed as property?: string
instead of property?: string | null
or property: string | null
.
the equivalent behaviour here for python would be to only add properties to required
when they're both .optional()
and .nullable()
which is why we throw the current error.
describe.each([ | ||
{ version: 'v3', z: zv3 as any }, | ||
{ version: 'v4', z: zv4 as any }, | ||
])('zodResponseFormat (Zod $version)', ({ version, z }) => { |
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.
👌 this is a cool way to test things
tests/helpers/zod.test.ts
Outdated
}); | ||
|
||
it('throws error on optional fields', () => { | ||
(version === 'v4' ? it.skip : it)('throws error on optional fields', () => { |
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.
hmm I don't think this is quite right, in Python it's fine because the property being omitted or explicitly set to null
results in the same type, None
, but in TS it's different.
so if we add properties that are .optional()
to the required
array, then the API will send them back as null
, which breaks the type promise because it'd be typed as property?: string
instead of property?: string | null
or property: string | null
.
the equivalent behaviour here for python would be to only add properties to required
when they're both .optional()
and .nullable()
which is why we throw the current error.
Changes being requested
Additional context & links