Skip to content
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

Handling of differences between Zod and Json Schema #73

Closed
marcesengel opened this issue Jun 12, 2023 · 4 comments
Closed

Handling of differences between Zod and Json Schema #73

marcesengel opened this issue Jun 12, 2023 · 4 comments

Comments

@marcesengel
Copy link

Hi!

When looking through the json schema specs on emails and how zod handles them I realised there's a fundamental difference: while the json schema spec uses RFC 5321 for email and RFC 6531 for idn-email, zod uses a custom RegExp which it deems "reasonable".
This is where I wondered if matching zod.string().email() to "format": "email" actually makes sense, or if we should maybe use "pattern": "[regex from zod]" instead. Otherwise one could run into issues where an email is valid for the json schema, but invalid when using zod.

This issue extends to #40, where I'm currently adding RegExps for the aforementioned RFCs - which wouldn't be in line with how zod handles things and leads to enormous patterns being ejected.

I think this deserves a general answer, with options being

  1. try to generate a json schema which best contains the information given to the zod schema (use "format": "idn-email")
  2. generate a json schema which matches with the validations zod does (use "pattern": "[regex from zod]")

@StefanTerdell

@StefanTerdell
Copy link
Owner

Fair. Check #74

@marcesengel
Copy link
Author

😍

Lovely! Didn't expect you to directly address this in code to be honest 🚀

@StefanTerdell
Copy link
Owner

Well, I agree with the problem description and it was a fairly quick fix. I'll see about getting it released in the coming days.

@StefanTerdell
Copy link
Owner

Fix released in 3.21.2

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

No branches or pull requests

2 participants