Closed nicanor-romero closed 8 months ago
Hello! I have found a corner case where an avro record with an empty array as fields will yield go code that does not build due to unused variables.
record
fields
Example of avro (attention to "fields":[ ]):
"fields":[ ]
{ "type":"record", "name":"TestAvro", "fields":[ { "name":"TestAvroSubType", "type":[ { "type":"record", "name":"SubType_1", "fields":[ ] } ] } ] }
When running gogen-avro on this test_avro.avsc it will output this in the file sub_type_1.go:
gogen-avro
test_avro.avsc
sub_type_1.go
func (r SubType_1) MarshalJSON() ([]byte, error) { var err error output := make(map[string]json.RawMessage) return json.Marshal(output) } func (r *SubType_1) UnmarshalJSON(data []byte) error { var fields map[string]json.RawMessage if err := json.Unmarshal(data, &fields); err != nil { return err } var val json.RawMessage return nil }
where the var err error and var val json.RawMessage are unused, so the build fails.
var err error
var val json.RawMessage
When running gogen-avro after the proposed fix, it will yield the following:
func (r SubType_1) MarshalJSON() ([]byte, error) { output := make(map[string]json.RawMessage) return json.Marshal(output) } func (r *SubType_1) UnmarshalJSON(data []byte) error { var fields map[string]json.RawMessage if err := json.Unmarshal(data, &fields); err != nil { return err } return nil }
@actgardner any chance we can get this one merged?
Hello! I have found a corner case where an avro
record
with an empty array asfields
will yield go code that does not build due to unused variables.Example of avro (attention to
"fields":[ ]
):When running
gogen-avro
on thistest_avro.avsc
it will output this in the filesub_type_1.go
:where the
var err error
andvar val json.RawMessage
are unused, so the build fails.When running
gogen-avro
after the proposed fix, it will yield the following: