Skip to content

Commit 3c944e1

Browse files
committed
Fix dereferenced variables might be null
1 parent 8fefc84 commit 3c944e1

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override List<T> CreateList<T>(Func<MapNode, T> map)
2626
//throw new OpenApiReaderException($"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList);
2727
}
2828

29-
return _nodeList.Select(n => map(new MapNode(Context, n as JsonObject)))
29+
return _nodeList?.Select(n => map(new MapNode(Context, n as JsonObject)))
3030
.Where(i => i != null)
3131
.ToList();
3232
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public string GetScalarValue(ValueNode key)
190190
//throw new OpenApiReaderException($"Expected scalar at line {_node.Start.Line} for key {key.GetScalarValue()}", Context);
191191
}
192192

193-
return scalarNode.ToString();
193+
return scalarNode?.GetValue<string>();
194194
}
195195

196196
/// <summary>

src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ValueNode(ParsingContext context, JsonNode node) : base(
2222

2323
public override string GetScalarValue()
2424
{
25-
return _node.ToString();
25+
return _node.GetValue<string>();
2626
}
2727

2828
/// <summary>

src/Microsoft.OpenApi.Readers/YamlHelper.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
using System.Globalization;
54
using System.IO;
65
using System.Linq;
7-
using System.Text.Json;
86
using System.Text.Json.Nodes;
9-
using Microsoft.OpenApi.Exceptions;
107
using SharpYaml.Serialization;
118

129
namespace Microsoft.OpenApi.Readers
@@ -22,7 +19,7 @@ public static string GetScalarValue(this JsonNode node)
2219
//throw new OpenApiException($"Expected scalar at line {node.Start.Line}");
2320
}
2421

25-
return scalarNode.ToString();
22+
return scalarNode?.GetValue<string>();
2623
}
2724

2825
public static JsonNode ParseJsonString(string yamlString)

0 commit comments

Comments
 (0)