Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AsyncApiDocument : IAsyncApiExtensible, IAsyncApiSerializable
/// <summary>
/// REQUIRED. The available channels and messages for the API.
/// </summary>
public IDictionary<string, AsyncApiChannel> Channels { get; set; } = new Dictionary<string, AsyncApiChannel>();
public IDictionary<string, AsyncApiChannel> Channels { get; set; }

/// <summary>
/// an element to hold various schemas for the specification.
Expand Down
3 changes: 1 addition & 2 deletions src/LEGO.AsyncAPI/Validation/Rules/AsyncApiDocumentRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LEGO.AsyncAPI.Tests
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;

Expand Down Expand Up @@ -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<string, AsyncApiChannel>();
}

this.document.Channels.Add(key, channel);
return this;
}
Expand Down
8 changes: 8 additions & 0 deletions test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,10 @@ public void Serialize_WithBindingReferences_SerializesDeserializes()
},
},
};
if (doc.Channels == null)
{
doc.Channels = new Dictionary<string, AsyncApiChannel>();
}
doc.Channels.Add(
"testChannel",
new AsyncApiChannelReference("#/components/channels/otherchannel"));
Expand Down Expand Up @@ -1212,6 +1216,10 @@ public void Serializev2_WithBindings_Serializes()
Protocol = "pulsar+ssl",
Url = "example.com",
});
if (doc.Channels == null)
{
doc.Channels = new Dictionary<string, AsyncApiChannel>();
}
doc.Channels.Add(
"testChannel",
new AsyncApiChannel
Expand Down
Loading