Skip to content

gen: Create type safe union types #581

@petedannemann

Description

@petedannemann

Right now it appears that generated union types simply use any, which is not type safe. This means code needs to be written manually to make this type safe. Ideally there would be some option to generate the boilerplate code to make this type safe.

Example schema with a union type:

{
  "namespace": "com.test.avro",
  "type": "record",
  "name": "TestEvent",
  "doc": "Test event",
  "fields": [
    {
      "name": "exampleunion",
      "type": ["string", "long"]
    }
  ]
}

avrogen -pkg avro -o testevent.go TestEvent.avsc

testevent.go

// Code generated by avro/gen. DO NOT EDIT.
package avro

// Test event.
type TestEvent struct {
	Exampleunion any `avro:"exampleunion"`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions