You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Martin Tzvetanov Grigorov (Jira)" <ji...@apache.org> on 2022/04/19 18:25:00 UTC
[jira] [Resolved] (AVRO-2883) Avrogen (csharp) namespace mapping missing for references
[ https://issues.apache.org/jira/browse/AVRO-2883?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Tzvetanov Grigorov resolved AVRO-2883.
---------------------------------------------
Fix Version/s: 1.11.1
1.12.0
Resolution: Fixed
> Avrogen (csharp) namespace mapping missing for references
> ---------------------------------------------------------
>
> Key: AVRO-2883
> URL: https://issues.apache.org/jira/browse/AVRO-2883
> Project: Apache Avro
> Issue Type: Bug
> Components: csharp
> Reporter: Thomas Vigh Sørensen
> Assignee: Zoltan Csizmadia
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.11.1, 1.12.0
>
> Time Spent: 2h
> Remaining Estimate: 0h
>
> 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
> {code:java}
> avrogen -s file.avsc . --namespace my.avro.ns:my.csharp.ns
> {code}
> 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:
> {code:json}
> {
> "type" : "record",
> "name" : "TestModel",
> "namespace" : "my.avro.ns",
> "fields" : [ {
> "name" : "eventType",
> "type" : {
> "type" : "enum",
> "name" : "EventType",
> "symbols" : [ "CREATE", "UPDATE", "DELETE" ]
> }
> } ]
> }
> {code}
> And running
> {code:java}
> avrogen -s models.avsc . --namespace my.avro.ns:my.csharp.ns
> {code}
>
> Will produce the following *EventType.cs*
> {code:c#}
> namespace my.csharp.ns
> {
> using System;
> using System.Collections.Generic;
> using System.Text;
> using Avro;
> using Avro.Specific;
>
> public enum EventType
> {
> CREATE,
> UPDATE,
> DELETE,
> }
> }
> {code}
>
> and the following *TestModel.cs*
> {code:c#}
> 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
> }
> }
> {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*):
> {code:c#}
> 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}
>
> Code for reproducing the issue can be found at: [https://github.com/FuKe/avrogen-namespace-bug]
--
This message was sent by Atlassian Jira
(v8.20.7#820007)