elodina / go-avro

Apache Avro for Golang
http://elodina.github.io/go-avro/
Apache License 2.0
128 stars 55 forks source link

AVSC file reusing schema #88

Closed BenFradet closed 7 years ago

BenFradet commented 7 years ago

I have a schema file containing an array of record schemas like so:

[
  {
    "name": "ReusedRecord",
    "type": "record",
    "fields": [
      {
        "name": "aString",
        "type": "string"
      }
    ]
  },
  {
     "name": "MainRecord",
     "type": "record",
     "fields": [
        {
          "name": "reusedRecord1",
          "type": "ReusedRecord"
        },
        {
          "name": "reusedRecord1",
          "type": "ReusedRecord"
        }
     ]
  }
]

The code generation works as expected in java through avro-tools but using go-avro it fails with this error: https://github.com/elodina/go-avro/blob/master/codegen.go#L93-L96 since the root schema is a UnionSchema and not a RecordSchema.

Does someone know how to circumvent this issue? Or should I repeat the schema x times?

BenFradet commented 7 years ago

I circumvented the issue by defining one global schema reusing a few records across sub schemas.