Skip to content

Commit f2053e9

Browse files
committed
WIP on alex/avro
1 parent 87b64da commit f2053e9

File tree

13 files changed

+185
-176
lines changed

13 files changed

+185
-176
lines changed

src/LEGO.AsyncAPI.Readers/V2/AsyncApiAvroSchemaDeserializer.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ namespace LEGO.AsyncAPI.Readers
1010

1111
public class AsyncApiAvroSchemaDeserializer
1212
{
13-
private static readonly FixedFieldMap<AvroSchema> schemaFixedFields = new()
14-
{
15-
{ "type", (a, n) => a.Type = n.GetScalarValue().GetEnumFromDisplayName<AvroSchemaType>() },
16-
{ "name", (a, n) => a.Name = n.GetScalarValue() },
17-
{ "namespace", (a, n) => a.Namespace = n.GetScalarValue() },
18-
{ "doc", (a, n) => a.Doc = n.GetScalarValue() },
19-
{ "fields", (a, n) => a.Fields = n.CreateList(LoadField) },
20-
};
21-
22-
public static AvroSchema LoadSchema(ParseNode node)
23-
{
24-
var mapNode = node.CheckMapNode("schema");
25-
var schema = new AvroSchema();
26-
27-
mapNode.ParseFields(ref schema, schemaFixedFields, null);
28-
29-
return schema;
30-
}
13+
// private static readonly FixedFieldMap<AvroSchema> schemaFixedFields = new()
14+
// {
15+
// { "type", (a, n) => a.Type = n.GetScalarValue() },
16+
// { "name", (a, n) => a.Name = n.GetScalarValue() },
17+
// { "namespace", (a, n) => a.Namespace = n.GetScalarValue() },
18+
// { "doc", (a, n) => a.Doc = n.GetScalarValue() },
19+
// { "fields", (a, n) => a.Fields = n.CreateList(LoadField) },
20+
// };
21+
22+
// public static AvroSchema LoadSchema(ParseNode node)
23+
// {
24+
// var mapNode = node.CheckMapNode("schema");
25+
// var schema = new AvroSchema();
26+
//
27+
// mapNode.ParseFields(ref schema, schemaFixedFields, null);
28+
//
29+
// return schema;
30+
// }
3131

3232
private static AvroField LoadField(ParseNode node)
3333
{
3434
var mapNode = node.CheckMapNode("field");
3535
var field = new AvroField();
36-
36+
3737
mapNode.ParseFields(ref field, fieldFixedFields, null);
38-
38+
3939
return field;
4040
}
4141

4242
private static readonly FixedFieldMap<AvroField> fieldFixedFields = new()
4343
{
4444
{ "name", (a, n) => a.Name = n.GetScalarValue() },
45-
{ "type", (a, n) => a.Type = LoadFieldType(n) },
45+
{ "type", (a, n) => a.Type = LoadSchema(n) },
4646
{ "doc", (a, n) => a.Doc = n.GetScalarValue() },
4747
{ "default", (a, n) => a.Default = n.CreateAny() },
4848
{ "order", (a, n) => a.Order = n.GetScalarValue() },
@@ -72,21 +72,21 @@ private static AvroField LoadField(ParseNode node)
7272
private static readonly FixedFieldMap<AvroArray> arrayFixedFields = new()
7373
{
7474
{ "type", (a, n) => { } },
75-
{ "items", (a, n) => a.Items = LoadFieldType(n) },
75+
{ "items", (a, n) => a.Items = LoadSchema(n) },
7676
};
7777

7878
private static readonly FixedFieldMap<AvroMap> mapFixedFields = new()
7979
{
8080
{ "type", (a, n) => { } },
81-
{ "values", (a, n) => a.Values = LoadFieldType(n) },
81+
{ "values", (a, n) => a.Values = LoadSchema(n) },
8282
};
8383

8484
private static readonly FixedFieldMap<AvroUnion> unionFixedFields = new()
8585
{
86-
{ "types", (a, n) => a.Types = n.CreateList(LoadFieldType) },
86+
{ "types", (a, n) => a.Types = n.CreateList(LoadSchema) },
8787
};
8888

89-
private static AvroFieldType LoadFieldType(ParseNode node)
89+
private static AvroSchema LoadSchema(ParseNode node)
9090
{
9191
if (node is ValueNode valueNode)
9292
{
@@ -98,7 +98,7 @@ private static AvroFieldType LoadFieldType(ParseNode node)
9898
var union = new AvroUnion();
9999
foreach (var item in node as ListNode)
100100
{
101-
union.Types.Add(LoadFieldType(item));
101+
union.Types.Add(LoadSchema(item));
102102
}
103103

104104
return union;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace LEGO.AsyncAPI.Models
44
{
55
using LEGO.AsyncAPI.Writers;
66

7-
public class AvroArray : AvroFieldType
7+
public class AvroArray : AvroSchema
88
{
99
public string Type { get; } = "array";
1010

11-
public AvroFieldType Items { get; set; }
11+
public AvroSchema Items { get; set; }
1212

1313
public override void SerializeV2(IAsyncApiWriter writer)
1414
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ namespace LEGO.AsyncAPI.Models
55
using System.Collections.Generic;
66
using LEGO.AsyncAPI.Writers;
77

8-
public class AvroEnum : AvroFieldType
8+
public class AvroEnum : AvroSchema
99
{
1010
public string Type { get; } = "enum";
1111

1212
public string Name { get; set; }
13+
14+
public string Namespace { get; set; }
1315

1416
public string Doc { get; set; }
1517

@@ -24,6 +26,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
2426
writer.WriteStartObject();
2527
writer.WriteOptionalProperty("type", this.Type);
2628
writer.WriteRequiredProperty("name", this.Name);
29+
writer.WriteRequiredProperty("namespace", this.Namespace);
2730
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
2831
writer.WriteOptionalProperty("doc", this.Doc);
2932
writer.WriteRequiredCollection("symbols", this.Symbols, (w, s) => w.WriteValue(s));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class AvroField : IAsyncApiSerializable
1919
/// <summary>
2020
/// The type of the field. Can be a primitive type, a complex type, or a union.
2121
/// </summary>
22-
public AvroFieldType Type { get; set; }
22+
public AvroSchema Type { get; set; }
2323

2424
/// <summary>
2525
/// The documentation for the field.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace LEGO.AsyncAPI.Models
55
using LEGO.AsyncAPI.Models.Interfaces;
66
using LEGO.AsyncAPI.Writers;
77

8-
public abstract class AvroFieldType : IAsyncApiSerializable
8+
public abstract class AvroSchema : IAsyncApiSerializable
99
{
10-
public static implicit operator AvroFieldType(AvroPrimitiveType type)
10+
public static implicit operator AvroSchema(AvroPrimitiveType type)
1111
{
1212
return new AvroPrimitive(type);
1313
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ namespace LEGO.AsyncAPI.Models
55
using LEGO.AsyncAPI.Writers;
66
using System.Collections.Generic;
77

8-
public class AvroFixed : AvroFieldType
8+
public class AvroFixed : AvroSchema
99
{
1010
public string Type { get; } = "fixed";
1111

1212
public string Name { get; set; }
13+
public string Namespaace { get; set; }
1314

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

@@ -20,6 +21,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
2021
writer.WriteStartObject();
2122
writer.WriteOptionalProperty("type", this.Type);
2223
writer.WriteRequiredProperty("name", this.Name);
24+
writer.WriteRequiredProperty("name", this.Namespaace);
2325
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
2426
writer.WriteRequiredProperty("size", this.Size);
2527
writer.WriteEndObject();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

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

7-
public class AvroMap : AvroFieldType
9+
public class AvroMap : AvroSchema
810
{
911
public string Type { get; } = "map";
1012

11-
public AvroFieldType Values { get; set; }
13+
public IDictionary<string, string> Values { get; set; } = new Dictionary<string, string>();
1214

1315
public override void SerializeV2(IAsyncApiWriter writer)
1416
{
17+
Convert.ToBoolean()
1518
writer.WriteStartObject();
1619
writer.WriteOptionalProperty("type", this.Type);
1720
writer.WriteRequiredObject("values", this.Values, (w, f) => f.SerializeV2(w));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace LEGO.AsyncAPI.Models
44
{
55
using LEGO.AsyncAPI.Writers;
66

7-
public class AvroPrimitive : AvroFieldType
7+
public class AvroPrimitive : AvroSchema
88
{
99
public AvroPrimitiveType Type { get; set; }
1010

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Copyright (c) The LEGO Group. All rights reserved.
1+
// Copyright (c) The LEGO Group. All rights reserved.
22

33
namespace LEGO.AsyncAPI.Models
44
{
55
using System.Collections.Generic;
66
using System.Linq;
77
using LEGO.AsyncAPI.Writers;
88

9-
public class AvroRecord : AvroFieldType
9+
public class AvroRecord : AvroSchema
1010
{
1111
public string Type { get; } = "record";
1212

0 commit comments

Comments
 (0)