Skip to content
Skills Library
Programming · Building & coding

generate-sample-data

/generate-sample-data

Generate mock/sample data from Zod schemas for testing, development, and mocks. Use when creating sample data generators, setting up test fixtures, populating mock APIs, or generating realistic fake data for development.

Licence
MIT
Last repository change
01.07.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 01.07.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Generate mock/sample data from Zod schemas for testing, development, and mocks. Use when creating sample data generators, setting up test fixtures, populating mock APIs, or generating realistic fake data for development.

Original author description

Generate mock/sample data from Zod schemas for testing, development, and mocks. Use when creating sample data generators, setting up test fixtures, populating mock APIs, or generating realistic fake data for development.

How it works

  1. When to Use
  2. Technology Stack
  3. File Structure
  4. Standard Function Signature
  5. Two Generation Patterns
  6. Enhancing with Faker
  7. Using in Mock APIs (MSW)
  8. Creating Array Samples
  9. CRITICAL: Deterministic Dates with Seeds
  10. Testing Sample Generators
Original SKILL.md headings · 136 lines, 470 words
SKILL.md preview
---
name: generate-sample-data
description: Generate mock/sample data from Zod schemas for testing, development, and mocks. Use when creating sample data generators, setting up test fixtures, populating mock APIs, or generating realistic fake data for development.
---

# Skill: Generate Sample Data from Zod Schemas

Generate type-safe, realistic sample data for testing, development, and mock APIs using Zod schema definitions.

## When to Use
- Creating sample data generators for domain models
- Populating MSW mock API handlers
- Generating test fixtures
- Creating Storybook stories
- Seeding development databases
- Building realistic demo data

## Technology Stack

| Package | Purpose |
|---------|---------|
| **@anatine/zod-mock** | Generates mock data from Zod schemas via `generateMock()` |
| **@faker-js/faker** | Provides realistic fake data |
| **Zod** | Source of truth for type definitions and validation |

## File Structure

```
model/
├── Job.ts              # Zod schema + type
├── Job.sample.ts       # Sample generator ← THIS FILE
├── User.ts / User.sample.ts
└── index.ts            # Re-export samples
```

## Standard Function Signature

```typescript
createEntitySample(options?: { seed?: number; overrides?: Partial<Entity> }): Entity
```

## Two Generation Patterns

### Pattern 1: Simple Schemas (Primitives Only)

Use `generateMock` directly:

```typescript
import { generateMock } from '@anatine/zod-mock';
import { EntitySchema } from './Entity';

export function createEntitySample(options?: { seed?: number; overrides?: Partial<Entity> }): Entity {
  const mock = generateMock(EntitySchema, { seed: options?.seed });
  return { ...mock, ...options?.overrides };
}
```

### Pattern 2: Composed Schemas (Nested Objects/Arrays)

Compose child samples:

```typescript
export function createJobSample(options?: { seed?: number; overrides?: Partial<Job> }): Job {
  const mock = generateMock(JobBaseSchema, {
    seed: options?.seed,
    stringMap: {
      name: () => faker.company.name(),
      email: () => faker.internet.email(),
    },
  });
  return { ...mock, ...options?.overrides };
}
```

## Enhancing with Faker

Use Faker for realistic names, emails, phones. Create seeded Faker instances for determinism:

```typescript
import { faker } from '@faker-js/faker';

// Seeded for determinism
if (options?.seed !== undefined) {
  faker.seed(options.seed);
}
```

## Using in Mock APIs (MSW)

Generate 15-20+ items with variety:

```typescript
const jobs = Array.from({ length: 20 }, (_, i) =>
  createJobSample({ seed: i, overrides: { status: i % 3 === 0 ? 'COMPLETED' : 'ACTIVE' } })
);
```

## Creating Array Samples

```typescript
export function createJobSamples(count: number, baseSeed: number = 0): Job[] {
  return Array.from({ length: count }, (_, i) =>
    createJobSample({ seed: baseSeed + i })
  );
}
```

## CRITICAL: Deterministic Dates with Seeds

**NEVER use `Date.now()` or `new Date()` when a seed is provided!**

```typescript
const baseTimestamp = seed !== undefined
  ? new Date(2026, 1, 20, 10, 0, 0).getTime() + (seed * 1000)
  : Date.now();
```

## Testing Sample Generators

Every generator should have tests for:
- Validity (validates against schema)
- Determinism (same seed = same output)
- Overrides work correctly

## Key Principles

1. Types derive from Zod schemas
2. JSON serializable only (ISO 8601 strings, not Date objects)
3. Consistent naming: `create[Entity]Sample` / `create[Entity]Samples`
4. Seed for determinism
5. Overrides for flexibility
6. Export from model index
7. 15-20+ items for lists/tables

## Installation

```bash
npm install -D @anatine/zod-mock @faker-js/faker
```

Versions

RepositoryScoreLicence
This page · bitovi/ai-enablement-prompts100MIT
quadient/migration-stack100MIT

Database snapshot: 13.11.2026 · package version 97bbca1b226b (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100seedmint
    Generate realistic sample/seed/mock data from a schema (TypeScript, Zod, Prisma, Drizzle, SQL, JSON) in a chosen locale and format, so prototypes and UI reviews are not empty. Use when the user asks for fake data, seed data, mock data, fixtures or demo data.
  • 100mocking-apis
    Generate mock API servers for testing and development with realistic response data. Use when creating mock APIs for development and testing. Trigger with phrases like "create mock API", "generate API mock", or "setup mock server".
  • 100mocking-apis
    Generate mock API servers for testing and development with realistic response data. Use when creating mock APIs for development and testing. Trigger with phrases like "create mock API", "generate API mock", or "setup mock server".
  • 100data-seeding
    Create or update database seed scripts for development and testing environments. Use when setting up test data, initializing development databases, creating demo environments, resetting to known state, or generating realistic sample data.
  • 100data-seeding
    Create or update database seed scripts for development and testing environments. Use when setting up test data, initializing development databases, creating demo environments, resetting to known state, or generating realistic sample data.
  • 100generating-test-data
    Generate realistic test data including edge cases and boundary conditions. Use when creating realistic fixtures or edge case test data. Trigger with phrases like "generate test data", "create fixtures", or "setup test database".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.