From b7ad55ca0867ac3e66998bc40516b1978ba7c710 Mon Sep 17 00:00:00 2001 From: Alex Wichmann Date: Tue, 1 Aug 2023 23:18:11 +0200 Subject: [PATCH 1/2] fix nullref --- src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs b/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs index 4bd72a19..1ed73752 100644 --- a/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs +++ b/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs @@ -62,7 +62,7 @@ public static IAsyncApiAny GetSpecificAsyncApiAny(IAsyncApiAny asyncApiAny, Asyn return new AsyncApiDateTime(dateTimeValue); } } - else if (type.Value.HasFlag(SchemaType.String)) + else if (type != null && type.Value.HasFlag(SchemaType.String)) { if (format == "byte") { From 9ad74e5fdc7e1a04cde95298eba565fa92d12238 Mon Sep 17 00:00:00 2001 From: Alex Wichmann Date: Tue, 1 Aug 2023 23:36:53 +0200 Subject: [PATCH 2/2] add test --- .../ParseNodes/AsyncApiAnyConverter.cs | 2 +- .../Models/AsyncApiMessage_Should.cs | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs b/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs index 1ed73752..d2f0ec2b 100644 --- a/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs +++ b/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs @@ -109,7 +109,7 @@ public static IAsyncApiAny GetSpecificAsyncApiAny(IAsyncApiAny asyncApiAny, Asyn return new AsyncApiNull(); } - if (schema?.Type == null) + if (type == null) { if (value == "true") { diff --git a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs index f207a31c..edb13eff 100644 --- a/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs @@ -16,6 +16,33 @@ namespace LEGO.AsyncAPI.Tests.Models internal class AsyncApiMessage_Should { + [Test] + public void AsyncApiMessage_WithNoType_DeserializesToDefault() + { + // Arrange + var expected = + @"{ + ""payload"": { + ""type"": ""object"", + ""properties"": { + ""someProp"": { + ""enum"": [ + ""test"", + ""test2"" + ] + } + } + } + }"; + + // Act + var message = new AsyncApiStringReader().ReadFragment(expected, AsyncApiVersion.AsyncApi2_0, out var diagnostic); + + // Assert + diagnostic.Errors.Should().BeEmpty(); + message.Payload.Properties.First().Value.Enum.Should().HaveCount(2); + } + [Test] public void AsyncApiMessage_WithNoSchemaFormat_DeserializesToDefault() {