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
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

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

public PropertyNode this[string key]
Expand Down Expand Up @@ -66,7 +66,7 @@
: default;
}
finally
{
{
Context.EndObject();
}
return new
Expand Down Expand Up @@ -164,7 +164,7 @@
? jsonValue
: throw new OpenApiReaderException($"Expected scalar while parsing {key.GetScalarValue()}", Context);

return Convert.ToString(scalarNode?.GetValue<object>(), CultureInfo.InvariantCulture);

Check warning on line 167 in src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)

Check warning on line 167 in src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)

Check warning on line 167 in src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)

Check warning on line 167 in src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this unnecessary check for null. (https://rules.sonarsource.com/csharp/RSPEC-2589)
}

/// <summary>
Expand Down
19 changes: 19 additions & 0 deletions test/Microsoft.OpenApi.Tests/Reader/MapNodeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.ParseNodes;
using Xunit;

namespace Microsoft.OpenApi.Tests.Reader;

public class MapNodeTests
{
[Fact]
public void DoesNotFailOnNullValue()
{
var jsonNode = JsonNode.Parse("{\"key\": null}");
var mapNode = new MapNode(new ParsingContext(new()), jsonNode);

Assert.NotNull(mapNode);
Assert.Empty(mapNode);
}
}