Support for z.lazy() and recursive schemas
#191
Replies: 5 comments 2 replies
|
@rattrayalex thank you for this. Lazy schemas are something that we do not support at all as of today. I'll take a look at it. |
|
Would adding if (isZodType(schema, 'ZodLazy')) {
return this.unwrapChained(schema.schema);
}to |
|
Is this supported now? Or is there a workaround you'd suggest in the meantime for recursive schemas? |
|
z.lazy is a kind of workaround that allows for manually defining a schema that cannot be computed due to primarily recursions and circular dependencies. |
|
Oh boy it has been a while but this has finally been released in v8.3.0 🎉🎉 . Please check it out and let us know if there are any issues. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Currently, this code (copied from zod's recursive types docs):
Throws this error:
Ideally, it would generate an OpenAPI spec like this:
This may require automatic resolution of registered schemas to
$refs, which I filed here: #142All reactions