alexrosenfeld10 commented on code in PR #1966: URL: https://github.com/apache/avro/pull/1966#discussion_r1172695000
########## lang/csharp/src/apache/msbuild/AvroGenTask.cs: ########## @@ -0,0 +1,114 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.IO; +using System.Linq; +using System.Collections.Generic; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Avro.msbuild +{ + public class AvroGenTask : Task + { + public override bool Execute() + { + try + { + Dictionary<string, string> namespaceMapping = new Dictionary<string, string>(); + + MessageImportance messageImportance = string.IsNullOrEmpty(MessageLevel) ? + MessageImportance.Normal : + (MessageImportance)Enum.Parse(typeof(MessageImportance), MessageLevel); + + var codegen = new CodeGen(); + + if (!string.IsNullOrEmpty(NamespaceMapping)) + { + foreach(var mapping in NamespaceMapping.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + { + var parts = mapping.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); + if (parts.Length != 2) + { + throw new ArgumentException("Malformed namespace mapping. Required format is \"avro.namespace:csharp.namespace\""); + } + namespaceMapping[parts[0]] = parts[1]; + } + } + + if (SchemaFiles != null) + { + foreach (var schemaFile in SchemaFiles) + { + var schemaText = System.IO.File.ReadAllText(schemaFile.ItemSpec); + codegen.AddSchema(schemaText, namespaceMapping); Review Comment: Even if I inline the shared enum definition, like so: ```csharp var codeCompileUnit = new CodeGen { Schemas = { Schema.Parse(""" { "name": "PlanetEnum", "namespace": "My.Model", "type": "enum", "symbols": [ "Earth", "Mars" ] } """), Schema.Parse(schemaText) }, }.GenerateCode(); ``` it fails with: ```text Avro.SchemaParseException: Undefined name: My.Model.PlanetEnum at 'fields[4].type' at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace) at Avro.RecordSchema.createField(JToken jfield, Int32 pos, SchemaNames names, String encspace) at Avro.RecordSchema.NewInstance(Type type, JToken jtok, PropertyMap props, SchemaNames names, String encspace) at Avro.NamedSchema.NewInstance(JObject jo, PropertyMap props, SchemaNames names, String encspace) at Avro.Schema.ParseJson(JToken jtok, SchemaNames names, String encspace) at Avro.Schema.Parse(String json, SchemaNames names, String encspace) at Avro.Schema.Parse(String json) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
