Closed thorhj closed 9 months ago
Same issue here. Does readonly()
affect the result or is it a ‘transparent’ definition , like .catch()
?
If it’s the latter, supporting .readonly()
should be pretty straightforward. Happy to submit a PR if it makes sense.
UPD: This local patch seems to be working – I no longer get empty schemas 🎉
diff --git a/src/parseDef.js b/src/parseDef.js
index 4f33785322590999d31593cdcbdb174175930799..f8a09be4387cd64c1534f1f3a2a6c70f4625e1f2 100644
--- a/src/parseDef.js
+++ b/src/parseDef.js
@@ -151,6 +151,8 @@ const selectParser = (def, typeName, refs) => {
case zod_1.ZodFirstPartyTypeKind.ZodBranded:
return (0, branded_1.parseBrandedDef)(def, refs);
case zod_1.ZodFirstPartyTypeKind.ZodCatch:
+ // https://github.com/StefanTerdell/zod-to-json-schema/issues/90
+ case zod_1.ZodFirstPartyTypeKind.ZodReadonly:
return (0, catch_1.parseCatchDef)(def, refs);
case zod_1.ZodFirstPartyTypeKind.ZodPipeline:
return (0, pipeline_1.parsePipelineDef)(def, refs);
For simplicity, ZodReadonly
is processed the same way as ZodCatch
.
Done in master
When is this gonna be released @StefanTerdell ?
@fredrikj31 about a minute ago
Great, thanks @StefanTerdell! The new version works like a charm ✨
If you have a bit of time, can you please update the list of releases?
It should help Renovate (and other similar tools) show the list changes in autogenerated PRs. It is empty at the moment:
With zod 3.22.0+ we now have
.readonly()
which can be applied to various types, most notably array and object. This is not supported inzod-to-json-schema
yet, so it just returns an empty schema: