Skip to content

Commit

Permalink
fix: nullable slice generation (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored Jul 10, 2022
1 parent 9b3682f commit da6f796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,16 @@ func resolveRefSchema(s *avro.RefSchema) string {
func (g generator) resolveUnionTypes(unionSchema *avro.UnionSchema, acc *data) string {
nullIsAllowed := false
typesInUnion := make([]string, 0)
for _, elementSchema := range unionSchema.Types() {
if _, ok := elementSchema.(*avro.NullSchema); ok {
for _, elem := range unionSchema.Types() {
if _, ok := elem.(*avro.NullSchema); ok {
nullIsAllowed = true
} else {
typesInUnion = append(typesInUnion, g.generateFrom(elementSchema, acc))
continue
}

typesInUnion = append(typesInUnion, g.generateFrom(elem, acc))
}
if nullIsAllowed && len(typesInUnion) == 1 {
typ := typesInUnion[0]
if strings.HasPrefix(typ, "[]") {
return typ
}
return "*" + typ
return "*" + typesInUnion[0]
}
return "interface{}"
}
Expand Down
6 changes: 3 additions & 3 deletions gen/testdata/golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da6f796

Please sign in to comment.