You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
In clients generated with typescript-fetch and used in NodeJS, if a post-middleware is added to client (withPostMiddleware) and tries to read the body of the response, then the request will hang when the body is larger than 16kb.
The culprit is the invocation of Response.clone(). Similarly to ReadableStream.tee() (which I suspect clone is invoking under the hood), the usage of this method is intended to be used for parallel consumption of the stream; however, the generated code consumes it sequentially.
When using this method, both the consumer of the original response (the main API method) and the consumer of the clone (the middleware) have to continuously read the body stream. If one of them does not read it, the underlying stream of both of them will stop reading data from the source once it reaches the highWaterMark of the stream, which is essentially the max size of the stream's buffer. In NodeJS, the default value of highWaterMark is 16kb.
openapi-generator version
Latest (7.5.0), not a regression.
OpenAPI declaration file content or url
This applies to any response that contains a body.
Steps to reproduce
letapi=newMyGeneratedApi();api=api.withPostMiddleware(async(context: ResponseContext)=>{console.log(awaitcontext?.response?.text())});// hangs if body is larger than 16kbconstdata=awaitapi.getData();
Suggest a fix
Instead of cloning the response (here and here), the generated code should:
Fully read the body before invoking the post middlewares.
Pass the body it to the middle-wares as is (as a partial Response object).
Construct a new (node-fetch) Response, so that the main API call can consume the body normally (once we read the body in step 1, the original response can no longer be used).
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
In clients generated with
typescript-fetch
and used in NodeJS, if a post-middleware is added to client (withPostMiddleware
) and tries to read the body of the response, then the request will hang when the body is larger than 16kb.The culprit is the invocation of Response.clone(). Similarly to ReadableStream.tee() (which I suspect clone is invoking under the hood), the usage of this method is intended to be used for parallel consumption of the stream; however, the generated code consumes it sequentially.
When using this method, both the consumer of the original response (the main API method) and the consumer of the clone (the middleware) have to continuously read the body stream. If one of them does not read it, the underlying stream of both of them will stop reading data from the source once it reaches the highWaterMark of the stream, which is essentially the max size of the stream's buffer. In NodeJS, the default value of highWaterMark is 16kb.
openapi-generator version
Latest (7.5.0), not a regression.
OpenAPI declaration file content or url
This applies to any response that contains a body.
Steps to reproduce
Suggest a fix
Instead of cloning the response (here and here), the generated code should:
The text was updated successfully, but these errors were encountered: