diff --git a/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs b/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs
index 5d90e7a8..0359d083 100644
--- a/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs
+++ b/src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs
@@ -44,7 +44,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.
diff --git a/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs b/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs
index e82f3c7c..2f759905 100644
--- a/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs
+++ b/src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs
@@ -37,8 +37,7 @@ public static class AsyncApiDocumentRules
context.Enter("channels");
try
{
- // MUST have at least 1 channel
- if (document.Channels == null || !document.Channels.Keys.Any())
+ if (document.Channels == null)
{
context.CreateError(
nameof(DocumentRequiredFields),
diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs
index 2967fd8c..3a5ad497 100644
--- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs
+++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs
@@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Tests
{
using System;
+ using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
@@ -42,6 +43,11 @@ 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 9b863969..94c09dbe 100644
--- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs
+++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs
@@ -1154,6 +1154,10 @@ public void Serialize_WithBindingReferences_SerializesDeserializes()
},
},
};
+ if (doc.Channels == null)
+ {
+ doc.Channels = new Dictionary();
+ }
doc.Channels.Add(
"testChannel",
new AsyncApiChannelReference("#/components/channels/otherchannel"));
@@ -1212,6 +1216,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