diff --git a/CHANGELOG b/CHANGELOG index a315b97..0cd33f8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Changelog +# UNRELEASED + +- Fix: `collapse_fields` was only working on the first instance of the field, not when it was found inside a map etc. later on. + # 0.5 - 2024-02-26 - Fix: oneofs were not being emitted. diff --git a/avro/typeRepo.go b/avro/typeRepo.go index 0572617..fbb4f21 100644 --- a/avro/typeRepo.go +++ b/avro/typeRepo.go @@ -3,6 +3,7 @@ package avro import ( "fmt" "github.com/flipp-oss/protoc-gen-avro/input" + "slices" "strings" ) @@ -43,6 +44,11 @@ func (r *TypeRepo) SeenType(t NamedType) { func (r *TypeRepo) GetType(name string) (Type, error) { if r.seenTypes[name] { + if r.Types[name] != nil { + if slices.Contains(r.CollapseFields, r.Types[name].GetName()) { + return r.Types[name].(Record).Fields[0].Type, nil + } + } return Bare(r.MappedNamespace(name[1:])), nil } t, ok := r.Types[name] diff --git a/testdata/collapse_fields/Widget.avsc b/testdata/collapse_fields/Widget.avsc index dd0969f..23c8b08 100644 --- a/testdata/collapse_fields/Widget.avsc +++ b/testdata/collapse_fields/Widget.avsc @@ -171,7 +171,10 @@ "name": "string_map", "type": { "type": "map", - "values": "testdata.StringList" + "values": { + "type": "array", + "items": "string" + } }, "default": {} },