Skip to content
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 @@ -125,7 +125,7 @@ public class JsonSchemaDeserializer
{
"additionalProperties", (a, n) =>
{
if (n.GetBooleanValueOrDefault(null) == false)
if (n is ValueNode && n.GetBooleanValueOrDefault(null) == false)
{
a.AdditionalProperties = new NoAdditionalProperties();
}
Expand Down Expand Up @@ -171,6 +171,9 @@ public class JsonSchemaDeserializer
{
"deprecated", (a, n) => { a.Deprecated = bool.Parse(n.GetScalarValue()); }
},
{
"nullable", (a, n) => { a.Nullable = n.GetBooleanValue(); }
},
};

private static readonly PatternFieldMap<AsyncApiSchema> schemaPatternFields =
Expand Down
84 changes: 84 additions & 0 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Copyright (c) The LEGO Group. All rights reserved.

using System.Linq;
using LEGO.AsyncAPI.Bindings;
using LEGO.AsyncAPI.Readers;

namespace LEGO.AsyncAPI.Tests.Models
{
using System;
Expand Down Expand Up @@ -89,6 +93,16 @@ public class AsyncApiSchema_Should
MinLength = 2,
},
},
AdditionalProperties = new AsyncApiSchema
{
Properties = new Dictionary<string, AsyncApiSchema>
{
["Property8"] = new AsyncApiSchema
{
Type = SchemaType.String | SchemaType.Null,
},
},
},
},
},
Nullable = true,
Expand Down Expand Up @@ -393,6 +407,16 @@ public void SerializeAsJson_WithAdvancedSchemaObject_V2Works()
""type"": ""string"",
""minLength"": 2
}
},
""additionalProperties"": {
""properties"": {
""Property8"": {
""type"": [
""null"",
""string""
]
}
}
}
}
},
Expand All @@ -411,6 +435,66 @@ public void SerializeAsJson_WithAdvancedSchemaObject_V2Works()
actual.Should().Be(expected);
}

[Test]
public void Deserialize_WithAdditionalProperties_Works()
{
// Arrange
var json = @"{
""title"": ""title1"",
""properties"": {
""property1"": {
""properties"": {
""property2"": {
""type"": ""integer""
},
""property3"": {
""type"": ""string"",
""maxLength"": 15
}
},
""additionalProperties"": false
},
""property4"": {
""properties"": {
""property5"": {
""properties"": {
""property6"": {
""type"": ""boolean""
}
}
},
""property7"": {
""type"": ""string"",
""minLength"": 2
}
},
""additionalProperties"": {
""properties"": {
""Property8"": {
""type"": [
""null"",
""string""
]
}
}
}
}
},
""nullable"": true,
""externalDocs"": {
""url"": ""http://example.com/externalDocs""
}
}";
var expected = AdvancedSchemaObject;

// Act
var actual = new AsyncApiStringReader().ReadFragment<AsyncApiSchema>(json, AsyncApiVersion.AsyncApi2_0, out var _diagnostics);

// Assert
actual.Should().BeEquivalentTo(expected);
_diagnostics.Errors.Should().BeEmpty();
}

[Test]
public void SerializeAsJson_WithAdvancedSchemaWithAllOf_V2Works()
{
Expand Down