Support Zod v4
Zod v4 has been released alongside zod v3 as of Zod v3.25 at the zod/v4 subpath. It would be good to have this codegen code for Zod updated to use Zod v4. The migration guide can be found here: https://zod.dev/v4/changelog
Hi,
I expect it would be possible to copy and paste the current Zod code generator, then just update for the zod/v4 sub module path and see how it goes. This project shouldn't be hugely impacted by changes in Z4 because it only superficially interacts with Zod's interface. Would want to provide both v3 and v4 generators.
Would you like to submit a PR for this?
I can submit a PR, would you suggest a similar pattern to the valibot codegen generation that passes in options to allow configuring between v3 and v4?
@PritamSangani Hiya,
I can submit a PR, would you suggest a similar pattern to the valibot codegen generation that passes in options to allow configuring between v3 and v4?
Let's go with two distinct modules, model-to-zod-3.ts and model-to-zod-4.ts. This will make it easier to maintain (vs maintaining conditional v3/v4 checks in the mapping logic). If there are additional options you would like to add to the Z4 implementation, feel free, just make sure they have reasonable defaults as the code generators should be callable without the user having to pass options.
Can also rename the current ModelToZod to ModelToZod3 (ill run a minor revision on publish indicating a potential naming break). I would hope the ModelToZod4 implementation can be mostly equivalent to the ModelToZod3 implementation (hopefully just a different import path specifier and a few tweaks here and there). But if you see room to improve things on Z4, feel free (it's a new implementation, so there's a bit of room to move with respect to implementation clean ups). Leave the Z3 implementation as is though so I have something to cross reference with.
Once merged, ill move it across to the https://github.com/sinclairzx81/typebox-workbench. Incidentally, if you are good with photoshop or other imaging software, I am probably going to need a new icon for Zod 4 (need to update https://github.com/sinclairzx81/typebox-workbench/blob/main/docs/assets/images/zod-control.png with the new logo). This is optional of course :)
Feel free to submit the PR, will be able to take a look over the coming days :) Many Thanks! S