Back to R&D
tool✓ Completed

API Mock Generator

CLI tool that generates mock API responses from OpenAPI specs for testing.

July 2024
CLITestingOpenAPIMock

Why I Built This

Waiting for backend APIs blocks frontend development. I wanted a tool that generates realistic mock data from API specs so development can proceed in parallel.

Tech Stack

DartLanguage
OpenAPI ParserSpec Parsing
FakerData Generation
ShelfHTTP Server

Technical Approach

Built a CLI tool in Dart that parses OpenAPI specs and generates a mock server with realistic fake data.

1

OpenAPI Parser

Built a robust parser for OpenAPI 3.0 specs supporting all common schema types.

2

Data Generation

Integrated Faker library with smart type inference for realistic data.

3

Mock Server

Created a lightweight HTTP server that serves generated responses with configurable latency.

4

CLI Interface

Designed intuitive CLI with watch mode for spec changes.

Key Learnings

What worked, what didn't, and what I'd do differently.

What Worked

  • Type inference from property names creates realistic data
  • Cached responses improve consistency during testing
  • Watch mode speeds up iterative development

Challenges Faced

  • Complex $ref resolution had edge cases that needed handling
  • Some OpenAPI extensions weren't widely documented

Key Insights

The bigger lessons that go beyond this specific experiment.

Specs Are Contracts

Good OpenAPI specs benefit both frontend and backend teams equally.

Realistic Data Matters

Edge cases in data (empty arrays, long strings) catch UI bugs early.

CLI UX

Good CLI tools have sensible defaults but allow customization.

What's Next

Considering adding: • Docker image for team sharing • Scenario mode for testing different states • Recording mode to capture real API responses • VS Code extension for inline preview

Interested in this experiment?

I'm always happy to discuss technical details, share learnings, or collaborate on similar explorations.