Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Union Generation for map[string]interface{} in Avro Schemas #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/avrogo/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ func canOmitUnionInfo(u typeInfo) bool {
// Check that either there's no union or the union is ["null", T]
// (the default union type for a pointer) and the Go type is also
// a pointer, meaning the avro package can infer that it's a
// pointer union.
return len(u.Union) == 0 || (len(u.Union) == 2 && u.Union[0].GoType == nullType && u.GoType[0] == '*')
// pointer union.
// If the union is ["null", map[string]T] then we can't omit the union
// Example: mapTest *map[string]interface{} `json:"mapTest"` will omit the union without this check for map
return len(u.Union) == 0 || (len(u.Union) == 2 && u.Union[0].GoType == nullType && u.GoType[0] == '*' && len(u.GoType) > 3 && u.GoType[:4] != "*map")

}

func writeUnionInfo(w io.Writer, info typeInfo) {
Expand Down