From 26bf9ddc2a48a4230c3406781b6465dd88261efe Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Tue, 28 Jan 2025 15:01:44 +0100 Subject: [PATCH 1/3] Don't return early for required map --- src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs b/src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs index 67c4737a..25777d51 100644 --- a/src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs +++ b/src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs @@ -285,10 +285,7 @@ public static void WriteRequiredMap( Action action) where T : IAsyncApiElement { - if (elements != null && elements.Any()) - { - writer.WriteMapInternal(name, elements, action); - } + writer.WriteMapInternal(name, elements, action); } /// From f11240a1b770f9c618f88f604e290adc819be276 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Wed, 19 Feb 2025 18:08:55 +0100 Subject: [PATCH 2/3] Added long awaited test --- .../AsyncApiDocumentV2Tests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs index 63e818b4..28bb3ff6 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs @@ -1325,5 +1325,37 @@ 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(); + settings.Bindings = BindingsCollection.All; + 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); + } } } \ No newline at end of file From eae12c312613ebcad5e66698db4f24c7d09030b2 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Wed, 19 Feb 2025 18:09:52 +0100 Subject: [PATCH 3/3] Indentation error --- .../AsyncApiDocumentV2Tests.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs index 28bb3ff6..6e1a9c70 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs @@ -1333,20 +1333,19 @@ public void SerializeV2_EmptyChannelObject_DeserializeAndSerializePreserveChanne { // 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: { } + 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(); - settings.Bindings = BindingsCollection.All; var reader = new AsyncApiStringReader(settings); // Act