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
I'm implementing a zod-schema-faker library to generate fake data for zod.
Recently I am trying to support fake data generation for custom schema (.custom) and custom validation logic (.refine), the strategy is to identify the schema/validator and execute user-defined faker to achieve the goal.
For example:
// user may have this validator:constvalidator=(val: string)=>val.length<=255constschema=z.string().refine(validator,{message: "String can't be more than 255 characters",})// they could generate data by register a custom validator:functionvalidatorFaker(fakeVal: string): string{returnfakeVal.slice(0,255)}installRefine(validator,validatorFaker)constfakeData=fake(schema)
Further info about how custom schema to be supported:
Hi, thank you for building this powerful validation library~
Feature Request
Could we store the user-defined validator in somewhere like
schema._def.effect
:https://github.com/colinhacks/zod/blob/890556e/src/types.ts#L322
Use case
I'm implementing a zod-schema-faker library to generate fake data for zod.
Recently I am trying to support fake data generation for custom schema (
.custom
) and custom validation logic (.refine
), the strategy is to identify the schema/validator and execute user-defined faker to achieve the goal.For example:
Further info about how custom schema to be supported:
Thank you 😄
The text was updated successfully, but these errors were encountered: