Skip to content

Commit f590563

Browse files
committed
fix: channels empty object allowed
1 parent 3c4861d commit f590563

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs

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

5151
/// <summary>
5252
/// an element to hold various schemas for the specification.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class AsyncApiDocumentRules
3030
context.Exit();
3131

3232
context.Enter("channels");
33-
if (document.Channels == null || !document.Channels.Keys.Any())
33+
if (document.Channels == null)
3434
{
3535
context.CreateError(
3636
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
@@ -1303,6 +1303,10 @@ public void Serialize_WithBindingReferences_SerializesDeserializes()
13031303
},
13041304
},
13051305
};
1306+
if (doc.Channels == null)
1307+
{
1308+
doc.Channels = new Dictionary<string, AsyncApiChannel>();
1309+
}
13061310
doc.Channels.Add(
13071311
"testChannel",
13081312
new AsyncApiChannel
@@ -1361,6 +1365,10 @@ public void Serializev2_WithBindings_Serializes()
13611365
Protocol = "pulsar+ssl",
13621366
Url = "example.com",
13631367
});
1368+
if (doc.Channels == null)
1369+
{
1370+
doc.Channels = new Dictionary<string, AsyncApiChannel>();
1371+
}
13641372
doc.Channels.Add(
13651373
"testChannel",
13661374
new AsyncApiChannel

0 commit comments

Comments
 (0)