Skill Detail

Zod Schema Generator

Converts JSON samples, TypeScript interfaces, and OpenAPI specs into Zod validation schemas. Uses ts-morph for AST parsing and zod-to-json-schema for bidirectional conversion.

Library & API ReferenceCursor
Library & API Reference Cursor Published
โญ 42.5k GitHub stars โฌ‡ 145.1M/wk npm
INSTALL WITH ANY AGENT
npx skills add agentskillexchange/skills --skill zod-schema-generator Copy
Works best when you want a reusable capability, not another fragile one-off prompt.
At a glance
Install & setup
npm install zod
Author
Colin McDonnell
Last updated
Mar 24, 2026
Quick brief

The Zod Schema Generator automates the creation of Zod runtime validation schemas from multiple source formats. It accepts JSON sample data, TypeScript interface definitions, and OpenAPI 3.x specifications as input and produces idiomatic Zod schemas with proper type inference. Using ts-morph for TypeScript AST parsing, it reads interface and type alias definitions directly from .ts files, converting optional properties, union types, discriminated unions, and branded types into their Zod equivalents. For JSON samples, it infers types using json-schema-inferrer and maps them to Zod primitives with appropriate refinements for email, URL, UUID, and date-time patterns detected in sample values. The bidirectional conversion capability via zod-to-json-schema allows generating JSON Schema from existing Zod definitions for documentation or API specification purposes. The generator handles complex patterns including recursive types using z.lazy(), transform pipes with z.transform(), and custom error messages. It also generates companion TypeScript types using z.infer for each schema, eliminating type duplication.