Skip to main content
strapi2front generates Zod validation schemas from your Strapi content types, providing runtime type safety and validation for forms, API inputs, and more.

What Gets Generated

For each content type, strapi2front creates Zod schemas that:

Validate Structure

Ensure data matches your Strapi schema structure

Enforce Constraints

Min/max length, number ranges, email format, etc.

Type Inference

Generate TypeScript types from schemas automatically

Custom Messages

Add custom validation error messages

Generated Schema Example

For an Article collection type:
article/schemas.ts

Schema Types

Validates data for creating new entries. Required fields are enforced.

Field Type Mappings

strapi2front maps Strapi field types to Zod schemas:
Media fields accept file IDs (numbers), not file objects. Upload files first via the upload API, then use the returned IDs.

Using Schemas in Forms

React Hook Form Example

components/ArticleForm.tsx

Astro Actions Example

actions/article.ts

Manual Validation

Custom Validation

Extend generated schemas with custom validation:

Advanced Relation Schemas (v5)

For Strapi v5, schemas support advanced relation operations:
Usage example:

Error Handling

Display Validation Errors

Custom Error Messages

Real-World Example: Multi-Step Form

components/CreateArticleWizard.tsx
Zod schemas are automatically regenerated when you run npx strapi2front sync. Keep them in sync with your Strapi schema.

Next Steps

Services

Use validated data with generated services

Relations

Validate related content references

Media

Upload files and validate media IDs

Types

Understand TypeScript type generation