|
3 | 3 | namespace LEGO.AsyncAPI.Models
|
4 | 4 | {
|
5 | 5 | using System.Collections.Generic;
|
| 6 | + using System.Linq; |
6 | 7 | using LEGO.AsyncAPI.Writers;
|
7 | 8 |
|
8 | 9 | public class AvroRecord : AvroFieldType
|
9 | 10 | {
|
10 | 11 | public string Type { get; } = "record";
|
11 | 12 |
|
| 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> |
12 | 16 | public string Name { get; set; }
|
13 | 17 |
|
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; } |
15 | 27 |
|
16 | 28 | public IList<string> Aliases { get; set; } = new List<string>();
|
17 | 29 |
|
18 | 30 | public IList<AvroField> Fields { get; set; } = new List<AvroField>();
|
19 | 31 |
|
| 32 | + public IDictionary<string, AvroFieldType> Metadata { get; set; } = new Dictionary<string, AvroFieldType>(); |
| 33 | + |
20 | 34 | public override void SerializeV2(IAsyncApiWriter writer)
|
21 | 35 | {
|
22 | 36 | writer.WriteStartObject();
|
23 | 37 | writer.WriteOptionalProperty("type", this.Type);
|
24 | 38 | writer.WriteRequiredProperty("name", this.Name);
|
| 39 | + writer.WriteRequiredProperty("namespace", this.Namespace); |
25 | 40 | writer.WriteOptionalProperty("doc", this.Doc);
|
26 | 41 | writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
|
27 | 42 | 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 | + } |
28 | 58 | writer.WriteEndObject();
|
29 | 59 | }
|
30 | 60 | }
|
|
0 commit comments