Skip to content

Commit

Permalink
implement metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed May 29, 2024
1 parent de29635 commit 87b64da
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,58 @@
namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Writers;

public class AvroRecord : AvroFieldType
{
public 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; }

public string Doc { get; set; }
/// <summary>
/// The namespace of the schema. Useful for named types to avoid name conflicts.
/// </summary>
public string? Namespace { get; set; }

Check warning on line 21 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>
/// Documentation for the schema.
/// </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.

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

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

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

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("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
{
item.Value.SerializeV2(writer);
}
}
}
writer.WriteEndObject();
}
}
Expand Down

0 comments on commit 87b64da

Please sign in to comment.