From 45b8d6a066a25da2e46e6373a4ad74dc7f09db6c Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 26 Feb 2024 11:10:37 +0100 Subject: [PATCH 1/5] fix --- src/LEGO.AsyncAPI/Models/Any/AsyncAPIArray.cs | 2 + .../Models/Any/AsyncAPIObject.cs | 2 + src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs | 85 ++++++++++++++++++- test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs | 53 ++++++++++++ .../AsyncApiDocumentV2Tests.cs | 27 +++--- .../LEGO.AsyncAPI.Tests.csproj | 1 - 6 files changed, 157 insertions(+), 13 deletions(-) create mode 100644 test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncAPIArray.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncAPIArray.cs index 042b1f68..01970b19 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncAPIArray.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncAPIArray.cs @@ -2,11 +2,13 @@ namespace LEGO.AsyncAPI.Models { + using System; using System.Collections.ObjectModel; using System.Text.Json.Nodes; using LEGO.AsyncAPI.Models.Interfaces; using LEGO.AsyncAPI.Writers; + [Obsolete("Please use AsyncApiAny instead")] public class AsyncApiArray : Collection, IAsyncApiExtension, IAsyncApiElement { diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncAPIObject.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncAPIObject.cs index 90e8e124..e93f595e 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncAPIObject.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncAPIObject.cs @@ -2,6 +2,7 @@ namespace LEGO.AsyncAPI.Models { + using System; using System.Collections.Generic; using System.Text.Json.Nodes; using LEGO.AsyncAPI.Models.Interfaces; @@ -10,6 +11,7 @@ namespace LEGO.AsyncAPI.Models /// /// AsyncApi object. /// + [Obsolete("Please use AsyncApiAny instead")] public class AsyncApiObject : Dictionary, IAsyncApiExtension, IAsyncApiElement { diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs index 098c88d4..691886b6 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs @@ -2,6 +2,11 @@ namespace LEGO.AsyncAPI.Models { + using System.Collections; + using System.Collections.Generic; + using System.ComponentModel; + using System.Linq; + using System.Text.Json; using System.Text.Json.Nodes; using LEGO.AsyncAPI.Models.Interfaces; using LEGO.AsyncAPI.Writers; @@ -13,6 +18,11 @@ namespace LEGO.AsyncAPI.Models /// public class AsyncApiAny : IAsyncApiElement, IAsyncApiExtension { + private JsonSerializerOptions options = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + }; + private JsonNode node; /// @@ -24,6 +34,64 @@ public AsyncApiAny(JsonNode node) this.node = node; } + public AsyncApiAny(object obj) + { + this.node = JsonNode.Parse(JsonSerializer.Serialize(obj, this.options)); + } + + public AsyncApiAny(Dictionary dictionary) + { + var jsonObject = new JsonObject(); + foreach (var kvp in dictionary) + { + jsonObject.Add(kvp.Key, kvp.Value.node); + } + + this.node = jsonObject; + } + + public AsyncApiAny(List list) + { + var jsonArray = new JsonArray(); + foreach (var item in list) + { + string jsonString = JsonSerializer.Serialize(item, this.options); + jsonArray.Add(JsonNode.Parse(jsonString)); + } + + this.node = jsonArray; + } + + public AsyncApiAny(Dictionary dictionary) + { + var jsonObject = new JsonObject(); + foreach (var kvp in dictionary) + { + string jsonString = JsonSerializer.Serialize(kvp.Value, this.options); + jsonObject.Add(kvp.Key, JsonNode.Parse(jsonString)); + } + + this.node = jsonObject; + } + + /// + /// Initializes a new instance of the class. + /// + /// The node. + public AsyncApiAny(JsonArray node) + { + this.node = node; + } + + /// + /// Initializes a new instance of the class. + /// + /// The node. + public AsyncApiAny(JsonObject node) + { + this.node = node; + } + /// /// Gets the node. /// @@ -34,7 +102,22 @@ public AsyncApiAny(JsonNode node) public T GetValue() { - return this.node.GetValue(); + return JsonSerializer.Deserialize(this.node.ToJsonString()); + } + + public bool TryGetValue(out T value) + { + try + { + + value = this.GetValue(); + return true; + } + catch (System.Exception) + { + value = default(T); + return false; + } } /// diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs new file mode 100644 index 00000000..a743499f --- /dev/null +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs @@ -0,0 +1,53 @@ +using LEGO.AsyncAPI.Models; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LEGO.AsyncAPI.Tests +{ + + public class AsyncApiAnyTests + { + [Test] + public void Test() + { + // Arrange + // Act + // Assert + } + + + [Test] + public void ctor_Primitives() + { + // Arrange + // Act + var a = new AsyncApiAny("string"); + var b = new AsyncApiAny(1); + var c = new AsyncApiAny(1.1); + var d = new AsyncApiAny(true); + var e = new AsyncApiAny(new MyType("test")); + var f = new AsyncApiAny(new List() { "test", "test2"}); + var g = new AsyncApiAny(new List() { new MyType("test") }); + var h = new AsyncApiAny(new Dictionary() { { "t", 2 } }); + var i = new AsyncApiAny(new Dictionary() { { "t", new MyType("test") } }); + + var v = e.GetValue(); + var k = i.GetValue>(); + // Assert + } + + + class MyType + { + public MyType(string value) + { + this.Value = value; + } + public string Value { get; set; } + } + } +} diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs index b48b1b48..a598ac18 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs +++ b/test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs @@ -7,16 +7,21 @@ namespace LEGO.AsyncAPI.Tests using System.Globalization; using System.IO; using System.Linq; - using LEGO.AsyncAPI.Bindings.Pulsar; using LEGO.AsyncAPI.Bindings; using LEGO.AsyncAPI.Bindings.Http; using LEGO.AsyncAPI.Bindings.Kafka; + using LEGO.AsyncAPI.Bindings.Pulsar; using LEGO.AsyncAPI.Models; using LEGO.AsyncAPI.Models.Interfaces; using LEGO.AsyncAPI.Readers; using LEGO.AsyncAPI.Writers; using NUnit.Framework; + public class ExtensionClass + { + public string Key { get; set; } + public long OtherKey { get; set; } + } public class AsyncApiDocumentV2Tests { [Test] @@ -838,8 +843,6 @@ public void SerializeV2_WithFullSpec_Serializes() string traitTitle = "traitTitle"; string schemaTitle = "schemaTitle"; string schemaDescription = "schemaDescription"; - string anyKey = "key"; - string anyOtherKey = "otherKey"; string anyStringValue = "value"; long anyLongValue = long.MaxValue; string exampleSummary = "exampleSummary"; @@ -864,6 +867,8 @@ public void SerializeV2_WithFullSpec_Serializes() string refreshUrl = "https://example.com/refresh"; string authorizationUrl = "https://example.com/authorization"; string requirementString = "requirementItem"; + + var document = new AsyncApiDocument() { Id = documentId, @@ -1016,11 +1021,11 @@ public void SerializeV2_WithFullSpec_Serializes() Description = schemaDescription, Examples = new List { - new AsyncApiObject + new AsyncApiAny(new ExtensionClass { - { anyKey, new AsyncApiAny(anyStringValue) }, - { anyOtherKey, new AsyncApiAny(anyLongValue) }, - }, + Key = anyStringValue, + OtherKey = anyLongValue, + }), }, }, Examples = new List @@ -1029,11 +1034,11 @@ public void SerializeV2_WithFullSpec_Serializes() { Summary = exampleSummary, Name = exampleName, - Payload = new AsyncApiObject + Payload =new AsyncApiAny(new ExtensionClass { - { anyKey, new AsyncApiAny(anyStringValue) }, - { anyOtherKey, new AsyncApiAny(anyLongValue) }, - }, + Key = anyStringValue, + OtherKey = anyLongValue, + }), Extensions = new Dictionary { { extensionKey, new AsyncApiAny(extensionString) }, diff --git a/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj b/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj index 692c8e06..1be4a264 100644 --- a/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj +++ b/test/LEGO.AsyncAPI.Tests/LEGO.AsyncAPI.Tests.csproj @@ -24,7 +24,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - From 5c18d932ec32f67363e27a2ec15683603110c2c9 Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 26 Feb 2024 11:40:41 +0100 Subject: [PATCH 2/5] add initial tests --- src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs | 69 +++++++++++++++++-- .../Bindings/Sns/SnsBindings_Should.cs | 7 ++ .../{ => Models}/AsyncApiAnyTests.cs | 26 +++---- 3 files changed, 85 insertions(+), 17 deletions(-) rename test/LEGO.AsyncAPI.Tests/{ => Models}/AsyncApiAnyTests.cs (60%) diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs index 691886b6..ea926853 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs @@ -2,10 +2,7 @@ namespace LEGO.AsyncAPI.Models { - using System.Collections; using System.Collections.Generic; - using System.ComponentModel; - using System.Linq; using System.Text.Json; using System.Text.Json.Nodes; using LEGO.AsyncAPI.Models.Interfaces; @@ -26,7 +23,7 @@ public class AsyncApiAny : IAsyncApiElement, IAsyncApiExtension private JsonNode node; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The node. public AsyncApiAny(JsonNode node) @@ -34,11 +31,19 @@ public AsyncApiAny(JsonNode node) this.node = node; } + /// + /// Initializes a new instance of the class. + /// + /// The object. public AsyncApiAny(object obj) { this.node = JsonNode.Parse(JsonSerializer.Serialize(obj, this.options)); } + /// + /// Initializes a new instance of the class. + /// + /// The dictionary. public AsyncApiAny(Dictionary dictionary) { var jsonObject = new JsonObject(); @@ -50,6 +55,10 @@ public AsyncApiAny(Dictionary dictionary) this.node = jsonObject; } + /// + /// Initializes a new instance of the class. + /// + /// The list. public AsyncApiAny(List list) { var jsonArray = new JsonArray(); @@ -62,6 +71,10 @@ public AsyncApiAny(List list) this.node = jsonArray; } + /// + /// Initializes a new instance of the class. + /// + /// The dictionary. public AsyncApiAny(Dictionary dictionary) { var jsonObject = new JsonObject(); @@ -74,6 +87,7 @@ public AsyncApiAny(Dictionary dictionary) this.node = jsonObject; } + /// /// Initializes a new instance of the class. /// @@ -92,19 +106,66 @@ public AsyncApiAny(JsonObject node) this.node = node; } + /// + /// Converts to from an Extension. + /// + /// T. + /// The extension. + /// . + public static T FromExtension(IAsyncApiExtension extension) + { + if (extension is AsyncApiAny any) + { + return any.GetValueOrDefault(); + } + else + { + return default(T); + } + } + /// /// Gets the node. /// + /// . /// /// The node. /// public JsonNode GetNode() => this.node; + /// + /// Gets the value. + /// + /// . + /// . public T GetValue() { return JsonSerializer.Deserialize(this.node.ToJsonString()); } + /// + /// Gets the value or default. + /// + /// . + /// or default. + public T GetValueOrDefault() + { + try + { + return this.GetValue(); + } + catch (System.Exception) + { + return default(T); + } + } + + /// + /// Tries the get value. + /// + /// . + /// The value. + /// true if the value could be converted, otherwise false. public bool TryGetValue(out T value) { try diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs index d4d5cf05..290ee107 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs @@ -381,6 +381,9 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() var settings = new AsyncApiReaderSettings(); settings.Bindings = BindingsCollection.Sns; var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); + var binding2 = new AsyncApiStringReader(settings).ReadFragment(expected, AsyncApiVersion.AsyncApi2_0, out _); + binding2.Bindings.First().Value.Extensions.TryGetValue("x-bindingExtension", out IAsyncApiExtension any); + var val = AsyncApiAny.FromExtension(any); // Assert Assert.AreEqual(actual, expected); @@ -388,5 +391,9 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() var expectedSnsBinding = (SnsOperationBinding)operation.Bindings.Values.First(); expectedSnsBinding.Should().BeEquivalentTo((SnsOperationBinding)binding.Bindings.Values.First(), options => options.IgnoringCyclicReferences()); } + class ExtensionClass + { + public string bindingXPropertyName { get; set; } + } } } \ No newline at end of file diff --git a/test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs similarity index 60% rename from test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs rename to test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs index a743499f..e335b6b1 100644 --- a/test/LEGO.AsyncAPI.Tests/AsyncApiAnyTests.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs @@ -12,16 +12,7 @@ namespace LEGO.AsyncAPI.Tests public class AsyncApiAnyTests { [Test] - public void Test() - { - // Arrange - // Act - // Assert - } - - - [Test] - public void ctor_Primitives() + public void GetValue_ReturnsCorrectConversions() { // Arrange // Act @@ -35,18 +26,27 @@ public void ctor_Primitives() var h = new AsyncApiAny(new Dictionary() { { "t", 2 } }); var i = new AsyncApiAny(new Dictionary() { { "t", new MyType("test") } }); - var v = e.GetValue(); - var k = i.GetValue>(); // Assert + Assert.AreEqual("string", a.GetValue()); + Assert.AreEqual(1, b.GetValue()); + Assert.AreEqual(1.1, c.GetValue()); + Assert.AreEqual(true, d.GetValue()); + Assert.NotNull(e.GetValue()); + Assert.IsNotEmpty(f.GetValue>()); + Assert.IsNotEmpty(f.GetValue>()); + Assert.IsNotEmpty(g.GetValue>()); + Assert.IsNotEmpty(g.GetValue>()); + Assert.IsNotEmpty(h.GetValue>()); + Assert.IsNotEmpty(i.GetValue>()); } - class MyType { public MyType(string value) { this.Value = value; } + public string Value { get; set; } } } From 963a9315908e264d6a2f382fb3672b5821b95223 Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 26 Feb 2024 11:58:54 +0100 Subject: [PATCH 3/5] remove redundant ctors --- src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs | 48 ------------------- .../Models/AsyncApiAnyTests.cs | 19 ++++---- 2 files changed, 10 insertions(+), 57 deletions(-) diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs index ea926853..c9c0c926 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs @@ -40,54 +40,6 @@ public AsyncApiAny(object obj) this.node = JsonNode.Parse(JsonSerializer.Serialize(obj, this.options)); } - /// - /// Initializes a new instance of the class. - /// - /// The dictionary. - public AsyncApiAny(Dictionary dictionary) - { - var jsonObject = new JsonObject(); - foreach (var kvp in dictionary) - { - jsonObject.Add(kvp.Key, kvp.Value.node); - } - - this.node = jsonObject; - } - - /// - /// Initializes a new instance of the class. - /// - /// The list. - public AsyncApiAny(List list) - { - var jsonArray = new JsonArray(); - foreach (var item in list) - { - string jsonString = JsonSerializer.Serialize(item, this.options); - jsonArray.Add(JsonNode.Parse(jsonString)); - } - - this.node = jsonArray; - } - - /// - /// Initializes a new instance of the class. - /// - /// The dictionary. - public AsyncApiAny(Dictionary dictionary) - { - var jsonObject = new JsonObject(); - foreach (var kvp in dictionary) - { - string jsonString = JsonSerializer.Serialize(kvp.Value, this.options); - jsonObject.Add(kvp.Key, JsonNode.Parse(jsonString)); - } - - this.node = jsonObject; - } - - /// /// Initializes a new instance of the class. /// diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs index e335b6b1..08f1682c 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LEGO.AsyncAPI.Tests { @@ -22,9 +20,10 @@ public void GetValue_ReturnsCorrectConversions() var d = new AsyncApiAny(true); var e = new AsyncApiAny(new MyType("test")); var f = new AsyncApiAny(new List() { "test", "test2"}); - var g = new AsyncApiAny(new List() { new MyType("test") }); - var h = new AsyncApiAny(new Dictionary() { { "t", 2 } }); - var i = new AsyncApiAny(new Dictionary() { { "t", new MyType("test") } }); + var g = new AsyncApiAny(new List() { "test", "test2"}.AsEnumerable()); + var h = new AsyncApiAny(new List() { new MyType("test") }); + var i = new AsyncApiAny(new Dictionary() { { "t", 2 } }); + var j = new AsyncApiAny(new Dictionary() { { "t", new MyType("test") } }); // Assert Assert.AreEqual("string", a.GetValue()); @@ -34,10 +33,12 @@ public void GetValue_ReturnsCorrectConversions() Assert.NotNull(e.GetValue()); Assert.IsNotEmpty(f.GetValue>()); Assert.IsNotEmpty(f.GetValue>()); - Assert.IsNotEmpty(g.GetValue>()); - Assert.IsNotEmpty(g.GetValue>()); - Assert.IsNotEmpty(h.GetValue>()); - Assert.IsNotEmpty(i.GetValue>()); + Assert.IsNotEmpty(g.GetValue>()); + Assert.IsNotEmpty(g.GetValue>()); + Assert.IsNotEmpty(h.GetValue>()); + Assert.IsNotEmpty(h.GetValue>()); + Assert.IsNotEmpty(i.GetValue>()); + Assert.IsNotEmpty(j.GetValue>()); } class MyType From b26964f3c368e7d83fdcb9a1b056c90003e05b1d Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 26 Feb 2024 12:16:19 +0100 Subject: [PATCH 4/5] fromextensionordefault --- src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs | 3 +-- test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs index c9c0c926..b83d5ba9 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs @@ -64,7 +64,7 @@ public AsyncApiAny(JsonObject node) /// T. /// The extension. /// . - public static T FromExtension(IAsyncApiExtension extension) + public static T FromExtensionOrDefault(IAsyncApiExtension extension) { if (extension is AsyncApiAny any) { @@ -122,7 +122,6 @@ public bool TryGetValue(out T value) { try { - value = this.GetValue(); return true; } diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs index 290ee107..dbca5966 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs @@ -383,7 +383,7 @@ public void SnsOperationBinding_WithFilledObject_SerializesAndDeserializes() var binding = new AsyncApiStringReader(settings).ReadFragment(actual, AsyncApiVersion.AsyncApi2_0, out _); var binding2 = new AsyncApiStringReader(settings).ReadFragment(expected, AsyncApiVersion.AsyncApi2_0, out _); binding2.Bindings.First().Value.Extensions.TryGetValue("x-bindingExtension", out IAsyncApiExtension any); - var val = AsyncApiAny.FromExtension(any); + var val = AsyncApiAny.FromExtensionOrDefault(any); // Assert Assert.AreEqual(actual, expected); From 99af9e4a2c642b55ff84fceadf7080556c9e4df0 Mon Sep 17 00:00:00 2001 From: VisualBean Date: Mon, 26 Feb 2024 12:28:03 +0100 Subject: [PATCH 5/5] add fallback for primitives --- src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs | 5 +++++ test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs index b83d5ba9..8985fed3 100644 --- a/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs +++ b/src/LEGO.AsyncAPI/Models/Any/AsyncApiAny.cs @@ -92,6 +92,11 @@ public static T FromExtensionOrDefault(IAsyncApiExtension extension) /// . public T GetValue() { + if (this.node is JsonValue) + { + return this.node.GetValue(); + } + return JsonSerializer.Deserialize(this.node.ToJsonString()); } diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs index 08f1682c..598ef31f 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs @@ -28,7 +28,7 @@ public void GetValue_ReturnsCorrectConversions() // Assert Assert.AreEqual("string", a.GetValue()); Assert.AreEqual(1, b.GetValue()); - Assert.AreEqual(1.1, c.GetValue()); + Assert.AreEqual(1.1, c.GetValue()); Assert.AreEqual(true, d.GetValue()); Assert.NotNull(e.GetValue()); Assert.IsNotEmpty(f.GetValue>());