Open kachkaev opened 2 months ago
unfortunately this has the same root issue: calling describe on your zod schemas does not create new instances, so there's nothing to check against. I could create an internal map of all seen descriptions, but with zod 4 around the corner it might not be worth the effort. Let's see how it turns out :)
I briefly checked the implementation of describe
, it seems to be creating a new instance:
https://github.com/colinhacks/zod/blame/03f2f080c4bb0ccd4434748a6e930ebdd1bd75a6/src/types.ts#L499-L505
The implementation of describe
has not been changed since Oct 2021, according to git blame.
Sorry, yes, you're right. I mixed this up with another bug and didn't read the issue properly.
I believe I have found a small bug similar to https://github.com/StefanTerdell/zod-to-json-schema/issues/66. Using
zod-to-json-schema@3.23.0
. Here is a reproduction:✅
z.string()
No description in
baz
, as expected.✅
z.string().min(1).max(255)
No description in
baz
, as expected.❌
z.string().default('default value')
Both
bar
andbaz
refer tofoo
, sobaz
unexpectedly inheritsfoo
’s description.❌
z.string().catch('caught value')
Same as above: Both
bar
andbaz
refer tofoo
, sobaz
unexpectedly inheritsfoo
’s description.If I call
zodToJsonSchema(schema, { $refStrategy: 'none' })
, description no longer ‘leaks’, which is great. However, it’d be great to see it not leaking by default because misplaced tooltips with description are confusing.PS: Thanks for the lib! It’s really neat an super-useful! 🙌