Skip to content

Commit 2fbd70f

Browse files
committed
mas
1 parent f2053e9 commit 2fbd70f

File tree

9 files changed

+172
-14
lines changed

9 files changed

+172
-14
lines changed

src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ public class AsyncApiAvroSchemaPayload : IAsyncApiMessagePayload
1010
{
1111
private AvroSchema schema;
1212

13-
public AsyncApiAvroSchemaPayload()
14-
{
15-
this.schema = new AvroSchema();
16-
}
17-
1813
public AsyncApiAvroSchemaPayload(AvroSchema schema)
1914
{
2015
this.schema = schema;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace LEGO.AsyncAPI.Models
44
{
5+
using System.Collections.Generic;
6+
using System.Linq;
57
using LEGO.AsyncAPI.Writers;
68

79
public class AvroArray : AvroSchema
@@ -10,11 +12,31 @@ public class AvroArray : AvroSchema
1012

1113
public AvroSchema Items { get; set; }
1214

15+
/// <summary>
16+
/// A map of properties not in the schema, but added as additional metadata.
17+
/// </summary>
18+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
19+
1320
public override void SerializeV2(IAsyncApiWriter writer)
1421
{
1522
writer.WriteStartObject();
1623
writer.WriteOptionalProperty("type", this.Type);
1724
writer.WriteRequiredObject("items", this.Items, (w, f) => f.SerializeV2(w));
25+
if (this.Metadata.Any())
26+
{
27+
foreach (var item in this.Metadata)
28+
{
29+
writer.WritePropertyName(item.Key);
30+
if (item.Value == null)
31+
{
32+
writer.WriteNull();
33+
}
34+
else
35+
{
36+
item.Value.SerializeV2(writer);
37+
}
38+
}
39+
}
1840
writer.WriteEndObject();
1941
}
2042
}

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace LEGO.AsyncAPI.Models
44
{
55
using System.Collections.Generic;
6+
using System.Linq;
67
using LEGO.AsyncAPI.Writers;
78

89
public class AvroEnum : AvroSchema
910
{
1011
public string Type { get; } = "enum";
1112

1213
public string Name { get; set; }
13-
14+
1415
public string Namespace { get; set; }
1516

1617
public string Doc { get; set; }
@@ -21,16 +22,36 @@ public class AvroEnum : AvroSchema
2122

2223
public string Default { get; set; }
2324

25+
/// <summary>
26+
/// A map of properties not in the schema, but added as additional metadata.
27+
/// </summary>
28+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
29+
2430
public override void SerializeV2(IAsyncApiWriter writer)
2531
{
2632
writer.WriteStartObject();
2733
writer.WriteOptionalProperty("type", this.Type);
2834
writer.WriteRequiredProperty("name", this.Name);
29-
writer.WriteRequiredProperty("namespace", this.Namespace);
35+
writer.WriteOptionalProperty("namespace", this.Namespace);
3036
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
3137
writer.WriteOptionalProperty("doc", this.Doc);
3238
writer.WriteRequiredCollection("symbols", this.Symbols, (w, s) => w.WriteValue(s));
3339
writer.WriteRequiredProperty("default", this.Default);
40+
if (this.Metadata.Any())
41+
{
42+
foreach (var item in this.Metadata)
43+
{
44+
writer.WritePropertyName(item.Key);
45+
if (item.Value == null)
46+
{
47+
writer.WriteNull();
48+
}
49+
else
50+
{
51+
item.Value.SerializeV2(writer);
52+
}
53+
}
54+
}
3455
writer.WriteEndObject();
3556
}
3657
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace LEGO.AsyncAPI.Models
55
using LEGO.AsyncAPI.Models.Interfaces;
66
using LEGO.AsyncAPI.Writers;
77
using System.Collections.Generic;
8+
using System.Linq;
89

910
/// <summary>
1011
/// Represents a field within an Avro record schema.
@@ -41,6 +42,11 @@ public class AvroField : IAsyncApiSerializable
4142
/// </summary>
4243
public IList<string> Aliases { get; set; } = new List<string>();
4344

45+
/// <summary>
46+
/// A map of properties not in the schema, but added as additional metadata.
47+
/// </summary>
48+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
49+
4450
public void SerializeV2(IAsyncApiWriter writer)
4551
{
4652
writer.WriteStartObject();
@@ -50,6 +56,21 @@ public void SerializeV2(IAsyncApiWriter writer)
5056
writer.WriteOptionalObject("default", this.Default, (w, s) => w.WriteAny(s));
5157
writer.WriteOptionalProperty("order", this.Order);
5258
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
59+
if (this.Metadata.Any())
60+
{
61+
foreach (var item in this.Metadata)
62+
{
63+
writer.WritePropertyName(item.Key);
64+
if (item.Value == null)
65+
{
66+
writer.WriteNull();
67+
}
68+
else
69+
{
70+
item.Value.SerializeV2(writer);
71+
}
72+
}
73+
}
5374
writer.WriteEndObject();
5475
}
5576
}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,48 @@ namespace LEGO.AsyncAPI.Models
44
{
55
using LEGO.AsyncAPI.Writers;
66
using System.Collections.Generic;
7+
using System.Linq;
78

89
public class AvroFixed : AvroSchema
910
{
1011
public string Type { get; } = "fixed";
1112

1213
public string Name { get; set; }
13-
public string Namespaace { get; set; }
14+
15+
public string? Namespaace { get; set; }
1416

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

1719
public int Size { get; set; }
1820

21+
/// <summary>
22+
/// A map of properties not in the schema, but added as additional metadata.
23+
/// </summary>
24+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
25+
1926
public override void SerializeV2(IAsyncApiWriter writer)
2027
{
2128
writer.WriteStartObject();
2229
writer.WriteOptionalProperty("type", this.Type);
2330
writer.WriteRequiredProperty("name", this.Name);
24-
writer.WriteRequiredProperty("name", this.Namespaace);
31+
writer.WriteOptionalProperty("namespace", this.Namespaace);
2532
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
2633
writer.WriteRequiredProperty("size", this.Size);
34+
if (this.Metadata.Any())
35+
{
36+
foreach (var item in this.Metadata)
37+
{
38+
writer.WritePropertyName(item.Key);
39+
if (item.Value == null)
40+
{
41+
writer.WriteNull();
42+
}
43+
else
44+
{
45+
item.Value.SerializeV2(writer);
46+
}
47+
}
48+
}
2749
writer.WriteEndObject();
2850
}
2951
}

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,40 @@ namespace LEGO.AsyncAPI.Models
44
{
55
using System;
66
using System.Collections.Generic;
7+
using System.Linq;
78
using LEGO.AsyncAPI.Writers;
89

910
public class AvroMap : AvroSchema
1011
{
1112
public string Type { get; } = "map";
1213

13-
public IDictionary<string, string> Values { get; set; } = new Dictionary<string, string>();
14+
public AvroPrimitiveType Values { get; set; }
15+
16+
/// <summary>
17+
/// A map of properties not in the schema, but added as additional metadata.
18+
/// </summary>
19+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
1420

1521
public override void SerializeV2(IAsyncApiWriter writer)
1622
{
17-
Convert.ToBoolean()
1823
writer.WriteStartObject();
1924
writer.WriteOptionalProperty("type", this.Type);
20-
writer.WriteRequiredObject("values", this.Values, (w, f) => f.SerializeV2(w));
25+
writer.WriteRequiredProperty("values", this.Values.GetDisplayName());
26+
if (this.Metadata.Any())
27+
{
28+
foreach (var item in this.Metadata)
29+
{
30+
writer.WritePropertyName(item.Key);
31+
if (item.Value == null)
32+
{
33+
writer.WriteNull();
34+
}
35+
else
36+
{
37+
item.Value.SerializeV2(writer);
38+
}
39+
}
40+
}
2141
writer.WriteEndObject();
2242
}
2343
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,46 @@
22

33
namespace LEGO.AsyncAPI.Models
44
{
5+
using System.Collections.Generic;
6+
using System.Linq;
57
using LEGO.AsyncAPI.Writers;
68

79
public class AvroPrimitive : AvroSchema
810
{
911
public AvroPrimitiveType Type { get; set; }
1012

13+
/// <summary>
14+
/// A map of properties not in the schema, but added as additional metadata.
15+
/// </summary>
16+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
17+
1118
public AvroPrimitive(AvroPrimitiveType type)
1219
{
1320
this.Type = type;
1421
}
1522

23+
public AvroPrimitive()
24+
{
25+
}
26+
1627
public override void SerializeV2(IAsyncApiWriter writer)
1728
{
1829
writer.WriteValue(this.Type.GetDisplayName());
30+
if (this.Metadata.Any())
31+
{
32+
foreach (var item in this.Metadata)
33+
{
34+
writer.WritePropertyName(item.Key);
35+
if (item.Value == null)
36+
{
37+
writer.WriteNull();
38+
}
39+
else
40+
{
41+
item.Value.SerializeV2(writer);
42+
}
43+
}
44+
}
1945
}
2046
}
2147
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ public class AvroRecord : AvroSchema
2525
/// </summary>
2626
public string? Doc { get; set; }
2727

28+
/// <summary>
29+
///
30+
/// </summary>
2831
public IList<string> Aliases { get; set; } = new List<string>();
2932

33+
/// <summary>
34+
///
35+
/// </summary>
3036
public IList<AvroField> Fields { get; set; } = new List<AvroField>();
3137

32-
public IDictionary<string, AvroFieldType> Metadata { get; set; } = new Dictionary<string, AvroFieldType>();
38+
/// <summary>
39+
/// A map of properties not in the schema, but added as additional metadata.
40+
/// </summary>
41+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
3342

3443
public override void SerializeV2(IAsyncApiWriter writer)
3544
{
3645
writer.WriteStartObject();
3746
writer.WriteOptionalProperty("type", this.Type);
3847
writer.WriteRequiredProperty("name", this.Name);
39-
writer.WriteRequiredProperty("namespace", this.Namespace);
48+
writer.WriteOptionalProperty("namespace", this.Namespace);
4049
writer.WriteOptionalProperty("doc", this.Doc);
4150
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
4251
writer.WriteRequiredCollection("fields", this.Fields, (w, s) => s.SerializeV2(w));

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,41 @@
33
namespace LEGO.AsyncAPI.Models
44
{
55
using System.Collections.Generic;
6+
using System.Linq;
67
using LEGO.AsyncAPI.Writers;
78

89
public class AvroUnion : AvroSchema
910
{
1011
public IList<AvroSchema> Types { get; set; } = new List<AvroSchema>();
1112

13+
/// <summary>
14+
/// A map of properties not in the schema, but added as additional metadata.
15+
/// </summary>
16+
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();
17+
1218
public override void SerializeV2(IAsyncApiWriter writer)
1319
{
1420
writer.WriteStartArray();
1521
foreach (var type in this.Types)
1622
{
1723
type.SerializeV2(writer);
1824
}
25+
26+
if (this.Metadata.Any())
27+
{
28+
foreach (var item in this.Metadata)
29+
{
30+
writer.WritePropertyName(item.Key);
31+
if (item.Value == null)
32+
{
33+
writer.WriteNull();
34+
}
35+
else
36+
{
37+
item.Value.SerializeV2(writer);
38+
}
39+
}
40+
}
1941
writer.WriteEndArray();
2042
}
2143
}

0 commit comments

Comments
 (0)