actgardner / gogen-avro

Generate Go code to serialize and deserialize Avro schemas
MIT License
366 stars 87 forks source link

Same enum name in different namespace #169

Closed cmouli84 closed 3 years ago

cmouli84 commented 3 years ago

Hi

We are running into an issue due to same enum name present in different namespaces. Find below the sample schema to illustrate the issue we are running into

{
  "type": "record",
  "name": "SomeType",
  "namespace": "com.company.team",
  "fields": [
    {
      "name": "fieldOne",
      "type": {
        "name": "TypeOne",
        "type": "record",
        "namespace": "com.company.team",
        "fields": [
          {
            "name": "type",
            "type": {
              "type": "enum",
              "name": "SomeEnum",
              "symbols": [
                "A",
                "B",
                "C"
              ]
            }
          }
        ]
      }
    },
    {
      "name": "fieldTwo",
      "type": {
        "name": "TypeTwo",
        "type": "record",
        "namespace": "com.company.shared",
        "fields": [
          {
            "name": "type",
            "type": {
              "type": "enum",
              "name": "SomeEnum",
              "symbols": [
                "X",
                "Y"
              ]
            }
          }
        ]
      }
    }
  ]
}

In the above schema, SomeEnum is present under namespaces com.company.team and com.company.shared and the enum in those namespaces allows for different set of values. But the generated go structs refer to same enum from com.company.shared.

type ComCompanyTeamSomeType struct {
    FieldOne ComCompanyTeamTypeOne `json:"fieldOne"`

    FieldTwo ComCompanySharedTypeTwo `json:"fieldTwo"`
}

type ComCompanyTeamTypeOne struct {
    Type SomeEnum `json:"type"`
}

type ComCompanySharedTypeTwo struct {
    Type SomeEnum `json:"type"`
}

type SomeEnum int32

const (
    SomeEnumX SomeEnum = 0
    SomeEnumY SomeEnum = 1
)

Command used to generate the go struct

gogen-avro -namespaced-names=full -package=schema schema/. schema.avsc

Is it possible to generate namespaced enums similar to go struct when -namespaced-names=full is set?

Thanks

dylanmei commented 3 years ago

The issue appears to be related: https://github.com/actgardner/gogen-avro/issues/13#issuecomment-278990580

actgardner commented 3 years ago

Hi @cmouli84, can you confirm if this issue still exists in the latest release (10.1.0)?

cmouli84 commented 3 years ago

Thanks @actgardner Issue is resolved with latest release (10.1.0)