Skip to content

Commit

Permalink
fix: nullref if type is not set on jsonschema when using enum. (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean authored Aug 1, 2023
1 parent 22b329c commit e53db72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI.Readers/ParseNodes/AsyncApiAnyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down Expand Up @@ -109,7 +109,7 @@ public static IAsyncApiAny GetSpecificAsyncApiAny(IAsyncApiAny asyncApiAny, Asyn
return new AsyncApiNull();
}

if (schema?.Type == null)
if (type == null)
{
if (value == "true")
{
Expand Down
27 changes: 27 additions & 0 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiMessage_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncApiMessage>(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()
{
Expand Down

0 comments on commit e53db72

Please sign in to comment.