Skip to content

Commit

Permalink
mas
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed May 30, 2024
1 parent f2053e9 commit 2fbd70f
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ public class AsyncApiAvroSchemaPayload : IAsyncApiMessagePayload
{
private AvroSchema schema;

public AsyncApiAvroSchemaPayload()
{
this.schema = new AvroSchema();
}

public AsyncApiAvroSchemaPayload(AvroSchema schema)
{
this.schema = schema;
Expand Down
22 changes: 22 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;

public class AvroArray : AvroSchema
Expand All @@ -10,11 +12,31 @@ public class AvroArray : AvroSchema

public AvroSchema Items { get; set; }

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public override void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredObject("items", this.Items, (w, f) => f.SerializeV2(w));
if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndObject();
}
}
Expand Down
25 changes: 23 additions & 2 deletions src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;

public class AvroEnum : AvroSchema
{
public string Type { get; } = "enum";

public string Name { get; set; }

public string Namespace { get; set; }

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

public string Default { get; set; }

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public override void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredProperty("name", this.Name);
writer.WriteRequiredProperty("namespace", this.Namespace);
writer.WriteOptionalProperty("namespace", this.Namespace);
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
writer.WriteOptionalProperty("doc", this.Doc);
writer.WriteRequiredCollection("symbols", this.Symbols, (w, s) => w.WriteValue(s));
writer.WriteRequiredProperty("default", this.Default);
if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndObject();
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace LEGO.AsyncAPI.Models
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
using System.Collections.Generic;
using System.Linq;

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

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
Expand All @@ -50,6 +56,21 @@ public void SerializeV2(IAsyncApiWriter writer)
writer.WriteOptionalObject("default", this.Default, (w, s) => w.WriteAny(s));
writer.WriteOptionalProperty("order", this.Order);
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndObject();
}
}
Expand Down
26 changes: 24 additions & 2 deletions src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,48 @@ namespace LEGO.AsyncAPI.Models
{
using LEGO.AsyncAPI.Writers;
using System.Collections.Generic;
using System.Linq;

public class AvroFixed : AvroSchema
{
public string Type { get; } = "fixed";

public string Name { get; set; }
public string Namespaace { get; set; }

public string? Namespaace { get; set; }

Check warning on line 15 in src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 15 in src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

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

public int Size { get; set; }

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public override void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredProperty("name", this.Name);
writer.WriteRequiredProperty("name", this.Namespaace);
writer.WriteOptionalProperty("namespace", this.Namespaace);
writer.WriteOptionalCollection("aliases", this.Aliases, (w, s) => w.WriteValue(s));
writer.WriteRequiredProperty("size", this.Size);
if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndObject();
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,40 @@ namespace LEGO.AsyncAPI.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;

public class AvroMap : AvroSchema
{
public string Type { get; } = "map";

public IDictionary<string, string> Values { get; set; } = new Dictionary<string, string>();
public AvroPrimitiveType Values { get; set; }

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public override void SerializeV2(IAsyncApiWriter writer)
{
Convert.ToBoolean()
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredObject("values", this.Values, (w, f) => f.SerializeV2(w));
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
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndObject();
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroPrimitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,46 @@

namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;

public class AvroPrimitive : AvroSchema
{
public AvroPrimitiveType Type { get; set; }

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public AvroPrimitive(AvroPrimitiveType type)
{
this.Type = type;
}

public AvroPrimitive()
{
}

public override void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteValue(this.Type.GetDisplayName());
if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
item.Value.SerializeV2(writer);
}
}
}
}
}
}
13 changes: 11 additions & 2 deletions src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,27 @@ public class AvroRecord : AvroSchema
/// </summary>
public string? Doc { get; set; }

Check warning on line 26 in src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 26 in src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

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

/// <summary>
///
/// </summary>
public IList<AvroField> Fields { get; set; } = new List<AvroField>();

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

public override void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteOptionalProperty("type", this.Type);
writer.WriteRequiredProperty("name", this.Name);
writer.WriteRequiredProperty("namespace", this.Namespace);
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));
Expand Down
22 changes: 22 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@
namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;

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

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public IDictionary<string, AvroSchema> Metadata { get; set; } = new Dictionary<string, AvroSchema>();

public override void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartArray();
foreach (var type in this.Types)
{
type.SerializeV2(writer);
}

if (this.Metadata.Any())
{
foreach (var item in this.Metadata)
{
writer.WritePropertyName(item.Key);
if (item.Value == null)
{
writer.WriteNull();
}
else
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndArray();
}
}
Expand Down

0 comments on commit 2fbd70f

Please sign in to comment.