Skip to content

fix: dont return early for required map #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2025
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
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);
}
}
}
Loading