swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.89k stars 6.03k forks source link

[golang] `"type": "object"` gets converted to `*interface{}` instead of `interface{}` #7474

Open grokify opened 6 years ago

grokify commented 6 years ago
Description

Definition property "type": "object" gets converted to *interface{} which returns an error when set to a struct or pointer pointer.

Swagger-codegen version

2.3.1

Swagger declaration file content or url

https://github.com/grokify/go-ringcentral/blob/28498505dba03a0d355a88e37d7c9ad1a338255b/codegen/swagger_ringcentral_spec.json

Command line used for generation

https://github.com/grokify/go-ringcentral/tree/28498505dba03a0d355a88e37d7c9ad1a338255b/codegen

java -jar swagger-codegen-cli.jar generate -c swagger_ringcentral_config.json -i swagger_ringcentral.json -l go -o .
Steps to reproduce
body := ringcentral.ScimUserPatch{
        Operations: []ringcentral.PatchOperationInfo{
            {
                Op: "add",
                Value: ringcentral.UserInfo{
                    Addresses: []ringcentral.AddressInfo{
                        {
                            Type_:         "work",
                            StreetAddress: "100 Main Street",
                            Locality:      "South Park",
                            Region:        "CO",
                            PostalCode:    "80440",
                            Country:       "US",
                        },
                    },
                },
            },
        },
        Schemas: []string{"urn:ietf:params:scim:api:messages:2.0:PatchOp"},
    }
Related issues/PRs

https://github.com/grokify/go-ringcentral/issues/10

Suggest a fix/enhancement

Set to interface{} instead of *interface{}

moshegood commented 3 years ago

Bump. This is still an issue.

You should pretty much never use *interface{} in go, as the regular interface{} is already nil-able.

HugoMario commented 3 years ago

hey @moshegood, thanks for bumping this. What is the best approach for this? i could help applying changes.

moshegood commented 3 years ago

Hi @HugoMario. I've got a fix to this in a PR here: https://github.com/swagger-api/swagger-codegen/pull/10932