Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
Description
When using avrogen for generating C# models from a schemafile, the --namespace option doesn't behave as expected, if the model refers to other types (currently only tested with enums).
When running
avrogen -s file.avsc . --namespace my.avro.ns:my.csharp.ns
the actual namespace of the generated C# files is changed to my.csharp.ns, but any references between the models are not updated with the correct namespace.
Given a schemafile containing:
{
"type" : "record",
"name" : "TestModel",
"namespace" : "my.avro.ns",
"fields" : [ {
"name" : "eventType",
"type" : {
"type" : "enum",
"name" : "EventType",
"symbols" : [ "CREATE", "UPDATE", "DELETE" ]
}
} ]
}
And running
avrogen -s models.avsc . --namespace my.avro.ns:my.csharp.ns
Will produce the following EventType.cs
namespace my.csharp.ns { using System; using System.Collections.Generic; using System.Text; using Avro; using Avro.Specific; public enum EventType { CREATE, UPDATE, DELETE, } }
and the following TestModel.cs
namespace my.csharp.ns { using System; using System.Collections.Generic; using System.Text; using Avro; using Avro.Specific; public partial class TestModel : ISpecificRecord { public static Schema _SCHEMA = Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"TestModel\",\"namespace\":\"my.avro.ns\",\"fields\":[{\"name\":\"e" + "ventType\",\"type\":{\"type\":\"enum\",\"name\":\"EventType\",\"namespace\":\"my.avro.ns\",\"sym" + "bols\":[\"CREATE\",\"UPDATE\",\"DELETE\"]}}]}"); private my.avro.ns.EventType _eventType; // More generated code } }
Notice how the namespace is set correctly to my.csharp.ns in both files, but the namespace of the referenced EventType in TestModel.cs is incorrect.
Example of expected output (TestModel.cs):
namespace my.csharp.ns { using System; using System.Collections.Generic; using System.Text; using Avro; using Avro.Specific; public partial class TestModel : ISpecificRecord { public static Schema _SCHEMA = Avro.Schema.Parse("{\"type\":\"record\",\"name\":\"TestModel\",\"namespace\":\"my.avro.ns\",\"fields\":[{\"name\":\"e" + "ventType\",\"type\":{\"type\":\"enum\",\"name\":\"EventType\",\"namespace\":\"my.avro.ns\",\"sym" + "bols\":[\"CREATE\",\"UPDATE\",\"DELETE\"]}}]}"); private my.csharp.ns.EventType _eventType; // More generated code } }
Code for reproducing the issue can be found at: https://github.com/FuKe/avrogen-namespace-bug
Attachments
Issue Links
- causes
-
AVRO-4187 Avrogen (csharp) --namespace causes "SCHEMA" to contain csharp instead of avro namespaces leading to the serializer not finding the schema in the schema registry
-
- Patch Available
-
- links to