This is an automated email from the ASF dual-hosted git repository.
zoltan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new 6f362d598 AVRO-3953: Prefixing enum member identifiers instead of
throwing (#2783)
6f362d598 is described below
commit 6f362d5986d20d44694f1e8d8d09410870a4cc26
Author: Clemens Vasters <[email protected]>
AuthorDate: Tue Mar 5 21:41:04 2024 +0100
AVRO-3953: Prefixing enum member identifiers instead of throwing (#2783)
* AVRO-3953
Signed-off-by: Clemens Vasters <[email protected]>
* Unit test added. Removed local check for symbol.
---------
Signed-off-by: Clemens Vasters <[email protected]>
---
lang/csharp/src/apache/main/CodeGen/CodeGen.cs | 7 ------
lang/csharp/src/apache/test/CodGen/CodeGenTest.cs | 27 +++++++++++++++++++++++
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
index 7e7936272..73b95852d 100644
--- a/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
+++ b/lang/csharp/src/apache/main/CodeGen/CodeGen.cs
@@ -474,8 +474,6 @@ namespace Avro
/// <exception cref="CodeGenException">
/// Unable to cast schema into an enum
/// or
- /// Enum symbol " + symbol + " is a C# reserved keyword
- /// or
/// Namespace required for enum schema " + enumschema.Name.
/// </exception>
protected virtual void processEnum(Schema schema)
@@ -498,11 +496,6 @@ namespace Avro
foreach (string symbol in enumschema.Symbols)
{
- if (CodeGenUtil.Instance.ReservedKeywords.Contains(symbol))
- {
- throw new CodeGenException("Enum symbol " + symbol + " is
a C# reserved keyword");
- }
-
CodeMemberField field = new CodeMemberField(typeof(int),
symbol);
ctd.Members.Add(field);
}
diff --git a/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
b/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
index f8eef4a9a..33c7f0cf6 100644
--- a/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
+++ b/lang/csharp/src/apache/test/CodGen/CodeGenTest.cs
@@ -109,6 +109,33 @@ namespace Avro.Test.CodeGen
Assert.That(hasPlanetEnumCode);
Assert.That(Regex.Matches(planetEnumCode, "public enum
PlanetEnum").Count, Is.EqualTo(1));
}
+
+ [Test]
+ public void EnumWithKeywordSymbolsShouldHavePrefixedSymbols()
+ {
+ AddSchema(@"{
+ ""type"": ""enum"",
+ ""symbols"": [
+ ""string"",
+ ""integer"",
+ ""float"",
+ ""boolean"",
+ ""list"",
+ ""dict"",
+ ""regex""
+ ],
+ ""name"": ""type"",
+ ""namespace"": ""com.example""
+}");
+ GenerateCode();
+ var types = GetTypes();
+ Assert.That(types.Count, Is.EqualTo(1));
+ bool hasTypeCode = types.TryGetValue("type", out string
typeCode);
+ Assert.That(hasTypeCode);
+ Assert.That(Regex.Matches(typeCode, "public enum type").Count,
Is.EqualTo(1));
+ Assert.That(Regex.Matches(typeCode, "@string,").Count,
Is.EqualTo(1));
+ Assert.That(Regex.Matches(typeCode, "@float,").Count,
Is.EqualTo(1));
+ }
}
}
}