Skip to content

Commit

Permalink
fix: dont return early for required map (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
UlrikSandberg authored Feb 20, 2025
1 parent 57c4095 commit e6b9bf4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ public static void WriteRequiredMap<T>(
Action<IAsyncApiWriter, string, T> action)
where T : IAsyncApiElement
{
if (elements != null && elements.Any())
{
writer.WriteMapInternal(name, elements, action);
}
writer.WriteMapInternal(name, elements, action);
}

/// <summary>
Expand Down
31 changes: 31 additions & 0 deletions test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,5 +1325,36 @@ public void Serializev2_WithBindings_Serializes()

Assert.AreEqual("this mah binding", httpBinding.Headers.Description);
}



[Test]
public void SerializeV2_EmptyChannelObject_DeserializeAndSerializePreserveChannelObject()
{
// Arrange
var spec = """
asyncapi: 2.6.0
info:
title: Spec with missing channel info
description: test description
servers:
production:
url: example.com
protocol: pulsar+ssl
description: test description
channels: { }
""";

var settings = new AsyncApiReaderSettings();
var reader = new AsyncApiStringReader(settings);

// Act
var deserialized = reader.Read(spec, out var diagnostic);
var actual = deserialized.Serialize(AsyncApiVersion.AsyncApi2_0, AsyncApiFormat.Yaml);

// Assert
actual.Should()
.BePlatformAgnosticEquivalentTo(spec);
}
}
}

0 comments on commit e6b9bf4

Please sign in to comment.