From f9019b144c9d49b547c9e3ae21243886bc3bb736 Mon Sep 17 00:00:00 2001 From: DominikKaloc Date: Thu, 4 Sep 2025 08:45:39 +0200 Subject: [PATCH 1/4] chore: empty channels should be allowed --- src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs b/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs index 27076369..264c1611 100644 --- a/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs +++ b/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs @@ -30,7 +30,7 @@ public static class AsyncApiDocumentRules context.Exit(); context.Enter("channels"); - if (document.Channels == null || !document.Channels.Keys.Any()) + if (document.Channels == null) { context.CreateError( nameof(DocumentRequiredFields), From 9b3c6693afaaeb5acf8ad5b3e7c58ed6dffd4f7f Mon Sep 17 00:00:00 2001 From: DominikKaloc Date: Thu, 4 Sep 2025 09:05:02 +0200 Subject: [PATCH 2/4] chore: do not create an empty one. Should fail if not in spec --- src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs b/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs index 5be55202..7b725a6c 100644 --- a/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs +++ b/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs @@ -46,7 +46,7 @@ public class AsyncApiDocument : IAsyncApiExtensible, IAsyncApiSerializable /// /// REQUIRED. The available channels and messages for the API. /// - public IDictionary Channels { get; set; } = new Dictionary(); + public IDictionary Channels { get; set; } /// /// an element to hold various schemas for the specification. From ac4c73c4ae40eb703323106066b9c56b1eea7ec5 Mon Sep 17 00:00:00 2001 From: DominikKaloc Date: Thu, 4 Sep 2025 11:17:45 +0200 Subject: [PATCH 3/4] chore: initialize channels in tests first when needed, as it was removed from asyncApiDocument --- test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs | 7 ++++++- test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs index 3f2ee429..886fb7bf 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs @@ -2,9 +2,10 @@ namespace LEGO.AsyncAPI.Tests { + using System; + using System.Collections.Generic; using LEGO.AsyncAPI.Models; using LEGO.AsyncAPI.Models.Interfaces; - using System; internal class AsyncApiDocumentBuilder { @@ -42,6 +43,10 @@ public AsyncApiDocumentBuilder WithDefaultContentType(string contentType = "appl public AsyncApiDocumentBuilder WithChannel(string key, AsyncApiChannel channel) { + if (this.document.Channels == null) + { + this.document.Channels = new Dictionary(); + } this.document.Channels.Add(key, channel); return this; } diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs index 6e1a9c70..13ae85e5 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs @@ -1202,6 +1202,10 @@ public void Serialize_WithBindingReferences_SerializesDeserializes() }, }, }; + if (doc.Channels == null) + { + doc.Channels = new Dictionary(); + } doc.Channels.Add( "testChannel", new AsyncApiChannel @@ -1260,6 +1264,10 @@ public void Serializev2_WithBindings_Serializes() Protocol = "pulsar+ssl", Url = "example.com", }); + if (doc.Channels == null) + { + doc.Channels = new Dictionary(); + } doc.Channels.Add( "testChannel", new AsyncApiChannel From 314d43b7e28d65c00550d18253178deefdab0964 Mon Sep 17 00:00:00 2001 From: DominikKaloc Date: Thu, 4 Sep 2025 11:27:10 +0200 Subject: [PATCH 4/4] chore: reordering usings --- src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs b/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs index 7b725a6c..b6488883 100644 --- a/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs +++ b/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs @@ -6,8 +6,8 @@ namespace LEGO.AsyncAPI.Models using System.Collections.Generic; using LEGO.AsyncAPI.Exceptions; using LEGO.AsyncAPI.Models.Interfaces; - using LEGO.AsyncAPI.Writers; using LEGO.AsyncAPI.Services; + using LEGO.AsyncAPI.Writers; /// /// This is the root document object for the API specification. It combines resource listing and API declaration together into one document.