OpenAPITools / OpenAPITools/openapi-generator

[BUG] [GO] generated code for specific responses is adding double return statement.

Open
#4,469 0 comments 0 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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When running the generator for go-experimental in some cases where the paths have specific status codes to return such as CreateImages/ (see https://github.com/outscale/osc-api/blob/3283cc733026d04905905e0d949fea858cee833b/outscale.yaml#L6323) the code generated add double return value to the function and the code results like the following:

https://github.com/marinsalinas/osc-sdk-go/blob/63f74b7d7fe7a6b7716b21167b8acc1824670443/api_image.go#L149

This causes problems with go-vet it marks unreachable code.

openapi-generator version

4.2.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/outscale/osc-api/master/outscale.yaml

Command line used for generation

openapi-generator generate -i outscale.yaml -g go-experimental

Steps to reproduce

Run the following command:
openapi-generator generate -i outscale.yaml -g go-experimental

you can see the double return statement in oapi_image.go at line 149

Related issues/PRs
Suggest a fix

Remove this double line at:
https://github.com/OpenAPITools/openapi-generator/blob/99204ecd66b61df9d97d5b456a8f82d35febc0e1/modules/openapi-generator/src/main/resources/go-experimental/api.mustache#L334

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 with modules/openapi-generator/src/main/resources/go-experimental/api.mustache at line 334, then reproduce with the outscale.yaml specification and the command openapi-generator generate -i outscale.yaml -g go-experimental. Compare the generated oapi_image.go around line 149; done means the duplicate return is absent and go-vet no longer reports unreachable code.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.