Skip to content

Commit 87b64da

Browse files
committed
implement metadata
1 parent de29635 commit 87b64da

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,58 @@
33
namespace LEGO.AsyncAPI.Models
44
{
55
using System.Collections.Generic;
6+
using System.Linq;
67
using LEGO.AsyncAPI.Writers;
78

89
public class AvroRecord : AvroFieldType
910
{
1011
public string Type { get; } = "record";
1112

13+
/// <summary>
14+
/// The name of the schema. Required for named types. See <a href="https://avro.apache.org/docs/1.9.0/spec.html#names">Avro Names</a>.
15+
/// </summary>
1216
public string Name { get; set; }
1317

14-
public string Doc { get; set; }
18+
/// <summary>
19+
/// The namespace of the schema. Useful for named types to avoid name conflicts.
20+
/// </summary>
21+
public string? Namespace { get; set; }
22+
23+
/// <summary>
24+
/// Documentation for the schema.
25+
/// </summary>
26+
public string? Doc { get; set; }
1527

1628
public IList<string> Aliases { get; set; } = new List<string>();
1729

1830
public IList<AvroField> Fields { get; set; } = new List<AvroField>();
1931

32+
public IDictionary<string, AvroFieldType> Metadata { get; set; } = new Dictionary<string, AvroFieldType>();
33+
2034
public override void SerializeV2(IAsyncApiWriter writer)
2135
{
2236
writer.WriteStartObject();
2337
writer.WriteOptionalProperty("type", this.Type);
2438
writer.WriteRequiredProperty("name", this.Name);
39+
writer.WriteRequiredProperty("namespace", this.Namespace);
2540
writer.WriteOptionalProperty("doc", this.Doc);
2641
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
2742
writer.WriteRequiredCollection("fields", this.Fields, (w, s) => s.SerializeV2(w));
43+
if (this.Metadata.Any())
44+
{
45+
foreach (var item in this.Metadata)
46+
{
47+
writer.WritePropertyName(item.Key);
48+
if (item.Value == null)
49+
{
50+
writer.WriteNull();
51+
}
52+
else
53+
{
54+
item.Value.SerializeV2(writer);
55+
}
56+
}
57+
}
2858
writer.WriteEndObject();
2959
}
3060
}

0 commit comments

Comments
 (0)