5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
7
using Microsoft . OpenApi . Interfaces ;
8
+ using Microsoft . OpenApi . Models . References ;
8
9
using Microsoft . OpenApi . Writers ;
9
10
10
11
@@ -120,11 +121,9 @@ public void SerializeAsV31(IOpenApiWriter writer)
120
121
PathItems ,
121
122
( w , key , component ) =>
122
123
{
123
- if ( component . Reference != null &&
124
- component . Reference . Type == ReferenceType . Schema &&
125
- component . Reference . Id == key )
124
+ if ( component is OpenApiPathItemReference reference )
126
125
{
127
- component . SerializeAsV31WithoutReference ( w ) ;
126
+ reference . SerializeAsV31 ( w ) ;
128
127
}
129
128
else
130
129
{
@@ -133,7 +132,7 @@ public void SerializeAsV31(IOpenApiWriter writer)
133
132
} ) ;
134
133
135
134
SerializeInternal ( writer , OpenApiSpecVersion . OpenApi3_1 , ( writer , element ) => element . SerializeAsV31 ( writer ) ,
136
- ( writer , referenceElement ) => referenceElement . SerializeAsV31WithoutReference ( writer ) ) ;
135
+ ( writer , referenceElement ) => referenceElement . SerializeAsV31 ( writer ) ) ;
137
136
}
138
137
139
138
/// <summary>
@@ -154,7 +153,7 @@ public void SerializeAsV3(IOpenApiWriter writer)
154
153
155
154
writer . WriteStartObject ( ) ;
156
155
SerializeInternal ( writer , OpenApiSpecVersion . OpenApi3_0 , ( writer , element ) => element . SerializeAsV3 ( writer ) ,
157
- ( writer , referenceElement ) => referenceElement . SerializeAsV3WithoutReference ( writer ) ) ;
156
+ ( writer , referenceElement ) => referenceElement . SerializeAsV3 ( writer ) ) ;
158
157
}
159
158
160
159
/// <summary>
@@ -172,14 +171,13 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
172
171
Schemas ,
173
172
( w , key , component ) =>
174
173
{
175
- if ( component . Reference is { Type : ReferenceType . Schema } &&
176
- component . Reference . Id == key )
174
+ if ( component is OpenApiSchemaReference reference )
177
175
{
178
- component . SerializeAsV3WithoutReference ( w ) ;
176
+ action ( w , reference ) ;
179
177
}
180
178
else
181
179
{
182
- component . SerializeAsV3 ( w ) ;
180
+ callback ( w , component ) ;
183
181
}
184
182
} ) ;
185
183
@@ -189,11 +187,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
189
187
Responses ,
190
188
( w , key , component ) =>
191
189
{
192
- if ( component . Reference != null &&
193
- component . Reference . Type == ReferenceType . Response &&
194
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
190
+ if ( component is OpenApiResponseReference reference )
195
191
{
196
- action ( w , component ) ;
192
+ action ( w , reference ) ;
197
193
}
198
194
else
199
195
{
@@ -207,11 +203,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
207
203
Parameters ,
208
204
( w , key , component ) =>
209
205
{
210
- if ( component . Reference != null &&
211
- component . Reference . Type == ReferenceType . Parameter &&
212
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
206
+ if ( component is OpenApiParameterReference reference )
213
207
{
214
- action ( w , component ) ;
208
+ action ( w , reference ) ;
215
209
}
216
210
else
217
211
{
@@ -225,11 +219,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
225
219
Examples ,
226
220
( w , key , component ) =>
227
221
{
228
- if ( component . Reference != null &&
229
- component . Reference . Type == ReferenceType . Example &&
230
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
222
+ if ( component is OpenApiExampleReference reference )
231
223
{
232
- action ( writer , component ) ;
224
+ action ( w , reference ) ;
233
225
}
234
226
else
235
227
{
@@ -243,12 +235,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
243
235
RequestBodies ,
244
236
( w , key , component ) =>
245
237
{
246
- if ( component . Reference != null &&
247
- component . Reference . Type == ReferenceType . RequestBody &&
248
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
249
-
238
+ if ( component is OpenApiRequestBodyReference reference )
250
239
{
251
- action ( w , component ) ;
240
+ action ( w , reference ) ;
252
241
}
253
242
else
254
243
{
@@ -262,11 +251,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
262
251
Headers ,
263
252
( w , key , component ) =>
264
253
{
265
- if ( component . Reference != null &&
266
- component . Reference . Type == ReferenceType . Header &&
267
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
254
+ if ( component is OpenApiHeaderReference reference )
268
255
{
269
- action ( w , component ) ;
256
+ action ( w , reference ) ;
270
257
}
271
258
else
272
259
{
@@ -280,11 +267,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
280
267
SecuritySchemes ,
281
268
( w , key , component ) =>
282
269
{
283
- if ( component . Reference != null &&
284
- component . Reference . Type == ReferenceType . SecurityScheme &&
285
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
270
+ if ( component is OpenApiSecuritySchemeReference reference )
286
271
{
287
- action ( w , component ) ;
272
+ action ( w , reference ) ;
288
273
}
289
274
else
290
275
{
@@ -298,11 +283,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
298
283
Links ,
299
284
( w , key , component ) =>
300
285
{
301
- if ( component . Reference != null &&
302
- component . Reference . Type == ReferenceType . Link &&
303
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
286
+ if ( component is OpenApiLinkReference reference )
304
287
{
305
- action ( w , component ) ;
288
+ action ( w , reference ) ;
306
289
}
307
290
else
308
291
{
@@ -316,11 +299,9 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
316
299
Callbacks ,
317
300
( w , key , component ) =>
318
301
{
319
- if ( component . Reference != null &&
320
- component . Reference . Type == ReferenceType . Callback &&
321
- string . Equals ( component . Reference . Id , key , StringComparison . OrdinalIgnoreCase ) )
302
+ if ( component is OpenApiCallbackReference reference )
322
303
{
323
- action ( w , component ) ;
304
+ action ( w , reference ) ;
324
305
}
325
306
else
326
307
{
0 commit comments