Skip to content

Conversation

@dahaque
Copy link

@dahaque dahaque commented Dec 10, 2025

This PR adds first-class timeout support to the typescript-fetch generator so users can prevent requests from hanging indefinitely.

Why?

The current typescript-fetch client doesn’t offer any way to cancel or fail a request after a specified time.
When Kubernetes or any API becomes slow, consumers have no built-in way to enforce a timeout leading to stalled network calls.

This PR introduces a simple, lightweight solution.

What this PR does

  1. Adds a withTimeout() wrapper
    -Wraps fetch with an AbortController
    -Automatically aborts the request when timeout limit is reached
    -Forwards user-provided abort signals correctly

  2. Extends RequestContext
    -Adds a timeout?: number property
    -Ensures timeout travels through the request flow cleanly

  3. Integrates timeout into the generated IsomorphicFetchHttpLibrary
    -Replaces direct use of fetch
    -Uses withTimeout(fetch, request.getTimeout())
    so all requests automatically inherit the timeout setting

{{/browser}}
{{/platforms}}

function withTimeout(fetchFn: any, timeout?: number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR

what about adding a docstring explaining what this function does?

please also follow step 3 in the PR checklist to update the samples so that CI can verify the change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please specify what unit the number is, also in the modules/openapi-generator/src/main/resources/typescript/http/http.mustache

@wing328
Copy link
Member

wing328 commented Dec 11, 2025

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants