Skip to content

Commit 0630122

Browse files
committed
Fixed errors when reporting bad maps
1 parent 381c459 commit 0630122

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using Microsoft.OpenApi.Any;
9-
using Microsoft.OpenApi.Exceptions;
10-
using Microsoft.OpenApi.Interfaces;
11-
using Microsoft.OpenApi.Models;
129
using Microsoft.OpenApi.Readers.Exceptions;
1310
using SharpYaml.Serialization;
1411

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using Microsoft.OpenApi.Any;
9-
using Microsoft.OpenApi.Exceptions;
109
using Microsoft.OpenApi.Interfaces;
1110
using Microsoft.OpenApi.Models;
1211
using Microsoft.OpenApi.Readers.Exceptions;
@@ -33,7 +32,7 @@ public MapNode(ParsingContext context, YamlNode node) : base(
3332
{
3433
if (!(node is YamlMappingNode mapNode))
3534
{
36-
throw new OpenApiReaderException("Expected map.", node);
35+
throw new OpenApiReaderException("Expected map.", Context);
3736
}
3837

3938
this._node = mapNode;
@@ -48,10 +47,10 @@ public PropertyNode this[string key]
4847
{
4948
get
5049
{
51-
YamlNode node = null;
50+
YamlNode node;
5251
if (this._node.Children.TryGetValue(new YamlScalarNode(key), out node))
5352
{
54-
return new PropertyNode(Context, key, this._node.Children[new YamlScalarNode(key)]);
53+
return new PropertyNode(Context, key, node);
5554
}
5655

5756
return null;
@@ -63,7 +62,7 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
6362
var yamlMap = _node;
6463
if (yamlMap == null)
6564
{
66-
throw new OpenApiReaderException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}", yamlMap);
65+
throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context);
6766
}
6867

6968
var nodes = yamlMap.Select(
@@ -99,7 +98,7 @@ public override Dictionary<string, T> CreateMapWithReference<T>(
9998
var yamlMap = _node;
10099
if (yamlMap == null)
101100
{
102-
throw new OpenApiReaderException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}", yamlMap);
101+
throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context);
103102
}
104103

105104
var nodes = yamlMap.Select(
@@ -133,8 +132,8 @@ public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
133132
{
134133
var yamlMap = _node;
135134
if (yamlMap == null)
136-
{
137-
throw new OpenApiReaderException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}", yamlMap);
135+
{
136+
throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context);
138137
}
139138

140139
var nodes = yamlMap.Select(
@@ -189,7 +188,7 @@ public string GetScalarValue(ValueNode key)
189188
var scalarNode = _node.Children[new YamlScalarNode(key.GetScalarValue())] as YamlScalarNode;
190189
if (scalarNode == null)
191190
{
192-
throw new OpenApiReaderException($"Expected scalar at line {_node.Start.Line} for key {key.GetScalarValue()}", _node);
191+
throw new OpenApiReaderException($"Expected scalar at line {_node.Start.Line} for key {key.GetScalarValue()}", Context);
193192
}
194193

195194
return scalarNode.Value;

0 commit comments

Comments
 (0)