From 4f53f13750ea06fd9c2b6a74cee785a92ce24dd7 Mon Sep 17 00:00:00 2001 From: VisualBean Date: Fri, 31 May 2024 12:55:31 +0200 Subject: [PATCH] minor fixes and docs --- src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs | 4 + src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs | 19 +++ src/LEGO.AsyncAPI/Models/Avro/AvroField.cs | 7 +- .../Models/Avro/AvroFieldType.cs | 25 ---- src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs | 16 +- src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs | 1 + src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs | 3 +- src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs | 139 ++++-------------- .../Models/Avro/AvroSchemaType.cs | 21 --- src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs | 4 + .../Services/AsyncApiReferenceResolver.cs | 1 + 11 files changed, 75 insertions(+), 165 deletions(-) delete mode 100644 src/LEGO.AsyncAPI/Models/Avro/AvroFieldType.cs delete mode 100644 src/LEGO.AsyncAPI/Models/Avro/AvroSchemaType.cs diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs index ca99b6f9..95a94e91 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroArray.cs @@ -10,6 +10,9 @@ public class AvroArray : AvroSchema { public override string Type { get; } = "array"; + /// + /// The schema of the array's items. + /// public AvroSchema Items { get; set; } /// @@ -37,6 +40,7 @@ public override void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndObject(); } } diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs index 7a019d51..7a694f41 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroEnum.cs @@ -10,16 +10,34 @@ public class AvroEnum : AvroSchema { public override string Type { get; } = "enum"; + /// + /// The name of the schema. Required for named types. See Avro Names. + /// public string Name { get; set; } + /// + /// The namespace of the schema. Useful for named types to avoid name conflicts. + /// public string Namespace { get; set; } + /// + /// Documentation for the schema. + /// public string Doc { get; set; } + /// + /// Alternate names for this enum. + /// public IList Aliases { get; set; } = new List(); + /// + /// Listing symbols. All symbols in an enum must be unique. + /// public IList Symbols { get; set; } = new List(); + /// + /// A default value for this enumeration. + /// public string Default { get; set; } /// @@ -52,6 +70,7 @@ public override void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndObject(); } } diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroField.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroField.cs index 17eb414a..69f596a6 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroField.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroField.cs @@ -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; /// /// Represents a field within an Avro record schema. @@ -38,7 +38,7 @@ public class AvroField : IAsyncApiSerializable public string Order { get; set; } /// - /// An array of strings, providing alternate names for this record (optional). + /// Alternate names for this record (optional). /// public IList Aliases { get; set; } = new List(); @@ -71,6 +71,7 @@ public void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndObject(); } } diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroFieldType.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroFieldType.cs deleted file mode 100644 index 4366c5e8..00000000 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroFieldType.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) The LEGO Group. All rights reserved. - -namespace LEGO.AsyncAPI.Models -{ - using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; - using System.Collections.Generic; - - public abstract class AvroSchema : IAsyncApiSerializable - { - public abstract string Type { get; } - - /// - /// A map of properties not in the schema, but added as additional metadata. - /// - public abstract IDictionary Metadata { get; set; } - - public static implicit operator AvroSchema(AvroPrimitiveType type) - { - return new AvroPrimitive(type); - } - - public abstract void SerializeV2(IAsyncApiWriter writer); - } -} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs index c1d1e637..bced9fa7 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroFixed.cs @@ -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"; + /// + /// The name of the schema. Required for named types. See Avro Names. + /// public string Name { get; set; } + /// + /// The namespace of the schema. Useful for named types to avoid name conflicts. + /// public string Namespace { get; set; } + + /// + /// Alternate names for this record. + /// public IList Aliases { get; set; } = new List(); + /// + /// Number of bytes per value. + /// public int Size { get; set; } /// @@ -46,6 +59,7 @@ public override void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndObject(); } } diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs index dcda89f4..879959f6 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroMap.cs @@ -38,6 +38,7 @@ public override void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndObject(); } } diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs index 1d3b63c6..60c4d73f 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroRecord.cs @@ -26,7 +26,7 @@ public class AvroRecord : AvroSchema public string Doc { get; set; } /// - /// + /// Alternate names for this record. /// public IList Aliases { get; set; } = new List(); @@ -64,6 +64,7 @@ public override void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndObject(); } } diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs index 3b29ad2a..1d1f0a8f 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs @@ -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; -// -// /// -// /// Represents an Avro schema model (compatible with Avro 1.9.0). -// /// -// // #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 -// { -// /// -// /// The type of the schema. See Avro Schema Types. -// /// -// public AvroSchemaType Type { get; set; } -// -// /// -// /// The name of the schema. Required for named types (e.g., record, enum, fixed). See Avro Names. -// /// -// public string Name { get; set; } -// -// /// -// /// The namespace of the schema. Useful for named types to avoid name conflicts. -// /// -// public string? Namespace { get; set; } -// -// /// -// /// Documentation for the schema. -// /// -// public string? Doc { get; set; } -// -// /// -// /// The list of fields in the schema. -// /// -// public IList Fields { get; set; } = new List(); -// -// 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(); -// } -// } -// } \ No newline at end of file +// 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; } + + /// + /// A map of properties not in the schema, but added as additional metadata. + /// + public abstract IDictionary Metadata { get; set; } + + public static implicit operator AvroSchema(AvroPrimitiveType type) + { + return new AvroPrimitive(type); + } + + public abstract void SerializeV2(IAsyncApiWriter writer); + } +} \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroSchemaType.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroSchemaType.cs deleted file mode 100644 index df9b61d7..00000000 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroSchemaType.cs +++ /dev/null @@ -1,21 +0,0 @@ -// // Copyright (c) The LEGO Group. All rights reserved. -// -// namespace LEGO.AsyncAPI.Models -// { -// using LEGO.AsyncAPI.Attributes; -// -// /// -// /// Enumeration of Avro schema types. See Avro Schemas. -// /// -// public enum AvroSchemaType -// { -// [Display("record")] -// Record, -// -// [Display("enum")] -// Enum, -// -// [Display("fixed")] -// Fixed -// } -// } \ No newline at end of file diff --git a/src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs b/src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs index 41712d3a..2cb72fd1 100644 --- a/src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs +++ b/src/LEGO.AsyncAPI/Models/Avro/AvroUnion.cs @@ -10,6 +10,9 @@ public class AvroUnion : AvroSchema { public override string Type { get; } = "map"; + /// + /// The types in this union. + /// public IList Types { get; set; } = new List(); /// @@ -40,6 +43,7 @@ public override void SerializeV2(IAsyncApiWriter writer) } } } + writer.WriteEndArray(); } } diff --git a/src/LEGO.AsyncAPI/Services/AsyncApiReferenceResolver.cs b/src/LEGO.AsyncAPI/Services/AsyncApiReferenceResolver.cs index 32cd435d..c37c2804 100644 --- a/src/LEGO.AsyncAPI/Services/AsyncApiReferenceResolver.cs +++ b/src/LEGO.AsyncAPI/Services/AsyncApiReferenceResolver.cs @@ -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);