Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2883

Avrogen (csharp) namespace mapping missing for references

    XMLWordPrintableJSON

Details

    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

          Activity

            People

              zoltan_csizmadia Zoltan Csizmadia
              FuKe Thomas Vigh Sørensen
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 10m
                  2h 10m