Skip to content

Commit 20aacc1

Browse files
authored
Merge pull request #2149 from microsoft/fix/null-value-map-node
fix: parsing failure on nodes set to null
2 parents 6bb1e54 + 4245de9 commit 20aacc1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public MapNode(ParsingContext context, JsonNode node) : base(
3333
}
3434

3535
_node = mapNode;
36-
_nodes = _node.Select(p => new PropertyNode(Context, p.Key, p.Value)).ToList();
36+
_nodes = _node.Where(static p => p.Value is not null).Select(p => new PropertyNode(Context, p.Key, p.Value)).ToList();
3737
}
3838

3939
public PropertyNode this[string key]
@@ -66,7 +66,7 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, OpenApiDocument
6666
: default;
6767
}
6868
finally
69-
{
69+
{
7070
Context.EndObject();
7171
}
7272
return new
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Text.Json.Nodes;
2+
using Microsoft.OpenApi.Reader;
3+
using Microsoft.OpenApi.Reader.ParseNodes;
4+
using Xunit;
5+
6+
namespace Microsoft.OpenApi.Tests.Reader;
7+
8+
public class MapNodeTests
9+
{
10+
[Fact]
11+
public void DoesNotFailOnNullValue()
12+
{
13+
var jsonNode = JsonNode.Parse("{\"key\": null}");
14+
var mapNode = new MapNode(new ParsingContext(new()), jsonNode);
15+
16+
Assert.NotNull(mapNode);
17+
Assert.Empty(mapNode);
18+
}
19+
}

0 commit comments

Comments
 (0)