@@ -55,7 +55,8 @@ public IEnumerable<HttpRequest> MapFromOpenApiDocument(Uri baseUri, OpenApiDocum
55
55
{
56
56
if ( baseUri == null )
57
57
{
58
- throw new QAToolKitSwaggerException ( "Swagger from file source needs BaseUrl defined. Inject baseUrl with AddBaseUrl in your SwaggerSource instantiation." ) ;
58
+ throw new QAToolKitSwaggerException (
59
+ "Swagger from file source needs BaseUrl defined. Inject baseUrl with AddBaseUrl in your SwaggerSource instantiation." ) ;
59
60
}
60
61
61
62
baseUri = new Uri ( baseUri , tempUri ) ;
@@ -106,6 +107,16 @@ private IEnumerable<HttpRequest> GetRestRequestsForPath(Uri baseUri, KeyValuePai
106
107
{
107
108
var testType = new List < TestType . Enumeration > ( ) ;
108
109
110
+ if ( operation . Value == null )
111
+ {
112
+ return testType ;
113
+ }
114
+
115
+ if ( operation . Value . Description == null )
116
+ {
117
+ return testType ;
118
+ }
119
+
109
120
if ( operation . Value . Description . Contains ( TestType . IntegrationTest . Value ( ) ) )
110
121
{
111
122
testType . Add ( TestType . Enumeration . IntegrationTest ) ;
@@ -129,10 +140,21 @@ private IEnumerable<HttpRequest> GetRestRequestsForPath(Uri baseUri, KeyValuePai
129
140
return testType ;
130
141
}
131
142
132
- private List < AuthenticationType . Enumeration > GetAuthenticationTypes ( KeyValuePair < OperationType , OpenApiOperation > operation )
143
+ private List < AuthenticationType . Enumeration > GetAuthenticationTypes (
144
+ KeyValuePair < OperationType , OpenApiOperation > operation )
133
145
{
134
146
var authenticationTypes = new List < AuthenticationType . Enumeration > ( ) ;
135
147
148
+ if ( operation . Value == null )
149
+ {
150
+ return authenticationTypes ;
151
+ }
152
+
153
+ if ( operation . Value . Description == null )
154
+ {
155
+ return authenticationTypes ;
156
+ }
157
+
136
158
if ( operation . Value . Description . Contains ( AuthenticationType . Administrator . Value ( ) ) )
137
159
{
138
160
authenticationTypes . Add ( AuthenticationType . Enumeration . Administrator ) ;
@@ -158,11 +180,31 @@ private IEnumerable<HttpRequest> GetRestRequestsForPath(Uri baseUri, KeyValuePai
158
180
159
181
private string GetDescription ( KeyValuePair < OperationType , OpenApiOperation > operation )
160
182
{
183
+ if ( operation . Value == null )
184
+ {
185
+ return String . Empty ;
186
+ }
187
+
188
+ if ( operation . Value . Description == null )
189
+ {
190
+ return String . Empty ;
191
+ }
192
+
161
193
return operation . Value . Description ;
162
194
}
163
195
164
196
private string [ ] GetTags ( KeyValuePair < OperationType , OpenApiOperation > operation )
165
197
{
198
+ if ( operation . Value == null )
199
+ {
200
+ return Array . Empty < string > ( ) ;
201
+ }
202
+
203
+ if ( operation . Value . Tags == null )
204
+ {
205
+ return Array . Empty < string > ( ) ;
206
+ }
207
+
166
208
return operation . Value . Tags . Select ( t => t . Name ) . ToArray ( ) ;
167
209
}
168
210
@@ -221,8 +263,10 @@ private HttpMethod GetHttpMethod(KeyValuePair<OperationType, OpenApiOperation> o
221
263
"403" => HttpStatusCode . Forbidden ,
222
264
"404" => HttpStatusCode . NotFound ,
223
265
"405" => HttpStatusCode . MethodNotAllowed ,
266
+ "406" => HttpStatusCode . NotAcceptable ,
224
267
"409" => HttpStatusCode . Conflict ,
225
268
"500" => HttpStatusCode . InternalServerError ,
269
+ "503" => HttpStatusCode . ServiceUnavailable ,
226
270
"default" => null ,
227
271
_ => throw new QAToolKitSwaggerException ( $ "HttpStatusCode not found '{ statusCode } '.") ,
228
272
} ;
@@ -332,6 +376,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
332
376
var properties = new List < Property > ( ) ;
333
377
334
378
#region Items
379
+
335
380
Property itemsProperty = null ;
336
381
337
382
if ( source . Value . Items != null )
@@ -359,13 +404,16 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
359
404
{
360
405
itemsProperty . Properties = new List < Property > ( ) ;
361
406
}
407
+
362
408
itemsProperty . Properties . AddRange ( recursiveProperties ) ;
363
409
}
364
410
}
365
411
}
412
+
366
413
#endregion
367
414
368
415
#region enums
416
+
369
417
Property enumProperty = null ;
370
418
if ( source . Value . Enum != null && source . Value . Enum . Count > 0 )
371
419
{
@@ -396,6 +444,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
396
444
}
397
445
}
398
446
}
447
+
399
448
#endregion
400
449
401
450
var prop = new Property
@@ -437,6 +486,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
437
486
{
438
487
prop . Properties = new List < Property > ( ) ;
439
488
}
489
+
440
490
prop . Properties . AddRange ( propsTem ) ;
441
491
}
442
492
@@ -491,17 +541,19 @@ private List<Response> GetResponses(KeyValuePair<OperationType, OpenApiOperation
491
541
private ResponseType GetResponseType ( OpenApiResponse value )
492
542
{
493
543
foreach ( var contentType in value . Content . Where ( contentType =>
494
- ContentType . From ( contentType . Key ) == ContentType . Json ) )
544
+ ContentType . From ( contentType . Key ) == ContentType . Json ) )
495
545
{
496
546
if ( contentType . Value . Schema . Items != null &&
497
- ( contentType . Value . Schema . Items . Type == "array" || contentType . Value . Schema . Items . Type != "object" ) &&
547
+ ( contentType . Value . Schema . Items . Type == "array" ||
548
+ contentType . Value . Schema . Items . Type != "object" ) &&
498
549
contentType . Value . Schema . Type == "array" )
499
550
{
500
551
return ResponseType . Array ;
501
552
}
502
553
else if ( contentType . Value . Schema . Items != null &&
503
- ( contentType . Value . Schema . Items . Type == "array" || contentType . Value . Schema . Items . Type == "object" ) &&
504
- contentType . Value . Schema . Type == "array" )
554
+ ( contentType . Value . Schema . Items . Type == "array" ||
555
+ contentType . Value . Schema . Items . Type == "object" ) &&
556
+ contentType . Value . Schema . Type == "array" )
505
557
{
506
558
return ResponseType . Objects ;
507
559
}
@@ -510,7 +562,7 @@ private ResponseType GetResponseType(OpenApiResponse value)
510
562
return ResponseType . Object ;
511
563
}
512
564
else if ( contentType . Value . Schema . Items == null &&
513
- ( contentType . Value . Schema . Type != "object" || contentType . Value . Schema . Type != "array" ) )
565
+ ( contentType . Value . Schema . Type != "object" || contentType . Value . Schema . Type != "array" ) )
514
566
{
515
567
return ResponseType . Primitive ;
516
568
}
@@ -539,7 +591,7 @@ private List<Property> GetResponseProperties(OpenApiResponse openApiResponse)
539
591
540
592
//TODO: support other content types
541
593
foreach ( var contentType in openApiResponse . Content . Where ( contentType =>
542
- ContentType . From ( contentType . Key ) == ContentType . Json ) )
594
+ ContentType . From ( contentType . Key ) == ContentType . Json ) )
543
595
{
544
596
if ( contentType . Value . Schema . Properties != null && contentType . Value . Schema . Properties . Count > 0 )
545
597
{
@@ -561,4 +613,4 @@ private List<Property> GetResponseProperties(OpenApiResponse openApiResponse)
561
613
return properties ;
562
614
}
563
615
}
564
- }
616
+ }
0 commit comments