Skip to content

Commit

Permalink
minor fixes and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed May 31, 2024
1 parent 1dd2468 commit 4f53f13
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 165 deletions.
4 changes: 4 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class AvroArray : AvroSchema
{
public override string Type { get; } = "array";

/// <summary>
/// The schema of the array's items.
/// </summary>
public AvroSchema Items { get; set; }

/// <summary>
Expand Down Expand Up @@ -37,6 +40,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndObject();
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,34 @@ public class AvroEnum : AvroSchema
{
public override string Type { get; } = "enum";

/// <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 enum.
/// </summary>
public IList<string> Aliases { get; set; } = new List<string>();

/// <summary>
/// Listing symbols. All symbols in an enum must be unique.
/// </summary>
public IList<string> Symbols { get; set; } = new List<string>();

/// <summary>
/// A default value for this enumeration.
/// </summary>
public string Default { get; set; }

/// <summary>
Expand Down Expand Up @@ -52,6 +70,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndObject();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/LEGO.AsyncAPI/Models/Avro/AvroField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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

/// <summary>
/// Represents a field within an Avro record schema.
Expand Down Expand Up @@ -38,7 +38,7 @@ public class AvroField : IAsyncApiSerializable
public string Order { get; set; }

/// <summary>
/// An array of strings, providing alternate names for this record (optional).
/// Alternate names for this record (optional).
/// </summary>
public IList<string> Aliases { get; set; } = new List<string>();

Expand Down Expand Up @@ -71,6 +71,7 @@ public void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndObject();
}
}
Expand Down
25 changes: 0 additions & 25 deletions src/LEGO.AsyncAPI/Models/Avro/AvroFieldType.cs

This file was deleted.

16 changes: 15 additions & 1 deletion src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@

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

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

/// <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>
/// Alternate names for this record.
/// </summary>
public IList<string> Aliases { get; set; } = new List<string>();

/// <summary>
/// Number of bytes per value.
/// </summary>
public int Size { get; set; }

/// <summary>
Expand Down Expand Up @@ -46,6 +59,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndObject();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndObject();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AvroRecord : AvroSchema
public string Doc { get; set; }

/// <summary>
///
/// Alternate names for this record.
/// </summary>
public IList<string> Aliases { get; set; } = new List<string>();

Expand Down Expand Up @@ -64,6 +64,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndObject();
}
}
Expand Down
139 changes: 25 additions & 114 deletions src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,25 @@
// // Copyright (c) The LEGO Group. All rights reserved.
//
// namespace LEGO.AsyncAPI.Models
// {
// using System;
// using System.Collections.Generic;
// using LEGO.AsyncAPI.Models.Interfaces;
// using LEGO.AsyncAPI.Writers;
//
// /// <summary>
// /// Represents an Avro schema model (compatible with Avro 1.9.0).
// /// </summary>
// // #ToFix: Any type can be the main type so avroschema should be removed
// /*
// Record
//
// Fields:
// name (string)
// namespace (optional string)
// doc (optional string)
// aliases (optional array of strings)
// fields (array of field objects, each with name, type, default, doc, order, and aliases)
//
// Enum
// Fields:
// name (string)
// namespace (optional string)
// aliases (optional array of strings)
// symbols (array of strings)
// default (optional string)
// doc (optional string)
//
// Array
// Fields:
// items (type of the array elements)
//
// Map
// Fields:
// values (type of the map values)
//
// Union
// Fields:
// A list of potential types (each element is a valid Avro schema)
//
// Fixed
// Fields:
// name (string)
// namespace (optional string)
// aliases (optional array of strings)
// size (integer specifying the number of bytes per value)
// doc (optional string)
// */
//
// public class AvroSchema : IAsyncApiSerializable, IAsyncApiReferenceable
// {
// /// <summary>
// /// The type of the schema. See <a href="https://avro.apache.org/docs/1.9.0/spec.html#schema_primitive">Avro Schema Types</a>.
// /// </summary>
// public AvroSchemaType Type { get; set; }
//
// /// <summary>
// /// The name of the schema. Required for named types (e.g., record, enum, fixed). 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>
// /// The list of fields in the schema.
// /// </summary>
// public IList<AvroField> Fields { get; set; } = new List<AvroField>();
//
// public bool UnresolvedReference { get; set; }
//
// public AsyncApiReference Reference { get; set; }
//
// public void SerializeV2(IAsyncApiWriter writer)
// {
// if (writer is null)
// {
// throw new ArgumentNullException(nameof(writer));
// }
//
// if (this.Reference != null && !writer.GetSettings().ShouldInlineReference(this.Reference))
// {
// this.Reference.SerializeV2(writer);
// return;
// }
//
// this.SerializeV2WithoutReference(writer);
// }
//
// public void SerializeV2WithoutReference(IAsyncApiWriter writer)
// {
// writer.WriteStartObject();
//
// writer.WriteOptionalProperty(AsyncApiConstants.Type, this.Type.GetDisplayName());
// writer.WriteOptionalProperty("name", this.Name);
// writer.WriteOptionalProperty("namespace", this.Namespace);
// writer.WriteOptionalProperty("doc", this.Doc);
// writer.WriteOptionalCollection("fields", this.Fields, (w, f) => f.SerializeV2(w));
//
// writer.WriteEndObject();
// }
// }
// }
// Copyright (c) The LEGO Group. All rights reserved.

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

public abstract class AvroSchema : IAsyncApiSerializable
{
public abstract string Type { get; }

/// <summary>
/// A map of properties not in the schema, but added as additional metadata.
/// </summary>
public abstract IDictionary<string, AsyncApiAny> Metadata { get; set; }

public static implicit operator AvroSchema(AvroPrimitiveType type)
{
return new AvroPrimitive(type);
}

public abstract void SerializeV2(IAsyncApiWriter writer);
}
}
21 changes: 0 additions & 21 deletions src/LEGO.AsyncAPI/Models/Avro/AvroSchemaType.cs

This file was deleted.

4 changes: 4 additions & 0 deletions src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class AvroUnion : AvroSchema
{
public override string Type { get; } = "map";

/// <summary>
/// The types in this union.
/// </summary>
public IList<AvroSchema> Types { get; set; } = new List<AvroSchema>();

/// <summary>
Expand Down Expand Up @@ -40,6 +43,7 @@ public override void SerializeV2(IAsyncApiWriter writer)
}
}
}

writer.WriteEndArray();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/LEGO.AsyncAPI/Services/AsyncApiReferenceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public override void Visit(AsyncApiMessage message)
{
this.ResolveObject(message.Payload as AsyncApiJsonSchemaPayload, r => message.Payload = r);
}

this.ResolveList(message.Traits);
this.ResolveObject(message.CorrelationId, r => message.CorrelationId = r);
this.ResolveObject(message.Bindings, r => message.Bindings = r);
Expand Down

0 comments on commit 4f53f13

Please sign in to comment.