[GOLANG] Bug. Client codegen Post Body
#5.442 aberto em 20 de abr. de 2017
Métricas do repositório
- Stars
- (12.701 stars)
- Métricas de merge de PR
- (Nenhuma PRs mesclada em 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
- Specify a POST endpoint that takes untyped JSON
- Codegen
- Call the
default_api.gofunction for that post. It should takeinterface{} - 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