[ 
https://issues.apache.org/jira/browse/AVRO-4187?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18029484#comment-18029484
 ] 

David Neukam commented on AVRO-4187:
------------------------------------

I added a patch with a fix by doing an opposite replacement for the SCHEMA 
property to keep changes and impact limited to the issue without causing 
side-effects to the overall generation.

Existing tests are adapted to find the issue, as the given samples in the tests 
are already providing sufficient samples to reproduce the issue but were 
lacking an assertion.

> Avrogen (csharp) --namespace causes "SCHEMA" to contain csharp instead of 
> avro namespaces leading to the serializer not finding the schema in the 
> schema registry
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AVRO-4187
>                 URL: https://issues.apache.org/jira/browse/AVRO-4187
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp
>    Affects Versions: 1.11.1, 1.12.0
>            Reporter: David Neukam
>            Priority: Major
>         Attachments: 
> 0001-fix-AVRO-4187-fix-bug-causing-csharp-Avrogen-generat.patch
>
>
> When using *avrogen* for generating C# models from a schemafile, the 
> *--namespace* option doesn't behave as expected.
> When running 
> {code:java}
> avrogen -s file.avsc . --namespace my.avro.ns:my.csharp.ns
> {code}
> the namespace within the SCHEMA property of the generated C# files is changed 
> to {*}my.csharp.ns{*}, but should be left with value *my.avro.ns.*
>  
> This was introduced with the bugfix in AVRO-2883.
>  
> Example of expected output ({*}TestModel.cs{*}):
> {code:java}
> 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}
>  
> Example of *ACTUAL* output ({*}TestModel.cs{*}):
> {code:java}
> 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.csharp.ns\",\"fields\":[{\"name\":\"e"
>  +
>                               
> "ventType\",\"type\":{\"type\":\"enum\",\"name\":\"EventType\",\"namespace\":\"my.csharp.ns\",\"sym"
>  +
>                               
> "bols\":[\"CREATE\",\"UPDATE\",\"DELETE\"]}}]}");
>               private my.csharp.ns.EventType _eventType;
>                // More generated code
>         }
> }{code}
>  
> This issue is already mentioned in the comments of AVRO-2883:
> {quote}Calling Schema.ToString() on the generated _SCHEMA property will use 
> the mapped namespaces. I suspect this could cause 
> [Confluent.SchemaRegistry.Serdes.SpecificSerializerImpl<T>.Serialize|https://github.com/confluentinc/confluent-kafka-dotnet/blob/0f44064fd7ff2513e5fb01230f0faab9f9715a64/src/Confluent.SchemaRegistry.Serdes.Avro/SpecificSerializerImpl.cs#L228]
>  not to find the schema in the schema registry, if it is configured to 
> neither register schemas automatically nor use the latest schema. I'm not 
> sure whether their schema registry distinguishes between schemas using 
> different namespaces.
> {quote}
> ??[~kniemitalo]??
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to