You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having nullable properties in a json array results in excessively large zod schemas.
I encountered this specifically when converting JSON to zod but it applies in other use cases as well, if it isn't solved for them. The expected behavior here is that array types should rarely (possibly never) result in union types. The actual behavior is that the schema is constructed as a union. I would suggest adding a flag for the current (union) behavior and returning recursively merged types by default.
Here's a trivial example. Imagine I have this JSON
As you can imagine for non trivial cases where properties can be nullable/vary in types you can end up with excessively large union types.
I believe this problem has already been solved in some related libraries, such as https://jvilk.com/MakeTypes/. I'd love to see a similar implementation to recursively merge unions in arrays; I'd like to use this tool but this is limiation for me currently!
The text was updated successfully, but these errors were encountered:
Traced the issue a little further and looks like this is just referencing the https://www.npmjs.com/package/json-schema-to-zod library. I'll leave the issue open as it still matters to have the UI but that's where the change will need to be made
Having nullable properties in a json array results in excessively large zod schemas.
I encountered this specifically when converting JSON to zod but it applies in other use cases as well, if it isn't solved for them. The expected behavior here is that array types should rarely (possibly never) result in union types. The actual behavior is that the schema is constructed as a union. I would suggest adding a flag for the current (union) behavior and returning recursively merged types by default.
Here's a trivial example. Imagine I have this JSON
The resulting zod type is
What I would write if doing this as a human:
As you can imagine for non trivial cases where properties can be nullable/vary in types you can end up with excessively large union types.
I believe this problem has already been solved in some related libraries, such as https://jvilk.com/MakeTypes/. I'd love to see a similar implementation to recursively merge unions in arrays; I'd like to use this tool but this is limiation for me currently!
The text was updated successfully, but these errors were encountered: