Skip to content

Commit 201a386

Browse files
committed
chore: empty channels allowed
1 parent 0b506e6 commit 201a386

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AsyncApiDocument : IAsyncApiExtensible, IAsyncApiSerializable
4444
/// <summary>
4545
/// REQUIRED. The available channels and messages for the API.
4646
/// </summary>
47-
public IDictionary<string, AsyncApiChannel> Channels { get; set; } = new Dictionary<string, AsyncApiChannel>();
47+
public IDictionary<string, AsyncApiChannel> Channels { get; set; }
4848

4949
/// <summary>
5050
/// an element to hold various schemas for the specification.

src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public static class AsyncApiDocumentRules
3737
context.Enter("channels");
3838
try
3939
{
40-
// MUST have at least 1 channel
41-
if (document.Channels == null || !document.Channels.Keys.Any())
40+
if (document.Channels == null)
4241
{
4342
context.CreateError(
4443
nameof(DocumentRequiredFields),

test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace LEGO.AsyncAPI.Tests
44
{
55
using System;
6+
using System.Collections.Generic;
67
using LEGO.AsyncAPI.Models;
78
using LEGO.AsyncAPI.Models.Interfaces;
89

@@ -42,6 +43,11 @@ public AsyncApiDocumentBuilder WithDefaultContentType(string contentType = "appl
4243

4344
public AsyncApiDocumentBuilder WithChannel(string key, AsyncApiChannel channel)
4445
{
46+
if (this.document.Channels == null)
47+
{
48+
this.document.Channels = new Dictionary<string, AsyncApiChannel>();
49+
}
50+
4551
this.document.Channels.Add(key, channel);
4652
return this;
4753
}

test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,10 @@ public void Serialize_WithBindingReferences_SerializesDeserializes()
11541154
},
11551155
},
11561156
};
1157+
if (doc.Channels == null)
1158+
{
1159+
doc.Channels = new Dictionary<string, AsyncApiChannel>();
1160+
}
11571161
doc.Channels.Add(
11581162
"testChannel",
11591163
new AsyncApiChannelReference("#/components/channels/otherchannel"));
@@ -1212,6 +1216,10 @@ public void Serializev2_WithBindings_Serializes()
12121216
Protocol = "pulsar+ssl",
12131217
Url = "example.com",
12141218
});
1219+
if (doc.Channels == null)
1220+
{
1221+
doc.Channels = new Dictionary<string, AsyncApiChannel>();
1222+
}
12151223
doc.Channels.Add(
12161224
"testChannel",
12171225
new AsyncApiChannel

0 commit comments

Comments
 (0)