Skip to main content

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.
Watch mode is designed for remote specifications accessed via HTTP/HTTPS. For local file watching, consider using a file system watcher like nodemon or chokidar instead.

Configuration

Watch mode is configured through the input.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: boolean
Default: 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.
Setting a very low interval (< 100ms) can cause excessive network requests and may trigger rate limiting on some APIs.

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
If the server responds with 304 Not Modified, regeneration is skipped.

Authentication

For APIs requiring authentication, pass credentials via fetch options:

Programmatic Usage

When using createClient 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

Watch mode has several limitations:
  1. Remote URLs only - Designed for HTTP/HTTPS specifications
  2. Polling-based - Not as efficient as file system watching
  3. Single process - Runs in the foreground
  4. No file system events - Won’t detect local file changes

Local File Watching

For local files, use a file system watcher instead:
Or create a custom watcher:
watch.ts

Next Steps

Programmatic Usage

Learn how to use the createClient API programmatically

Custom Plugins

Build custom plugins to extend code generation