Skip to content

Commit 308f508

Browse files
authoredOct 10, 2021
nullable checks, additional registers
1 parent fdd1f90 commit 308f508

File tree

3 files changed

+63
-11
lines changed

3 files changed

+63
-11
lines changed
 

‎Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.3.10</Version>
3+
<Version>0.3.11</Version>
44
</PropertyGroup>
55
</Project>

‎src/QAToolKit.Source.Swagger/QAToolKit.Source.Swagger.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<PackageReference Include="Microsoft.OpenApi" Version="1.2.3" />
3838
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
3939
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
40-
<PackageReference Include="QAToolKit.Core" Version="0.3.9" />
40+
<PackageReference Include="QAToolKit.Core" Version="0.3.10" />
4141
</ItemGroup>
4242

4343
</Project>

‎src/QAToolKit.Source.Swagger/SwaggerProcessor.cs

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public IEnumerable<HttpRequest> MapFromOpenApiDocument(Uri baseUri, OpenApiDocum
5555
{
5656
if (baseUri == null)
5757
{
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.");
5960
}
6061

6162
baseUri = new Uri(baseUri, tempUri);
@@ -106,6 +107,16 @@ private IEnumerable<HttpRequest> GetRestRequestsForPath(Uri baseUri, KeyValuePai
106107
{
107108
var testType = new List<TestType.Enumeration>();
108109

110+
if (operation.Value == null)
111+
{
112+
return testType;
113+
}
114+
115+
if (operation.Value.Description == null)
116+
{
117+
return testType;
118+
}
119+
109120
if (operation.Value.Description.Contains(TestType.IntegrationTest.Value()))
110121
{
111122
testType.Add(TestType.Enumeration.IntegrationTest);
@@ -129,10 +140,21 @@ private IEnumerable<HttpRequest> GetRestRequestsForPath(Uri baseUri, KeyValuePai
129140
return testType;
130141
}
131142

132-
private List<AuthenticationType.Enumeration> GetAuthenticationTypes(KeyValuePair<OperationType, OpenApiOperation> operation)
143+
private List<AuthenticationType.Enumeration> GetAuthenticationTypes(
144+
KeyValuePair<OperationType, OpenApiOperation> operation)
133145
{
134146
var authenticationTypes = new List<AuthenticationType.Enumeration>();
135147

148+
if (operation.Value == null)
149+
{
150+
return authenticationTypes;
151+
}
152+
153+
if (operation.Value.Description == null)
154+
{
155+
return authenticationTypes;
156+
}
157+
136158
if (operation.Value.Description.Contains(AuthenticationType.Administrator.Value()))
137159
{
138160
authenticationTypes.Add(AuthenticationType.Enumeration.Administrator);
@@ -158,11 +180,31 @@ private IEnumerable<HttpRequest> GetRestRequestsForPath(Uri baseUri, KeyValuePai
158180

159181
private string GetDescription(KeyValuePair<OperationType, OpenApiOperation> operation)
160182
{
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+
161193
return operation.Value.Description;
162194
}
163195

164196
private string[] GetTags(KeyValuePair<OperationType, OpenApiOperation> operation)
165197
{
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+
166208
return operation.Value.Tags.Select(t => t.Name).ToArray();
167209
}
168210

@@ -221,8 +263,10 @@ private HttpMethod GetHttpMethod(KeyValuePair<OperationType, OpenApiOperation> o
221263
"403" => HttpStatusCode.Forbidden,
222264
"404" => HttpStatusCode.NotFound,
223265
"405" => HttpStatusCode.MethodNotAllowed,
266+
"406" => HttpStatusCode.NotAcceptable,
224267
"409" => HttpStatusCode.Conflict,
225268
"500" => HttpStatusCode.InternalServerError,
269+
"503" => HttpStatusCode.ServiceUnavailable,
226270
"default" => null,
227271
_ => throw new QAToolKitSwaggerException($"HttpStatusCode not found '{statusCode}'."),
228272
};
@@ -332,6 +376,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
332376
var properties = new List<Property>();
333377

334378
#region Items
379+
335380
Property itemsProperty = null;
336381

337382
if (source.Value.Items != null)
@@ -359,13 +404,16 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
359404
{
360405
itemsProperty.Properties = new List<Property>();
361406
}
407+
362408
itemsProperty.Properties.AddRange(recursiveProperties);
363409
}
364410
}
365411
}
412+
366413
#endregion
367414

368415
#region enums
416+
369417
Property enumProperty = null;
370418
if (source.Value.Enum != null && source.Value.Enum.Count > 0)
371419
{
@@ -396,6 +444,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
396444
}
397445
}
398446
}
447+
399448
#endregion
400449

401450
var prop = new Property
@@ -437,6 +486,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
437486
{
438487
prop.Properties = new List<Property>();
439488
}
489+
440490
prop.Properties.AddRange(propsTem);
441491
}
442492

@@ -491,17 +541,19 @@ private List<Response> GetResponses(KeyValuePair<OperationType, OpenApiOperation
491541
private ResponseType GetResponseType(OpenApiResponse value)
492542
{
493543
foreach (var contentType in value.Content.Where(contentType =>
494-
ContentType.From(contentType.Key) == ContentType.Json))
544+
ContentType.From(contentType.Key) == ContentType.Json))
495545
{
496546
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") &&
498549
contentType.Value.Schema.Type == "array")
499550
{
500551
return ResponseType.Array;
501552
}
502553
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")
505557
{
506558
return ResponseType.Objects;
507559
}
@@ -510,7 +562,7 @@ private ResponseType GetResponseType(OpenApiResponse value)
510562
return ResponseType.Object;
511563
}
512564
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"))
514566
{
515567
return ResponseType.Primitive;
516568
}
@@ -539,7 +591,7 @@ private List<Property> GetResponseProperties(OpenApiResponse openApiResponse)
539591

540592
//TODO: support other content types
541593
foreach (var contentType in openApiResponse.Content.Where(contentType =>
542-
ContentType.From(contentType.Key) == ContentType.Json))
594+
ContentType.From(contentType.Key) == ContentType.Json))
543595
{
544596
if (contentType.Value.Schema.Properties != null && contentType.Value.Schema.Properties.Count > 0)
545597
{
@@ -561,4 +613,4 @@ private List<Property> GetResponseProperties(OpenApiResponse openApiResponse)
561613
return properties;
562614
}
563615
}
564-
}
616+
}

0 commit comments

Comments
 (0)
Please sign in to comment.