OpenAPITools / OpenAPITools/openapi-generator

[REQ][Go] Allow streaming large response bodies

Open
#24,543 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Have the Execute functions avoid calling io.ReadAll unless the content-type is json, xml, etc.
    • For example, if the content-type returns as octet-stream or similar, don't call io.ReadAll and have those using this manually handle it using the *http.Response return value.
  2. Add a new function for each Execute called ExecuteNoRead or ExecuteWithBody; 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.