Watch Mode
Watch mode automatically regenerates your TypeScript client whenever your OpenAPI specification changes. This is particularly useful during development when your API is evolving.Overview
Watch mode polls your OpenAPI specification at regular intervals and regenerates the client when changes are detected. It works with both local files and remote URLs.Configuration
Watch mode is configured through theinput.watch property. The implementation is in /home/daytona/workspace/source/packages/shared/src/config/input/types.ts:175:
Basic Usage
CLI
Enable watch mode with the-w or --watch flag:
Configuration File
Configuration Options
enabled
Type: booleanDefault:
false
Enables or disables watch mode.
interval
Type: number (milliseconds)Default:
1000
How frequently to check for changes. The watcher polls the specification URL at this interval.
timeout
Type: number (milliseconds)Default:
60_000 (60 seconds)
How long to wait for the specification to download before timing out.
Multiple Inputs
Configure watch mode independently for each input:Global Watch Configuration
Apply watch settings to all inputs:How It Works
The watch mode implementation uses HTTP polling with conditional requests. From/home/daytona/workspace/source/packages/openapi-ts/src/createClient.ts:169:
Conditional Requests
Watch mode uses HTTP headers to avoid unnecessary regeneration:- ETag - Cached entity tags
- Last-Modified - Cached modification times
- If-None-Match - Conditional request headers
- If-Modified-Since - Conditional request headers
304 Not Modified, regeneration is skipped.
Authentication
For APIs requiring authentication, pass credentials via fetch options:Programmatic Usage
When usingcreateClient programmatically, watch mode runs indefinitely:
Detecting Watch Mode
Check if watch mode is active:Development Workflow
Package Scripts
Add watch mode to your development workflow:package.json
Docker Compose
Watch a specification served by Docker:docker-compose.yml
Error Handling
Watch mode handles errors gracefully to avoid crashing during development:Handling Transient Errors
If your API server restarts, watch mode will continue polling:Performance Considerations
Limitations
Local File Watching
For local files, use a file system watcher instead:watch.ts
Next Steps
Programmatic Usage
Learn how to use the createClient API programmatically
Custom Plugins
Build custom plugins to extend code generation