Skip to content

Commit 95fe099

Browse files
authored
fix(oneof-anyof-nulls): added fix for deserializing null values to oaf containers (#59)
This commit adds support for the null values to pass while deserialization if none of the inner types are matched as the OAF containers are nullable by default
1 parent 7fb7681 commit 95fe099

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

APIMatic.Core.Test/Utilities/OneOfContainerTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public void TestNativeType()
7878
});
7979
}
8080

81+
[Test]
82+
public void TestNativeTypeWithNullValue()
83+
{
84+
NativeOneOfContainer container = CoreHelper.JsonDeserialize<NativeOneOfContainer>("null");
85+
86+
Assert.IsNull(container);
87+
}
88+
8189
[Test]
8290
public void TestNativeNullableType()
8391
{

APIMatic.Core/Utilities/Converters/UnionTypeConverter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ private T DeserializeOneOfAnyOf(JToken token, JsonSerializer serializer, List<Un
7979
return mappedValues[0].value;
8080
}
8181

82+
if (token.Type == JTokenType.Null)
83+
{
84+
// allow null values to pass as the OAF containers are nullable by default
85+
return default;
86+
}
87+
8288
if (_isOneOf)
8389
{
8490
throw new OneOfValidationException(unMappedTypes, token.ToString());

0 commit comments

Comments
 (0)