diff --git a/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs b/src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs index 4bd72a19..d2f0ec2b 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") { @@ -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() {