Skip to content

Conversation

@Bram-dc
Copy link
Contributor

@Bram-dc Bram-dc commented Apr 13, 2025

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

@Bram-dc Bram-dc changed the title Initial changed Initial changes for zod@4 Apr 13, 2025
@Bram-dc Bram-dc marked this pull request as draft April 13, 2025 02:07
@Bram-dc Bram-dc mentioned this pull request Apr 13, 2025
"components": {
"schemas": {
"Token": {
"id": "Token",
Copy link
Contributor Author

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.

Copy link
Contributor Author

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,
Copy link
Contributor Author

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

Copy link
Collaborator

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) => ({
Copy link
Contributor Author

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

@Bram-dc
Copy link
Contributor Author

Bram-dc commented Apr 22, 2025

@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.

@kibertoad
Copy link
Collaborator

@Bram-dc can you try using latest beta version? Wonder if it addressed some of the issues that you have encountered.

@Bram-dc
Copy link
Contributor Author

Bram-dc commented Apr 27, 2025

@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 z.globalRegistry and z.registry(). I might create a PR for that in the zod github.

@kibertoad
Copy link
Collaborator

@Bram-dc Can you update this for the final 3.25.3 release? We could then merge it after it is green

@adri1wald
Copy link

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 🤩

@kibertoad
Copy link
Collaborator

@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?

@Bram-dc
Copy link
Contributor Author

Bram-dc commented May 25, 2025

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.

@Bram-dc
Copy link
Contributor Author

Bram-dc commented May 26, 2025

Waiting for this PR to be accepted: colinhacks/zod#4525

@Bram-dc
Copy link
Contributor Author

Bram-dc commented May 26, 2025

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.

Done and done

@kibertoad
Copy link
Collaborator

@Bram-dc new version with the fix was released

@Bram-dc
Copy link
Contributor Author

Bram-dc commented May 29, 2025

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

@gabriel-bianchessi
Copy link

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. :)

@Bram-dc Bram-dc marked this pull request as ready for review June 4, 2025 14:08
@thelinuxlich
Copy link

thanks for the work @Bram-dc !

@kibertoad
Copy link
Collaborator

I'll try to release on Sunday

@kibertoad kibertoad changed the title Initial changes for zod@4 Support zod@4 Jun 8, 2025
@kibertoad kibertoad merged commit 18530c0 into turkerdev:main Jun 8, 2025
6 checks passed
@kibertoad
Copy link
Collaborator

@Bram-dc Looks like the transition to dual-publishing wasn't entirely smooth, I'm getting the following error in an ESM project now:

Error: Cannot find module 'C:\sources\node\shared-ts-libs4\packages\app\fastify-api-contracts\node_modules\fastify-type-provider-zod\dist\esm\core' imported from C:\sources\node\shared-ts-libs4\packages\app\fastify-api-contracts\node_modules\fastify-type-provider-zod\dist\esm\index.js

Import looks like this:

import {
  type ZodTypeProvider,
  serializerCompiler,
  validatorCompiler,
} from 'fastify-type-provider-zod'

@kibertoad
Copy link
Collaborator

@kibertoad
Copy link
Collaborator

@Bram-dc Can you check #167?

@samchungy
Copy link

Congrats on the release 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants