OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.83k stars 6.58k forks source link

[GoLang] Array Items anyOf do not properly map #2622

Open stefan79 opened 5 years ago

stefan79 commented 5 years ago
Description

I have an object with a two-dimensional array, and the inner array items may be floator integer. If I attempt to generate the go client code it will create a nested map instead.

So instead of this:

Metrics map[string][][]map[string]interface{} `json:"metrics,omitempty"`

I was hoping for this:

Metrics map[string][][]interface{} `json:"metrics,omitempty"`
openapi-generator version

3.3.4

OpenAPI declaration file content or url
Command line used for generation

GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w" openapi-generator generate -i ../api/openapi.yaml -g go -o ../vendor/instana/openapi

Steps to reproduce

Create the client. (Bug is already apparent) Invoke a service. Note that JSON result cannot be mapped: panic: json: cannot unmarshal number into Go struct field MetricItem.metrics of type map[string]interface {}

Related issues/PRs
Suggest a fix/enhancement

I would have to dive in, I assume that the problem lies in org.openapitools.codegen.languages. AbstractGoCodegen as it "overmatches" the object type. See typeMapping.put("object", "map[string]interface{}");

auto-labeler[bot] commented 5 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

stefan79 commented 5 years ago

Anything I can do to help with this?