| name | write-zod-schema |
| description | Define and apply Zod schemas for validating external or complex data throughout the codebase. |
write-zod-schema Skill
Purpose:
Define and use Zod schemas for data validation throughout the codebase.
When to Use:
- When validating external data (e.g., Contentful API responses).
- When enforcing type safety for complex objects.
Instructions:
- Import Zod:
import z from "zod";
- Define schemas for all external or complex data structures.
- Use
.parse() or .safeParse() to validate data at runtime.
- Export schemas for reuse in other modules.
- Add tests for custom validation logic if needed.
Code Example:
import z from "zod";
export const RuleReferenceSchema = z.object({
id: z.string(),
title: z.string(),
content: z.string(),
});
const rule = RuleReferenceSchema.parse(data);
Related Files:
src/shared/
scripts/fetch-content.ts