openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Support upload/download progress handlers

Open jgoz opened this issue 3 years ago • 6 comments

It would be great if the axios and xhr handlers supported per-request upload/download progress handlers. This is supported in the official openapi-generator package via client-specifc options that can be passed through to each request.

I'm not sure what would be the easiest path to support these handlers in this project. Fetch, Node, and Angular don't support progress callbacks, so maybe the quickest path would be to follow openapi-generator and accept optional request overrides on each request. These could even be opt-in via CLI arguments.

E.g.,

myService.uploadFile(fileBlob, {
  onUploadProgress: (progress) => {},
  // ... other client-specific request options
})

jgoz avatar Jun 15 '22 17:06 jgoz

+1

fugudesign avatar Jun 28 '22 07:06 fugudesign

Some cases could be handled through providing a custom axios instance since onUploadProgress is a constructor option. https://github.com/ferdikoomen/openapi-typescript-codegen/issues/942

Although supporting this on a per-request basis via config propagation would be nice.

As a temporary workaround I'm using axios request interceptors. This only works since axios is imported as a singleton in this package and this method patches the global axios instance.

axios.interceptors.request.use((config) => {
  config.onUploadProgress = (progressEvent) => {}
  return config
})

sourcec0de avatar Jul 29 '22 03:07 sourcec0de

I've created a PR that can solve this by allowing an axios custom instance, #1434. Please comment there so it will get attention 😄

Or-Zarchi-Forter avatar Feb 06 '23 13:02 Or-Zarchi-Forter

Check my PR #1682

50Bytes-dev avatar Aug 07 '23 19:08 50Bytes-dev

any update ?

jfroffice avatar Apr 11 '24 13:04 jfroffice

any update ?

Just use my PR #1682

50Bytes-dev avatar Apr 12 '24 06:04 50Bytes-dev