Fix Union Generation for map[string]interface{} in Avro Schemas #129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of the avrogo code generator incorrectly omits union information for fields defined as map[string]interface{} in Avro schemas. This occurs specifically in cases where the union type is ["null", map[string]T]. The omission of this union information leads to incorrect code generation, not reflecting the intended schema's flexibility and complexity.
Example of Issue:
A field defined as mapTest *map[string]interface{} 'json:"mapTest"' in the Avro schema incorrectly omits the necessary union type information in the generated Go code.
Solution:
This pull request introduces a fix in the union type generation logic within the writeUnionInfo function. It specifically addresses the handling of map[string]interface{} fields to ensure the proper inclusion of union type information.
The fix involves updating the logic to recognize and correctly handle the ["null", map[string]T] union case, ensuring that it's not omitted during code generation. This change allows the generated Go code to accurately represent the Avro schema's structure and the intended flexibility of the map[string]interface{} field.