A TypeScript tool that generates Cloudflare Workers-compatible API stubs and types from OpenAPI YAML specifications.
- 🚀 Cloudflare Workers Native: Generates code specifically optimized for Cloudflare Workers
- 📝 Complete Type Generation: Converts OpenAPI schemas to comprehensive TypeScript interfaces
- 🔄 Modular Architecture: Creates separate workers for each route group
- ⚡ Zero Dependencies: Generated code runs without external runtime dependencies
- 🛠️ Configurable: Support for custom API endpoints and authentication
- 🎯 AI-Ready: Optional AI enhancement for business logic (when API key provided)
npm install
npm run build- Place your OpenAPI YAML file in the
examples/directory - Configure your settings in
src/config/index.ts - Run the generator:
npm run generateEdit src/config/index.ts:
export const config = {
outputDir: './generated',
apiKey: process.env.OPENAI_API_KEY, // Optional: for AI enhancement
apiUrl: 'https://api.openai.com/v1', // Optional: custom AI endpoint
generateCloudflareWorkers: true,
enableTypeGeneration: true,
};The tool generates:
types.ts: Complete TypeScript type definitionsapi-client.ts: Cloudflare Workers-compatible API clientworker.ts: Main router that delegates to route-specific workers*_worker.ts: Individual workers for each route group (audio, chat, etc.)
generated/
├── types.ts # TypeScript interfaces
├── api-client.ts # API client with fetch methods
├── worker.ts # Main router worker
├── audio_worker.ts # Audio-related endpoints
├── chat_worker.ts # Chat completions
├── assistants_worker.ts # AI assistants
└── ... # Additional route workers
- Copy generated files to your Workers project
- Set environment variables:
API_KEY=your_api_key API_BASE_URL=https://api.openai.com/v1 - Deploy using Wrangler:
wrangler deploy
// Import the main worker
import worker from './generated/worker';
export default worker;-
Clone the repository:
git clone <repository-url> -
Navigate to the project directory:
cd openapi-stub-generator -
Install the dependencies:
npm install
-
Configure the API endpoint and key in
src/config/index.ts. -
Place your OpenAPI YAML file in the
examplesdirectory. -
Run the generator:
npm run generate -
Check the
distdirectory for the generated stubs and types.
Refer to examples/basic-usage.ts for a demonstration of how to use the stub generator tool with a sample OpenAPI YAML file.
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.