@@ -93,7 +93,7 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
93
93
94
94
public override Dictionary < string , T > CreateMapWithReference < T > (
95
95
ReferenceType referenceType ,
96
- Func < MapNode , T > map )
96
+ Func < MapNode , T > map )
97
97
{
98
98
var yamlMap = _node ;
99
99
if ( yamlMap == null )
@@ -104,28 +104,37 @@ public override Dictionary<string, T> CreateMapWithReference<T>(
104
104
var nodes = yamlMap . Select (
105
105
n =>
106
106
{
107
- var entry = new
108
- {
109
- key = n . Key . GetScalarValue ( ) ,
110
- value = map ( new MapNode ( Context , ( YamlMappingNode ) n . Value ) )
111
- } ;
112
- if ( entry . value == null )
113
- {
114
- return null ; // Body Parameters shouldn't be converted to Parameters
115
- }
116
- // If the component isn't a reference to another component, then point it to itself.
117
- if ( entry . value . Reference == null )
107
+ var key = n . Key . GetScalarValue ( ) ;
108
+ ( string key , T value ) entry ;
109
+ try
118
110
{
119
- entry . value . Reference = new OpenApiReference ( )
111
+ Context . StartObject ( key ) ;
112
+ entry = (
113
+ key : key ,
114
+ value : map ( new MapNode ( Context , ( YamlMappingNode ) n . Value ) )
115
+ ) ;
116
+ if ( entry . value == null )
117
+ {
118
+ return default ; // Body Parameters shouldn't be converted to Parameters
119
+ }
120
+ // If the component isn't a reference to another component, then point it to itself.
121
+ if ( entry . value . Reference == null )
120
122
{
121
- Type = referenceType ,
122
- Id = entry . key
123
- } ;
123
+ entry . value . Reference = new OpenApiReference ( )
124
+ {
125
+ Type = referenceType ,
126
+ Id = entry . key
127
+ } ;
128
+ }
129
+ }
130
+ finally
131
+ {
132
+ Context . EndObject ( ) ;
124
133
}
125
134
return entry ;
126
135
}
127
136
) ;
128
- return nodes . Where ( n => n != null ) . ToDictionary ( k => k . key , v => v . value ) ;
137
+ return nodes . Where ( n => n != default ) . ToDictionary ( k => k . key , v => v . value ) ;
129
138
}
130
139
131
140
public override Dictionary < string , T > CreateSimpleMap < T > ( Func < ValueNode , T > map )
@@ -137,10 +146,21 @@ public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
137
146
}
138
147
139
148
var nodes = yamlMap . Select (
140
- n => new
149
+ n =>
141
150
{
142
- key = n . Key . GetScalarValue ( ) ,
143
- value = map ( new ValueNode ( Context , ( YamlScalarNode ) n . Value ) )
151
+ var key = n . Key . GetScalarValue ( ) ;
152
+ try
153
+ {
154
+ Context . StartObject ( key ) ;
155
+ YamlScalarNode scalarNode = n . Value as YamlScalarNode ;
156
+ if ( scalarNode == null )
157
+ {
158
+ throw new OpenApiReaderException ( $ "Expected scalar while parsing { typeof ( T ) . Name } ", Context ) ;
159
+ }
160
+ return ( key , value : map ( new ValueNode ( Context , ( YamlScalarNode ) n . Value ) ) ) ;
161
+ } finally {
162
+ Context . EndObject ( ) ;
163
+ }
144
164
} ) ;
145
165
return nodes . ToDictionary ( k => k . key , v => v . value ) ;
146
166
}
0 commit comments