OpenAPITools / OpenAPITools/openapi-generator

[BUG] [GO] Issues when downloading files

Open
#12,810 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

one endpoint I have is for downloading files and so I defined the response as such in the contract:

      responses:
        '200':
          description: Resource returned OK.
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary

in the now deprecated client, the endpoint definition was generated as such

/*
 * Execute executes the request
 * @return *os.File
 */
func (a *...ApiService) Get...Execute(r ApiGet...Request) (*os.File, *_nethttp.Response, GenericOpenAPIError) {
...

whereas, it is now generated as follows:

// Execute executes the request
//  @return *os.File
func (a *...ApiService) Get....Execute(r ApiGet...Request) (**os.File, *http.Response, error) {
	

I am not entirely sure why the returned type is **os.File instead of *os.File but this has the consequence to fail the download of files because the decode method does not handle this properly because that switch case https://github.com/OpenAPITools/openapi-generator/blob/0eca6291275394dab1bff79c9b4b6737202a9be9/modules/openapi-generator/src/main/resources/go/client.mustache#L423 is ignored since v is now of ***os.File

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 in modules/openapi-generator/src/main/resources/go/client.mustache around the referenced decode switch case. Reproduce the file-download endpoint with an application/octet-stream response and inspect the generated Go client’s Execute and decode behavior. Done means the generated return type is *os.File and the download is decoded successfully without the extra pointer level.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.