Convert any OpenAPI 3.x schema into a fully functional Cloudflare Worker mock API in seconds โ entirely in your browser.
- ๐ 100% Client-Side - No server required, runs entirely in your browser
- โก Instant Generation - Paste schema, click generate, deploy
- ๐ฏ Smart Fallbacks - Multiple mock data generation strategies
- ๐ Safe Code Output - Properly escaped, production-ready JavaScript
- ๐จ Dark Theme UI - Beautiful, modern interface
- ๐ฆ Zero Dependencies - Pure HTML, CSS, and JavaScript
- ๐ง Extensible - Modular codebase ready for customization
- Frontend Development - Mock backends before API implementation
- Testing & QA - Reliable, consistent test data
- Demos & Prototypes - Quick API mocking for presentations
- CI/CD Pipelines - Temporary mock endpoints for testing
- API Documentation - Interactive examples with real responses
Simply open index.html in your browser - no installation needed!
# Clone the repository
git clone https://github.com/yourusername/openapi-worker-generator.git
cd openapi-worker-generator
# Open in browser
open index.html # macOS
# or
start index.html # Windows
# or
xdg-open index.html # Linux- Paste Schema - Add your OpenAPI 3.x JSON schema
- Select Fallback Mode - Choose how to generate mock data
- Generate - Click the button to create your worker
- Deploy - Copy or download
worker.jsandwrangler.toml
# Install Wrangler (Cloudflare's CLI)
npm install -g wrangler
# Login to Cloudflare
wrangler login
# Deploy your worker
wrangler deployThe generator uses a smart example precedence system:
- Named examples:
responses[status].content[type].examples[name].value - Inline example:
responses[status].content[type].example - Schema example:
responses[status].content[type].schema.example - Selected fallback mode (see below)
{
"ok": true,
"mocked": true,
"path": "/users"
}Simple, reliable response when no schema is available.
{
"id": 0,
"name": "string",
"email": "user@example.com",
"active": false
}Generates typed mock data based on your schema definitions.
{
"id": 847,
"name": "xkpqwmfhzt",
"email": "user529@example.com",
"active": true
}Creates realistic, randomized mock data with variety.
{
"openapi": "3.0.0",
"info": {
"title": "Users API",
"version": "1.0.0"
},
"paths": {
"/users": {
"get": {
"summary": "List all users",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"example": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]
}
}
}
}
}
},
"/users/{id}": {
"get": {
"summary": "Get user by ID",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": { "type": "integer" }
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
}
}
}
}
}
}
}
}
}
}The generated Cloudflare Worker includes:
- โ Regex-based routing - Fast path matching with parameter support
- โ CORS headers - Pre-configured for cross-origin requests
- โ OPTIONS handling - Automatic preflight request support
- โ
Content negotiation - Respects
Content-Typefrom schema - โ Status codes - Uses correct HTTP status from your spec
- โ 404 handling - Graceful fallback for unmatched routes
- โ No runtime dependencies - Pure JavaScript, no external libs
openapi-worker-generator/
โโโ index.html # Main UI structure
โโโ style.css # Dark theme styling
โโโ app.js # Core generator logic
โ โโโ Utilities # Escaping, regex, type generation
โ โโโ Parser # OpenAPI schema parsing
โ โโโ Generator # Worker code generation
โ โโโ UI # Event handlers, display
โโโ README.md # This file
| Feature | Supported | Notes |
|---|---|---|
| OpenAPI 3.0.x | โ | Full support |
| OpenAPI 3.1.x | โ | Full support |
| Path parameters | โ | {id} converted to regex |
| Query parameters | Ignored (mocks don't validate) | |
| Request bodies | Ignored (mocks return examples) | |
| Multiple responses | โ | Uses first 2xx or first available |
| Examples | โ | Named, inline, and schema examples |
| Content types | โ | Respects Content-Type header |
| Security | Not validated (future feature) | |
| Callbacks | โ | Not supported |
| Links | โ | Not supported |
Future enhancements planned:
- Authentication mocking - Basic/Bearer token validation
- Delay simulation -
x-mock-delayextension support - Query param overrides -
?__status=404&__example=error - TypeScript output - Optional TS worker generation
- Multiple workers - Split by tag/path prefix
- Request logging - Optional console/analytics integration
- State simulation - POST/PUT/DELETE state tracking
- Webhook forwarding - Proxy real requests to external URLs
Contributions are welcome! The codebase is designed to be modular and extensible.
MIT License - see LICENSE file for details.
- Inspired by the need for instant API mocking during frontend development
- Built for developers who need reliable mock APIs without complex setup
- Designed with Cloudflare Workers' simplicity and performance in mind