Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/openapi-ts/configuration/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};
```

<!--@include: ../../partials/examples.md-->
<!--@include: ../../partials/sponsors.md-->
16 changes: 13 additions & 3 deletions packages/openapi-ts/src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,19 @@ export const createClient = async ({
}): Promise<Context | undefined> => {
const watches: ReadonlyArray<WatchValues> =
_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));

Expand Down
6 changes: 6 additions & 0 deletions packages/openapi-ts/src/types/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*
Expand Down
Loading