timdeschryver / zod-fixture

Creating fixtures based on zod schemas
https://zod-fixture.timdeschryver.dev/
MIT License
120 stars 10 forks source link

Support Additional Recursion Wrappers #83

Closed THEtheChad closed 1 year ago

THEtheChad commented 1 year ago

There were still some edge cases with recursion that included methods like nullable, optional, and promise.

z.lazy(() => categorySchema.array()).nullable()

Full example below.

const baseCategorySchema = z.object({
    name: z.string(),
});

type Category = z.infer<typeof baseCategorySchema> & {
    subcategories?: Category[] | null;
};

const categorySchema: z.ZodType<Category> = baseCategorySchema.extend({
    subcategories: z.lazy(() => categorySchema.array()).nullable(),
});
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zod-fixture ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2023 3:27pm
github-actions[bot] commented 1 year ago

:tada: This PR is included in version 2.2.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: