OpenAPITools / OpenAPITools/openapi-generator

[BUG][Go][Client] Empty object generates compilation failure

Open
#3,829 3 comments 3 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

Version
4.1.1

Command line used for generation
openapi-generator generate -i swagger.yaml -g go-o ./

Spec

swagger: "2.0"
info: 
  title: Foo
  version: v1
paths: 
  /foo: 
    post:
      operationId: fooPost
      parameters: 
        - 
          in: body
          name: body
          required: false
          schema: 
            $ref: "#/definitions/Foo"
      responses: 
        200: 
          description: "successful operation"
definitions: 
  Foo: 
    type: object

Description
Generated Foo model is:

type FooPostOpts struct {
	Body optional.Map[string]interface{}
}

which does not compile as optional.Map does not exist.
I would expect this model definition instead:

type FooPostOpts struct {
	Body map[string]interface{}
}

I can reproduce this issue with any object without properties.

cc @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09) @bkabrda (2019/07)
@wing328

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 running the provided openapi-generator command with the minimal swagger.yaml specification and inspect the generated Go client's FooPostOpts model. Trace how an empty object definition is represented for the optional body parameter, then verify that the generated client compiles and uses a valid map type.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.