default and automatic generated fields should be optional
See original GitHub issueHello there. Whenever I use zod to validate my schema, i validate the data coming from userland. That means any HTTP/REST API, MQTT API etc. needs to get validated in order to create or update a database entry.
That means, all fields that are autogenerated (denoted by prisma with @id
) should be marked as optional
or removed from the model, as they are not needed neither in create or update mechanisms.
Fields that have a default value (denoted by @default
) should be optional. This could be solved by making the field itself optional with ?
. However, I would like to disallow explicitly setting null
, but allow implicitly accepting the default value by omitting the field.
This could be solved with /// @zod.optional()
in the schema, but could also be a sensible default.
What are your thoughts? Is it worth to introduce an option for the generator? Am I maybe understanding something wrong? In the end it is not so urgent, because it can be fixed on my end applying the correct types. Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
No, you are understanding it correctly. I definitely agree this needs to be incorporated in some way. I’m currently brainstorming a more all-encompassing rework that should handle this, #93, and #90. So I’ll update this issue when that becomes available! Thanks!
Hey @CarterGrimmeisen has there been any progress on this? Is this still on your radar? It would be an improvement I could surely use 😃