swagger-api / swagger-api/swagger-codegen

[GOLANG] Bug. Client codegen Post Body

Open
#5,442 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Go help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The issue here revolves around golang client generated code and having an untyped json expected in the body. The codegen will set the varLocalPostBody = &body, and body interface{}, so internally we will pass around the memory address of body instead of its contents. This causes client error: Unsupported 'Body' type/value when I attempt to pass a struct into the POST endpoint defined.

Swagger-codegen version

2.2.0. I'm calling via this jimschubert container

Swagger declaration file content or url
post:
      description: submitting a new JSON
      operationId: postJSON
      parameters:
        - in: body
          name: body
          description: JSON
          required: true
          schema:
            type: object
      responses:
        200:
          description: received Raw JSON
Command line used for generation

where the v1.yaml is my swagger spec

clientconfig.json is

{
  "packageName": "apiclient",
  "packageVersion": "1.0"
}
docker run -it -v $(pwd):/swag \
	          jimschubert/swagger-codegen-cli generate \
	          -i /swag/v1.yaml \
	          -l go \
	          -o /swag/out/api/client \
	          -c /swag/clientconfig.json
Steps to reproduce
  1. Specify a POST endpoint that takes untyped JSON
  2. Codegen
  3. Call the default_api.go function for that post. It should take interface{}
  4. See the client error: Unsupported 'Body' type/value

*I've also see the &body code if I specify a type integer

Related issues
Suggest a Fix

Pass around the actual contents of the interface {}

s/&body/body

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

Reproduce the issue with the provided v1.yaml, clientconfig.json, and Docker generation command, then inspect the generated client/default_api.go code for the POST operation. Compare how the interface{} body is passed with the reported Unsupported 'Body' type/value error; done means generated calls pass the body contents and the reproduction succeeds.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.