Closed kiesman99 closed 2 years ago
Thanks for creating this issue, and including a reproducible snippet 👍
With Optional
, the schema type is Optional
and this is causing problems at the moment.
We have a check for this, but it's at the wrong location. The issue should be resolved after we move this check to a better location.
The fix is to move the check on the inner type at
https://github.com/timdeschryver/zod-fixture/blob/main/src/generate.ts#L10-L12 to the extractFromZodSchema
method at https://github.com/timdeschryver/zod-fixture/blob/main/src/generate.ts#L27. This way when a property's type is looked up it will use the inner type.
More information:
The "real" type of the property is available on the schema,
To get the information of the "real" type we have to dig a bit deeper, and it's available on the schema's definition as _def.innerType
.
Feel free to create a PR with a fix if you want.
I will try to look at it the next few days. Thanks for the more detailed description!
:tada: This issue has been resolved in version 1.0.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
@timdeschryver thank you for fixing this! was having the same issue with nullable and it's solved for me now :)
I'm glad to hear that @jjmalina :)
Hey there! Thank you very much for your blog articles and of course this awesome library! (Big Fan 😄)
Description
However, i've run into an issue with zod-fixture. I cannot create fixtures of objects containing properties that are optional. It always throws this error message
Uncaught Error: Missing type for ZodType "ZodOptional"
. I think the correct mapping forZodOptional
is missing here.If I find a solution to this problem, i'll submit a PR. Until then, i just wanted to inform you i've encountered this issue.
Minimal Reproducible
Go to this StackBlitz and open the console of the browser. You'll be greeted with the error message.
Minimal test as reproducible sample