Skip to content

Commit

Permalink
- Fix: oneofs were not being emitted.
Browse files Browse the repository at this point in the history
  • Loading branch information
dorner committed Feb 26, 2024
1 parent dcf0931 commit 3bc19d2
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

# 0.5 - 2024-02-26

- Fix: oneofs were not being emitted.
1 change: 1 addition & 0 deletions avro/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func RecordFromProto(proto *descriptorpb.DescriptorProto, namespace string) []Na
if field.OneofIndex != nil && !field.GetProto3Optional() {
union := oneofs[field.GetOneofIndex()].Type.(Union)
union.Types = append(union.Types, FieldTypeFromProto(field))
oneofs[field.GetOneofIndex()].Type = union
} else {
fields = append(fields, FieldFromProto(field))
}
Expand Down
37 changes: 37 additions & 0 deletions testdata/base/AOneOf.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"type": "record",
"name": "AOneOf",
"namespace": "testdata",
"fields": [
{
"name": "a_oneof",
"type": [
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
},
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
],
"default": null
}
]
}
2 changes: 1 addition & 1 deletion testdata/base/AYowzaMapEntry.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"default": {}
}
]
}
}
12 changes: 12 additions & 0 deletions testdata/base/TypeA.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
}
12 changes: 12 additions & 0 deletions testdata/base/TypeB.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
44 changes: 44 additions & 0 deletions testdata/base/Widget.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,50 @@
"values": "testdata.StringList"
},
"default": {}
},
{
"name": "a_one_of",
"type": [
"null",
{
"type": "record",
"name": "AOneOf",
"namespace": "testdata",
"fields": [
{
"name": "a_oneof",
"type": [
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
},
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
],
"default": null
}
]
}
],
"default": null
}
]
}
37 changes: 37 additions & 0 deletions testdata/collapse_fields/AOneOf.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"type": "record",
"name": "AOneOf",
"namespace": "testdata",
"fields": [
{
"name": "a_oneof",
"type": [
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
},
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
],
"default": null
}
]
}
12 changes: 12 additions & 0 deletions testdata/collapse_fields/TypeA.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
}
12 changes: 12 additions & 0 deletions testdata/collapse_fields/TypeB.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
44 changes: 44 additions & 0 deletions testdata/collapse_fields/Widget.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,50 @@
"values": "testdata.StringList"
},
"default": {}
},
{
"name": "a_one_of",
"type": [
"null",
{
"type": "record",
"name": "AOneOf",
"namespace": "testdata",
"fields": [
{
"name": "a_oneof",
"type": [
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
},
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
],
"default": null
}
]
}
],
"default": null
}
]
}
44 changes: 44 additions & 0 deletions testdata/emit_only/Widget.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,50 @@
"values": "testdata.StringList"
},
"default": {}
},
{
"name": "a_one_of",
"type": [
"null",
{
"type": "record",
"name": "AOneOf",
"namespace": "testdata",
"fields": [
{
"name": "a_oneof",
"type": [
{
"type": "record",
"name": "TypeA",
"namespace": "testdata",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
},
{
"type": "record",
"name": "TypeB",
"namespace": "testdata",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
],
"default": null
}
]
}
],
"default": null
}
]
}
37 changes: 37 additions & 0 deletions testdata/namespace_map/AOneOf.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"type": "record",
"name": "AOneOf",
"namespace": "mynamespace",
"fields": [
{
"name": "a_oneof",
"type": [
{
"type": "record",
"name": "TypeA",
"namespace": "mynamespace",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
},
{
"type": "record",
"name": "TypeB",
"namespace": "mynamespace",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
],
"default": null
}
]
}
12 changes: 12 additions & 0 deletions testdata/namespace_map/TypeA.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "record",
"name": "TypeA",
"namespace": "mynamespace",
"fields": [
{
"name": "foo",
"type": "string",
"default": ""
}
]
}
12 changes: 12 additions & 0 deletions testdata/namespace_map/TypeB.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "record",
"name": "TypeB",
"namespace": "mynamespace",
"fields": [
{
"name": "bar",
"type": "string",
"default": ""
}
]
}
Loading

0 comments on commit 3bc19d2

Please sign in to comment.