Watch mode automatically regenerates your TypeScript client whenever your OpenAPI specification changes. This is particularly useful during development when your API is evolving.
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.
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:
export type Watch = { /** * Whether this feature is enabled. * * @default false */ enabled?: boolean; /** * How often should we attempt to detect the input file change? (in ms) * * @default 1000 */ interval?: number; /** * How long will we wait before the request times out? * * @default 60_000 */ timeout?: number;};
The watch mode implementation uses HTTP polling with conditional requests. From /home/daytona/workspace/source/packages/openapi-ts/src/createClient.ts:169:
When using createClient programmatically, watch mode runs indefinitely:
import { createClient } from '@hey-api/openapi-ts';// This will run forever in watch modeawait createClient({ input: { path: 'https://api.example.com/openapi.json', watch: true, }, output: 'src/client',});// This code will never executeconsole.log('Done!');
Watch mode handles errors gracefully to avoid crashing during development:
// From /home/daytona/workspace/source/packages/openapi-ts/src/createClient.ts:64if (error && !_watches) { // Throw on first run const text = await response.text().catch(() => ''); throw new Error( `Request failed with status ${response.status}: ${text || response.statusText}`, );}// Subsequent errors in watch mode are logged but don't throw// This allows the watcher to recover when the server comes back online