openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
Support for `fetchRetry` or being able to pass additional `ApiRequestOptions` to the service's methods.
Hey, while using the native fetch package, everything works as expected. However on some places in the code I am using retries. I tried to integrate fetch-retry-ts package that I've used before. It's basically just a wrapper on top of fetch that adds retry functionality. I am instantianing my fetchRetry like this:
import fetchWithRetry from 'fetch-retry-ts'
const fetchRetry = fetchWithRetry(fetch)
export default fetchRetry
Before implementing openapi-typescript-codegen package, I've used fetchRetry like this:
const requestOptions = {
method: 'GET',
retries: 5,
retryDelay: (attempt, error, response) => Math.pow(2, attempt) * 1000,
retryOn: [404],
}
const [error, response] = await to(fetchRetry(EndpointURL.value.GET.SingleDeed(id), requestOptions))
Now I'd like to use it the same, just together with the generated service's methods, but I was unable to pass these retry options to the generated SDK. I tried playing around with custom request file, but with no success, since I was unable to generate also the additional argument for passing additional request options (with the retry options) that would my custom request file use (where I am trying to call fetchRetry instead of fetch).
Basically from this:
public static deedDeedRetrieve(id: string): CancelablePromise<Offer> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/v1/deed/deed/{id}/',
path: {
'id': id,
},
});
}
I'd need to do something like this (please note the added second parameter and passing the additionalRequestOptions down to the request method):
public static deedDeedRetrieve(id: string, additionalRequestOptions): CancelablePromise<Offer> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/v1/deed/deed/{id}/',
path: {
'id': id,
},
additionalRequestOptions, // passing down to the `request` function where I could use it when calling the `fetchRetry`
});
}
Do you have any idea how I could use the fetchRetry package and passing to it the retry options? Thanks!
hey @ferdikoomen , any thoughts on this? do you think it makes sense to introduce support for this? i could eventually open a PR once I will have time to spend some time on this:) thanks!