This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 3d23a1621 AVRO-3003: Fully qualify enum default value in C# code gen 
(#1596)
3d23a1621 is described below

commit 3d23a1621558627532cd2f8417c19e59b8bec6e7
Author: Jose Massada <[email protected]>
AuthorDate: Tue Apr 19 19:20:03 2022 +0100

    AVRO-3003: Fully qualify enum default value in C# code gen (#1596)
    
    (cherry picked from commit 3c3c05edf519ce41060c0534f0099c32f5bd8989)
---
 lang/csharp/src/apache/main/CodeGen/CodeGen.cs     |  2 +-
 .../csharp/src/apache/test/AvroGen/AvroGenTests.cs | 31 +++++++++++++++++++---
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs 
b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
index e2438d980..85ba07da6 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
@@ -784,7 +784,7 @@ namespace Avro
                 codeField.Attributes = MemberAttributes.Private;
                 if (field.Schema is EnumSchema es && es.Default != null)
                 {
-                    codeField.InitExpression = new 
CodeTypeReferenceExpression($"{es.Name}.{es.Default}");
+                    codeField.InitExpression = new 
CodeTypeReferenceExpression($"{es.Namespace}.{es.Name}.{es.Default}");
                 }
 
                 // Process field documentation if it exist and add to the field
diff --git a/lang/csharp/src/apache/test/AvroGen/AvroGenTests.cs 
b/lang/csharp/src/apache/test/AvroGen/AvroGenTests.cs
index 9b6a3a024..93e453190 100644
--- a/lang/csharp/src/apache/test/AvroGen/AvroGenTests.cs
+++ b/lang/csharp/src/apache/test/AvroGen/AvroGenTests.cs
@@ -421,7 +421,7 @@ namespace Avro.Test.AvroGen
         {
             TestSchema(schema, typeNamesToCheck, generatedFilesToCheck: 
generatedFilesToCheck);
         }
-        
+
         [TestCase(
             _nullableLogicalTypesArray,
             "org.apache.avro.codegentest.testdata", 
"org.apache.csharp.codegentest.testdata",
@@ -552,7 +552,7 @@ namespace Avro.Test.AvroGen
     ""name"" : ""ClassKeywords"",
     ""namespace"" : ""com.base"",
     ""fields"" :
-        [      
+        [
             { ""name"" : ""int"", ""type"" : ""int"" },
             { ""name"" : ""base"", ""type"" : ""long"" },
             { ""name"" : ""event"", ""type"" : ""boolean"" },
@@ -583,7 +583,7 @@ namespace Avro.Test.AvroGen
     ""name"" : ""SchemaObject"",
     ""namespace"" : ""schematest"",
     ""fields"" :
-        [      
+        [
             { ""name"" : ""myobject"", ""type"" :
                 [
                     ""null"",
@@ -605,7 +605,7 @@ namespace Avro.Test.AvroGen
        ""name"" : ""LogicalTypes"",
        ""namespace"" : ""schematest"",
        ""fields"" :
-               [       
+               [
                        { ""name"" : ""nullibleguid"", ""type"" : [""null"", 
{""type"": ""string"", ""logicalType"": ""uuid"" } ]},
                        { ""name"" : ""guid"", ""type"" : {""type"": 
""string"", ""logicalType"": ""uuid"" } },
                        { ""name"" : ""nullibletimestampmillis"", ""type"" : 
[""null"", {""type"": ""long"", ""logicalType"": ""timestamp-millis""}]  },
@@ -621,6 +621,29 @@ namespace Avro.Test.AvroGen
                ]
 }",
             new object[] { "schematest.LogicalTypes", typeof(Guid?), 
typeof(Guid), typeof(DateTime?), typeof(DateTime), typeof(DateTime?), 
typeof(DateTime), typeof(TimeSpan?), typeof(TimeSpan), typeof(TimeSpan?), 
typeof(TimeSpan), typeof(AvroDecimal?), typeof(AvroDecimal) })]
+        [TestCase(@"
+{
+  ""namespace"": ""enum.base"",
+  ""type"": ""record"",
+  ""name"": ""EnumInDifferentNamespace"",
+  ""doc"": ""Test enum with a default value in a different namespace"",
+  ""fields"": [
+    {
+      ""name"": ""anEnum"",
+      ""type"": {
+        ""namespace"": ""enum.base.other"",
+        ""type"": ""enum"",
+        ""name"": ""AnEnum"",
+        ""symbols"": [
+          ""A"",
+          ""B""
+        ],
+        ""default"": ""A""
+      }
+    }
+  ]
+}",
+            new object[] { "enum.base.EnumInDifferentNamespace", 
"enum.base.other.AnEnum" })]
         public void GenerateSchemaCheckFields(string schema, object[] result)
         {
             Assembly assembly = TestSchema(schema);

Reply via email to