OpenAPITools / OpenAPITools/openapi-generator

[BUG][Golang][client] README.md example wrong return value

Open
#2,795 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Go 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

All my operations are generated with a return signature that is a 3-tuple, for example:

func (a *UserApiService) Create(ctx context.Context, userCreatePayload UserCreatePayload) (UserCreateResponse, *http.Response, error) {

README.md however lists this as an example:

r, err := client.Service.Operation(auth, args)

This is wrong as it suggests that the return value is a 2-tuple.

openapi-generator version

Happens both in 4.0.0-beta3 and 3.3.4

OpenAPI declaration file content or url

I'm honestly not sure how to find a reproducer for this. It happens with openapi-generator installed through npm, but I can't reproduce it on the petstore example, where the generated operations really do seem to return 2-tuples.

The template go/api.mustache does have this:

func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {

which suggests that the first return value only gets rendered if {{returnType}} is defined, but the README doesn't take this into account. However I'm not sure where this value comes from and why I can't reproduce on the petstore example.

Command line used for generation

openapi-generator generate -g go -c config/languages/go.json -i spec/full_spec.yaml -o generated/myclient

Steps to reproduce

For me, the reproducer is just running the above command.

Related issues/PRs

I haven't found any.

Suggest a fix

I think that taking the {{returnValue}} variable into account in the README example should fix this.

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

Read the Go client example in README.md and compare its return-value usage with the signature rendered by go/api.mustache. Confirm how the return value is represented for generated operations, then update the README example so it matches the documented generated signature and verify the example is consistent with the template.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.