This site is not affiliated with or endorsed by Vercel, Inc. Read the docs, then deploy or run each experiment yourself.
AI

API Mock from OpenAPI

Paste an OpenAPI snippet - mock Next.js Route Handler stubs as downloadable text.

Run this experiment yourself

Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.

Local development

cd apps/experiments/api-mock-from-openapi
pnpm install
pnpm dev

Then open http://localhost:3010.

This is an experimental demo. Generated stubs are mocks, not production handlers.

API Mock from OpenAPI turns an OpenAPI YAML/JSON snippet into Next.js App Router Route Handler stubs via generateObject. The UI lists method/path mappings and downloads a concatenated stubs file. No AI keys - 503.

Features

  • OpenAPI paste – YAML or JSON sample products API.
  • Route list – method, path, handler filename.
  • Download stubs – single text file of mock handlers.
  • Cap 12 operations.
  • Honest unavailable state.

Server Reference

POST /api/mock

{ "openapi": "openapi: 3.0.3\n..." }

Success (200)

{
  "summary": "Mocks for Products API list/create/get.",
  "routes": [
    {
      "method": "GET",
      "path": "/api/products",
      "handlerFilename": "app/api/products/route.ts",
      "stubSource": "export async function GET() { ... }"
    }
  ],
  "downloadText": "// GET /api/products\n...",
  "provider": "ai-gateway"
}
StatusCause
503No AI provider
400Empty openapi

Implementation Details

clampBundle rebuilds downloadText if the model leaves it empty.

Use Cases

  • Bootstrap mock handlers from a spec.
  • Teach OpenAPI - App Router mapping.
  • Offline API demos.

Limitations

  • Stubs are not type-checked or wired into the app.
  • Complex $ref graphs may be incomplete.
  • No auth / rate limits.

Use in your project

Copy the download helper and stub schema; paste files into app/api manually after review.

Deployment

Deploy on Vercel

Local Development

cd apps/experiments/api-mock-from-openapi
pnpm install
pnpm dev

Configuration

VariableRequiredPurpose
AI_GATEWAY_API_KEYYes (or OPENAI_API_KEY)Preferred provider
OPENAI_API_KEYNoFallback
AI_MODELNoModel override

Vercel / Next.js Features Used

  • AI SDK generateObject
  • Vercel AI Gateway
  • Route Handlers
  • Zod

Next Steps

On this page