Repository navigation
Expand file tree
/
Copy pathAvroRecord.cs
More file actions
71 lines (61 loc) · 2.46 KB
/
Copy pathAvroRecord.cs
File metadata and controls
71 lines (61 loc) · 2.46 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;
public class AvroRecord : AvroSchema
{
public override string Type { get; } = "record";
/// <summary>
/// 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>.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The namespace of the schema. Useful for named types to avoid name conflicts.
/// </summary>
public string Namespace { get; set; }
/// <summary>
/// Documentation for the schema.
/// </summary>
public string Doc { get; set; }
/// <summary>
/// Alternate names for this record.
/// </summary>
public IList<string> Aliases { get; set; } = new List<string>();
/// <summary>
/// A list of fields contained within this record.
/// </summary>
public IList<AvroField> Fields { get; set; } = new List<AvroField>();
/// <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 SerializeV2WithoutReference(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredProperty("name", this.Name);
writer.WriteOptionalProperty("namespace", this.Namespace);
writer.WriteOptionalProperty("doc", this.Doc);
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
writer.WriteRequiredCollection("fields", this.Fields, (w, s) => s.SerializeV2(w));
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();
}
}
}