api-contracts-and-zod-validation

Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.

16 stars

Best use case

api-contracts-and-zod-validation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.

Teams using api-contracts-and-zod-validation should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/api-contracts-and-zod-validation/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/api-contracts-and-zod-validation/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/api-contracts-and-zod-validation/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How api-contracts-and-zod-validation Compares

Feature / Agentapi-contracts-and-zod-validationStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# API Contracts and Zod Validation

Generate Zod schemas with TypeScript type inference for forms, API routes, and Server Actions. Validate inputs in Server Actions or route handlers with runtime type checking.

## Core Capabilities

### 1. Generate Zod Schemas from TypeScript Types

When creating API contracts or form validations:

- Analyze existing TypeScript interfaces or types
- Generate equivalent Zod schemas with proper validation rules
- Ensure bidirectional type compatibility (Zod -> TypeScript)
- Use `z.infer<typeof schema>` for automatic type inference

### 2. Form Validation Schemas

To create form validation with Zod:

- Generate schemas for React Hook Form, Formik, or native forms
- Include field-level validation rules (min/max length, regex, custom validators)
- Support nested objects, arrays, and complex data structures
- Provide helpful error messages for validation failures
- Use `references/zod_patterns.md` for common validation patterns

### 3. API Route and Server Action Validation

To add validation to API endpoints or Server Actions:

- Wrap handler logic with schema validation using `.parse()` or `.safeParse()`
- Return typed errors for validation failures
- Generate request/response schemas for API contracts
- Validate query parameters, body payloads, and route parameters
- Ensure type safety between client and server code

### 4. Schema Generation Script

Use `scripts/generate_zod_schema.py` to automate schema generation:

```bash
python scripts/generate_zod_schema.py --input types/entities.ts --output schemas/entities.ts
```

The script:
- Parses TypeScript interfaces/types
- Generates Zod schemas with appropriate validators
- Preserves JSDoc comments as descriptions
- Handles common patterns (optional fields, unions, enums)

## Resource Files

### scripts/generate_zod_schema.py
Automated TypeScript-to-Zod schema generator. Parses TypeScript AST and generates equivalent Zod schemas.

### references/zod_patterns.md
Common Zod validation patterns including:
- String validation (email, URL, UUID, custom regex)
- Number constraints (min, max, positive, integer)
- Date validation and transformation
- Array and tuple validation
- Object shape validation
- Union and discriminated unions
- Optional and nullable fields
- Custom refinements and transforms
- Error message customization

### assets/schema_templates/
Pre-built Zod schema templates:
- `form_schema_template.ts` - Basic form validation
- `api_route_schema_template.ts` - API route request/response
- `server_action_schema_template.ts` - Server Action input/output
- `entity_schema_template.ts` - Database entity validation

## Usage Workflow

### For New API Routes

1. Define request/response TypeScript types
2. Generate Zod schemas using `scripts/generate_zod_schema.py` or templates
3. Add validation middleware to route handler
4. Return typed validation errors on failure

### For Server Actions

1. Define input parameters as TypeScript types
2. Create Zod schema for validation
3. Use `.safeParse()` at the beginning of the action
4. Return validation errors in action result
5. Handle errors on the client side

### For Forms

1. Define form fields as TypeScript interface
2. Generate Zod schema with field validators
3. Integrate with form library (React Hook Form recommended)
4. Display validation errors inline

## Best Practices

- Always use `.safeParse()` instead of `.parse()` to avoid throwing exceptions
- Provide clear, user-friendly error messages
- Validate early (at API boundary or Server Action entry)
- Keep schemas colocated with routes/actions for maintainability
- Use `z.infer<typeof schema>` for automatic TypeScript types
- Document validation rules in schema comments
- Test edge cases (empty values, invalid formats, boundary conditions)

## Integration with Worldbuilding App

Common use cases for worldbuilding applications:

- **Entity creation forms**: Validate character, location, faction data
- **Relationship APIs**: Ensure valid entity IDs and relationship types
- **Timeline events**: Validate dates, ordering, and event data
- **Search/filter endpoints**: Validate query parameters and filters
- **Bulk operations**: Validate arrays of entities or updates
- **Import/export**: Validate file formats and data structure

Consult `references/zod_patterns.md` for specific validation patterns applicable to worldbuilding entities.

Related Skills

bio-alignment-validation

16
from diegosouzapw/awesome-omni-skill

Validate alignment quality with insert size distribution, proper pairing rates, GC bias, strand balance, and other post-alignment metrics. Use when verifying alignment data quality before variant calling or quantification.

date-validation

16
from diegosouzapw/awesome-omni-skill

Use when editing Planning Hubs, timelines, calendars, or any file with day-name + date combinations (Wed Nov 12), relative dates (tomorrow), or countdowns (18 days until) - validates day-of-week accuracy, relative date calculations, and countdown math with two-source ground truth verification before allowing edits

spring-validation

16
from diegosouzapw/awesome-omni-skill

Bean Validation (Jakarta Validation) with Spring Boot. Custom validators, validation groups, cross-field validation, and internationalized error messages.

Smart Contracts

16
from diegosouzapw/awesome-omni-skill

Smart contracts are self-executing programs on blockchain. This guide covers Solidity basics, contract deployment, interaction, and frontend integration for building decentralized applications with au

fullstack-validation

16
from diegosouzapw/awesome-omni-skill

Comprehensive validation methodology for multi-component applications including backend, frontend, database, and infrastructure

Data Contracts

16
from diegosouzapw/awesome-omni-skill

A Data Contract is a formal agreement between a data producer (e.g., a microservice) and a data consumer (e.g., a data platform) that defines the structure, semantics, and quality of data being shared

api-validation

16
from diegosouzapw/awesome-omni-skill

Apply when validating API request inputs: body, query params, path params, and headers. This skill covers Zod v4 patterns.

api-request-validation

16
from diegosouzapw/awesome-omni-skill

A skill for implementing robust API request validation in Python web frameworks like FastAPI using Pydantic. Covers Pydantic models, custom validators (email, password), field-level and cross-field validation, query/file validation, and structured error responses. Use when you need to validate incoming API requests.

API Contracts Generator

16
from diegosouzapw/awesome-omni-skill

Génère des contrats API cohérents entre Frontend (Next.js) et Backend (NestJS) avec types synchronisés, validation standardisée et error handling uniforme. À utiliser lors de la création d'APIs, DTOs, types frontend/backend, ou quand l'utilisateur mentionne "API", "DTO", "types", "contract", "validation", "frontend-backend", "synchronisation".

api-contracts-and-validation

16
from diegosouzapw/awesome-omni-skill

Define and validate API contracts using Zod

api-contract-validation

16
from diegosouzapw/awesome-omni-skill

Detect breaking changes in API contracts (OpenAPI/Swagger specs)

android-playstore-api-validation

16
from diegosouzapw/awesome-omni-skill

Create and run validation script to test Play Store API connection