Skip to content

Commit c664ea5

Browse files
committed
Added map keys into the context path
1 parent f3267bc commit c664ea5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,26 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
6767
}
6868

6969
var nodes = yamlMap.Select(
70-
n => new
71-
{
72-
key = n.Key.GetScalarValue(),
73-
value = n.Value as YamlMappingNode == null
74-
? default(T)
75-
: map(new MapNode(Context, n.Value as YamlMappingNode))
70+
n => {
71+
72+
var key = n.Key.GetScalarValue();
73+
T value;
74+
try
75+
{
76+
Context.StartObject(key);
77+
value = n.Value as YamlMappingNode == null
78+
? default(T)
79+
: map(new MapNode(Context, n.Value as YamlMappingNode));
80+
}
81+
finally
82+
{
83+
Context.EndObject();
84+
}
85+
return new
86+
{
87+
key = key,
88+
value = value
89+
};
7690
});
7791

7892
return nodes.ToDictionary(k => k.key, v => v.value);

test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public void BadSchema()
5454
reader.Read(input, out var diagnostic);
5555

5656
diagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>() {
57-
new OpenApiError(new OpenApiReaderException("Expected a value.") {
58-
Pointer = "#/~1foo/get/responses/200/content/application~1json/schema"
57+
new OpenApiError(new OpenApiReaderException("schema must be a map/object") {
58+
Pointer = "#/paths/~1foo/get/responses/200/content/application~1json/schema"
5959
})
6060
});
6161
}

0 commit comments

Comments
 (0)