Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nullref if type is not set on jsonschema when using enum. #123

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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