diff --git a/docs/openapi-ts/configuration/input.md b/docs/openapi-ts/configuration/input.md index 6269d1c769..ab4db9283b 100644 --- a/docs/openapi-ts/configuration/input.md +++ b/docs/openapi-ts/configuration/input.md @@ -164,5 +164,19 @@ npx @hey-api/openapi-ts \ ::: +If your server doesn't support `HEAD` requests for incremental checks, you can pass an object to `input.watch` and disable them explicitly: + +```js +export default { + input: { + path: 'https://api.example.com/openapi.json', + watch: { + enabled: true, + isHeadMethodSupported: false, + }, + }, +}; +``` + diff --git a/packages/openapi-ts/src/createClient.ts b/packages/openapi-ts/src/createClient.ts index 2ce32962f8..5020ce6dec 100644 --- a/packages/openapi-ts/src/createClient.ts +++ b/packages/openapi-ts/src/createClient.ts @@ -250,9 +250,19 @@ export const createClient = async ({ }): Promise => { const watches: ReadonlyArray = _watches || - Array.from({ length: config.input.length }, () => ({ - headers: new Headers(), - })); + Array.from({ length: config.input.length }, (_, index) => { + const watchValues: WatchValues = { + headers: new Headers(), + }; + + const isHeadMethodSupported = + config.input[index]?.watch.isHeadMethodSupported; + if (isHeadMethodSupported !== undefined) { + watchValues.isHeadMethodSupported = isHeadMethodSupported; + } + + return watchValues; + }); const inputPaths = config.input.map((input) => compileInputPath(input)); diff --git a/packages/openapi-ts/src/types/input.d.ts b/packages/openapi-ts/src/types/input.d.ts index 4821d19a1d..02b684986a 100644 --- a/packages/openapi-ts/src/types/input.d.ts +++ b/packages/openapi-ts/src/types/input.d.ts @@ -181,6 +181,12 @@ export type Watch = { * @default 1000 */ interval?: number; + /** + * Does the remote server support `HEAD` requests for change detection? + * Set this to `false` if you know the endpoint does not implement `HEAD` + * to avoid unnecessary requests during watch mode. + */ + isHeadMethodSupported?: boolean; /** * How long will we wait before the request times out? *