Skip to content

Commit

Permalink
- Fix: collapse_fields was only working on the first instance of th…
Browse files Browse the repository at this point in the history
…e field, not when it was found inside a map etc. later on.
  • Loading branch information
dorner committed Feb 27, 2024
1 parent 3bc19d2 commit 7e643f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions avro/typeRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package avro
import (
"fmt"
"github.com/flipp-oss/protoc-gen-avro/input"
"slices"
"strings"
)

Expand Down Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion testdata/collapse_fields/Widget.avsc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@
"name": "string_map",
"type": {
"type": "map",
"values": "testdata.StringList"
"values": {
"type": "array",
"items": "string"
}
},
"default": {}
},
Expand Down

0 comments on commit 7e643f6

Please sign in to comment.