Repository navigation
Expand file tree
/
Copy pathAvroMap.cs
More file actions
52 lines (45 loc) · 1.54 KB
/
Copy pathAvroMap.cs
File metadata and controls
52 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace ByteBard.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using ByteBard.AsyncAPI.Writers;
public class AvroMap : AsyncApiAvroSchema
{
public override string Type { get; } = "map";
public AvroPrimitiveType Values { get; set; }
/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public override IDictionary<string, AsyncApiAny> Metadata { get; set; } = new Dictionary<string, AsyncApiAny>();
public override void SerializeV2(IAsyncApiWriter writer)
{
this.SerializeCore(writer);
}
public override void SerializeV3(IAsyncApiWriter writer)
{
this.SerializeCore(writer);
}
public void SerializeCore(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredProperty("values", this.Values.GetDisplayName());
if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
writer.WriteAny(item.Value);
}
}
}
writer.WriteEndObject();
}
}
}