-
Notifications
You must be signed in to change notification settings - Fork 38
Support zod@4 #153
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
Support zod@4 #153
Conversation
| "components": { | ||
| "schemas": { | ||
| "Token": { | ||
| "id": "Token", |
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 not valid in the OpenAPI spec. The best solution is to fix this upstream. Removing it manually feels dirty.
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 has been resolved by not using the global registry, more testing has to be done on the stable release to ensure this also wont happen using the global registry.
| "type": "string", | ||
| }, | ||
| "seed": { | ||
| "exclusiveMinimum": true, |
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.
z.int().positive() is currently undefined, so this is a workaround.
See: colinhacks/zod#4087
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 was fixed
|
|
||
| export const createValidationError = (error: ZodError): ZodFastifySchemaValidationError[] => | ||
| error.errors.map((issue) => ({ | ||
| error.issues.map((issue) => ({ |
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.
Issues have changed, we should not access error.issues here.
See: https://v4.zod.dev/v4/changelog#deprecates-addissue-and-addissues
…transform handling
|
@kibertoad @turkerdev Could we have a nightly release or beta release so I can do some integrated testing? "npm i https://github.com/turkerdev/fastify-type-provider-zod" does not work with this current setup. |
|
@Bram-dc can you try using latest beta version? Wonder if it addressed some of the issues that you have encountered. |
Yes it did resolve most of the issues, the only one causing our tests to fail is the "id" fields being added to the schema when using the global registry. There is also different behaviour when using |
…pdate schema definitions to use 'object'
|
@Bram-dc Can you update this for the final 3.25.3 release? We could then merge it after it is green |
|
just popping by here to say i'm so excited and so thankful for this release! it'll let us finally fix the excruciatingly slow type checking in our repo 🤩 |
|
@Bram-dc What are the outstanding zod bugs/issues that need to be addressed before we can get to green? Also, can I help with anything? |
|
I think most issues are fixed, also zod 3.25 has some weird cjs imports we need to fix. We might need to use a different compiler in our project (maybe rollup?). But I think zod will fix their issues so I will wait for those to come. Also we should write a few extra zod-to-json tranform functions (we can extend behaviour). Mainly that the built into zod one is very minimal. Fastify tranforms Dates for example to iso strings. The built in zod-to-openapi returns an error as dates cannot be represented as a schema. |
|
Waiting for this PR to be accepted: colinhacks/zod#4525 |
Done and done |
|
@Bram-dc new version with the fix was released |
|
I think this is ready to be merged for now and release a beta. We should clearly state in the docs that this new version is not compatible with zod v3 |
|
Hey guys, great job migrating to zod v4. Do you have an approximate release date in mind? If I can contribute with something, let me know. :) |
|
thanks for the work @Bram-dc ! |
|
I'll try to release on Sunday |
|
@Bram-dc Looks like the transition to dual-publishing wasn't entirely smooth, I'm getting the following error in an ESM project now: Import looks like this: import {
type ZodTypeProvider,
serializerCompiler,
validatorCompiler,
} from 'fastify-type-provider-zod' |
|
@Bram-dc This is also very unhappy: https://arethetypeswrong.github.io/?p=fastify-type-provider-zod%405.0.0 |
|
Congrats on the release 👏 |
This PR is far from ready to be merged, mostly due to bugs in the early release of zod v4. Also the way zod handles issues has changed so we might also want to do it differently in this package.
This PR has big breaking changes since it uses a different zod-to-json (built into zod@4)
Tests are failing, due to bugs in zod