Skip to content

Commit be1e4f2

Browse files
committed
cleanup
1 parent 0407946 commit be1e4f2

File tree

3 files changed

+23
-43
lines changed

3 files changed

+23
-43
lines changed

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="12.0.3" />
40-
<PackageReference Include="QAToolKit.Core" Version="0.1.7" />
40+
<PackageReference Include="QAToolKit.Core" Version="0.2.0" />
4141
</ItemGroup>
4242

4343
</Project>

src/QAToolKit.Source.Swagger/SwaggerOptions.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,8 @@ public SwaggerOptions AddBasicAuthentication(string userName, string password)
6565
/// <returns></returns>
6666
public SwaggerOptions AddRequestFilters(RequestFilter requestFilter)
6767
{
68-
if (requestFilter == null)
69-
throw new ArgumentException(nameof(requestFilter));
70-
7168
UseRequestFilter = true;
72-
RequestFilter = requestFilter;
69+
RequestFilter = requestFilter ?? throw new ArgumentException(nameof(requestFilter));
7370
return this;
7471
}
7572

@@ -80,10 +77,7 @@ public SwaggerOptions AddRequestFilters(RequestFilter requestFilter)
8077
/// <returns></returns>
8178
public SwaggerOptions AddBaseUrl(Uri baseUrl)
8279
{
83-
if (baseUrl == null)
84-
throw new ArgumentException(nameof(baseUrl));
85-
86-
BaseUrl = baseUrl;
80+
BaseUrl = baseUrl ?? throw new ArgumentException(nameof(baseUrl));
8781
return this;
8882
}
8983
}

src/QAToolKit.Source.Swagger/SwaggerProcessor.cs

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,22 @@ private HttpMethod GetHttpMethod(KeyValuePair<OperationType, OpenApiOperation> o
199199

200200
private HttpStatusCode? GetHttpStatus(string statusCode)
201201
{
202-
switch (statusCode)
203-
{
204-
case "200":
205-
return HttpStatusCode.OK;
206-
case "201":
207-
return HttpStatusCode.Created;
208-
case "202":
209-
return HttpStatusCode.Accepted;
210-
case "204":
211-
return HttpStatusCode.NoContent;
212-
case "400":
213-
return HttpStatusCode.BadRequest;
214-
case "401":
215-
return HttpStatusCode.Unauthorized;
216-
case "403":
217-
return HttpStatusCode.Forbidden;
218-
case "404":
219-
return HttpStatusCode.NotFound;
220-
case "405":
221-
return HttpStatusCode.MethodNotAllowed;
222-
case "409":
223-
return HttpStatusCode.Conflict;
224-
case "500":
225-
return HttpStatusCode.InternalServerError;
226-
case "default":
227-
return null;
228-
default:
229-
throw new QAToolKitSwaggerException("HttpStatusCode not found.");
230-
}
202+
return statusCode switch
203+
{
204+
"200" => HttpStatusCode.OK,
205+
"201" => HttpStatusCode.Created,
206+
"202" => HttpStatusCode.Accepted,
207+
"204" => HttpStatusCode.NoContent,
208+
"400" => HttpStatusCode.BadRequest,
209+
"401" => HttpStatusCode.Unauthorized,
210+
"403" => HttpStatusCode.Forbidden,
211+
"404" => HttpStatusCode.NotFound,
212+
"405" => HttpStatusCode.MethodNotAllowed,
213+
"409" => HttpStatusCode.Conflict,
214+
"500" => HttpStatusCode.InternalServerError,
215+
"default" => null,
216+
_ => throw new QAToolKitSwaggerException("HttpStatusCode not found."),
217+
};
231218
}
232219

233220
private string GetSummary(KeyValuePair<OperationType, OpenApiOperation> openApiOperation)
@@ -311,7 +298,7 @@ private List<RequestBody> GetRequestBodies(KeyValuePair<OperationType, OpenApiOp
311298
{
312299
var requestBody = new RequestBody
313300
{
314-
Name = contentType.Value.Schema.Reference != null ? contentType.Value.Schema.Reference.Id : null,
301+
Name = contentType.Value.Schema.Reference?.Id,
315302
ContentType = ContentType.ToEnum(contentType.Key),
316303
Properties = null,
317304
Required = openApiOperation.Value.RequestBody.Required
@@ -334,9 +321,8 @@ private List<RequestBody> GetRequestBodies(KeyValuePair<OperationType, OpenApiOp
334321

335322
return requests;
336323
}
337-
catch (Exception ex)
324+
catch
338325
{
339-
var msg = ex.Message;
340326
return new List<RequestBody>();
341327
}
342328
}
@@ -357,7 +343,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
357343
Format = source.Value.Items.Description,
358344
Type = source.Value.Items.Type,
359345
Properties = null,
360-
Name = source.Value.Items.Reference != null ? source.Value.Items.Reference.Id : null
346+
Name = source.Value.Items.Reference?.Id
361347
};
362348
itemsProperty.Required = source.Value.Items.Required.Contains(itemsProperty.Name);
363349

@@ -390,7 +376,7 @@ private List<Property> GetPropertiesRecursively(KeyValuePair<string, OpenApiSche
390376
Format = null,
391377
Type = "enum",
392378
Properties = new List<Property>(),
393-
Name = source.Value.Reference != null ? source.Value.Reference.Id : null,
379+
Name = source.Value.Reference?.Id,
394380
};
395381
enumProperty.Required = source.Value.Required.Contains(enumProperty.Name);
396382

0 commit comments

Comments
 (0)