OpenAPITools / OpenAPITools/openapi-generator
[BUG][Golang][Client] Response JSON array of object not handled in spec 2.0 but works in spec 3.0
Nobody has claimed this yet.
- 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
When using an OAS 2.0 spec with a response that is an array of object, the generated code attempts to return a map[string]interface{} which runs into an error when the array is unmarshaled.
OAS 2.0 results in the following method signature which attempts to return a map[string]interface{}
func (a *LocalesApiService) GetAllLocales(ctx context.Context) (map[string]interface{}, *http.Response, error) {
This results in the following error:
json: cannot unmarshal array into Go value of type map[string]interface {}
Using an OAS 3.0 spec works as expected. It returns a []Locale as expected:
func (a *LocalesApiService) GetAllLocales(ctx context.Context) ([]Locale, *http.Response, error) {
openapi-generator version
4.1.0-SNAPSHOT, master branch
OpenAPI declaration file content or url
Non-working 2.0 spec: https://github.com/grokify/go-ringcentral-engage/blob/fd5a68df4d1612de69bed7e35c10ceb337a8da32/codegen/partial-specs_v2.0.0/openapi-spec_locales.json
Working 3.0 spec: https://github.com/grokify/go-ringcentral-engage/blob/fd5a68df4d1612de69bed7e35c10ceb337a8da32/codegen/partial-specs_v3.0.0/openapi-spec_locales.json
Command line used for generation
$ java -jar openapi-generator-cli.jar generate -i partial-specs_v3.0.0/openapi-spec_locales.json -g go -o engagedigital --package-name engagedigital
Steps to reproduce
Build a SDK against the linked specs.
Related issues/PRs
https://github.com/grokify/go-ringcentral-engage/issues/2
Suggest a fix
Make it work like the OAS 3.0 spec.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the Go client from the linked OAS 2.0 and OAS 3.0 locale specs using the provided command, then compare the GetAllLocales signatures and response unmarshalling. The fix is done when the OAS 2.0 response generates and unmarshals as []Locale rather than map[string]interface{}.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100