OpenAPITools / OpenAPITools/openapi-generator
[REQ][Go] Allow streaming large response bodies
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Similar idea as #16640, with a slightly different approach in relation with Go.
The generated client only gives the option to stream bodies to memory via io.ReadAll. It doesn't give the option to stream the body to any other form (e.g. to disk).
Describe the solution you'd like
- Have the Execute functions avoid calling
io.ReadAllunless the content-type is json, xml, etc.- For example, if the content-type returns as octet-stream or similar, don't call
io.ReadAlland have those using this manually handle it using the*http.Responsereturn value.
- For example, if the content-type returns as octet-stream or similar, don't call
- Add a new function for each Execute called
ExecuteNoReadorExecuteWithBody; the idea is Execute will stay the same while the new function will always only return the(*http.Response, error)tuple.- In this case, calling Execute will always stream the entire body to memory, while the new function will give the users control over the response body.
Describe alternatives you've considered
I've been using raw HTTP requests using Go's standard library via net/http, having it return bodies yet to be streamed. I've also tried my own implementation for this issue (specifically solution 2), and it seems to run great with my projects.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the generated Go Execute functions and their uses of io.ReadAll, then review how the returned *http.Response is currently handled. Compare the two proposed approaches, including the existing discussion in #16640; done means large non-JSON response bodies can be controlled by callers without breaking existing Execute behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100