Skip to content

Commit dbd8d92

Browse files
committed
Clean up and add XML documentations for public methods
1 parent c3c0abc commit dbd8d92

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/Microsoft.OpenApi.Tool/OpenApiService.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
25
using System.IO;
36
using System.Linq;
47
using System.Net;
@@ -24,9 +27,13 @@ public static void ProcessOpenApiDocument(
2427
bool inline,
2528
bool resolveExternal)
2629
{
27-
if (input == null)
30+
if (string.IsNullOrEmpty(input))
2831
{
29-
throw new ArgumentNullException("input");
32+
throw new ArgumentNullException(nameof(input));
33+
}
34+
if (output.Exists)
35+
{
36+
throw new IOException("The file you're writing to already exists. Please input a new output path.");
3037
}
3138

3239
var stream = GetStream(input);
@@ -51,7 +58,7 @@ public static void ProcessOpenApiDocument(
5158

5259
var context = result.OpenApiDiagnostic;
5360

54-
if (context.Errors.Count != 0)
61+
if (context.Errors.Count > 0)
5562
{
5663
var errorReport = new StringBuilder();
5764

@@ -63,11 +70,6 @@ public static void ProcessOpenApiDocument(
6370
throw new ArgumentException(string.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
6471
}
6572

66-
if (output.Exists)
67-
{
68-
throw new IOException("The file you're writing to already exists.Please input a new output path.");
69-
}
70-
7173
using var outputStream = output?.Create();
7274

7375
var textWriter = outputStream != null ? new StreamWriter(outputStream) : Console.Out;

src/Microsoft.OpenApi/Services/CopyReferences.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -9,14 +9,18 @@ namespace Microsoft.OpenApi.Services
99
{
1010
internal class CopyReferences : OpenApiVisitorBase
1111
{
12-
private readonly OpenApiDocument target;
13-
public OpenApiComponents Components = new OpenApiComponents();
12+
private readonly OpenApiDocument _target;
13+
public OpenApiComponents Components = new();
1414

1515
public CopyReferences(OpenApiDocument target)
1616
{
17-
this.target = target;
17+
_target = target;
1818
}
1919

20+
/// <summary>
21+
/// Visits IOpenApiReferenceable instances that are references and not in components.
22+
/// </summary>
23+
/// <param name="referenceable"> An IOpenApiReferenceable object.</param>
2024
public override void Visit(IOpenApiReferenceable referenceable)
2125
{
2226
switch (referenceable)
@@ -54,6 +58,10 @@ public override void Visit(IOpenApiReferenceable referenceable)
5458
base.Visit(referenceable);
5559
}
5660

61+
/// <summary>
62+
/// Visits <see cref="OpenApiSchema"/>
63+
/// </summary>
64+
/// <param name="schema">The OpenApiSchema to be visited.</param>
5765
public override void Visit(OpenApiSchema schema)
5866
{
5967
// This is needed to handle schemas used in Responses in components
@@ -71,33 +79,33 @@ public override void Visit(OpenApiSchema schema)
7179

7280
private void EnsureComponentsExists()
7381
{
74-
if (target.Components == null)
82+
if (_target.Components == null)
7583
{
76-
target.Components = new OpenApiComponents();
84+
_target.Components = new OpenApiComponents();
7785
}
7886
}
7987

8088
private void EnsureSchemasExists()
8189
{
82-
if (target.Components.Schemas == null)
90+
if (_target.Components.Schemas == null)
8391
{
84-
target.Components.Schemas = new Dictionary<string, OpenApiSchema>();
92+
_target.Components.Schemas = new Dictionary<string, OpenApiSchema>();
8593
}
8694
}
8795

8896
private void EnsureParametersExists()
8997
{
90-
if (target.Components.Parameters == null)
98+
if (_target.Components.Parameters == null)
9199
{
92-
target.Components.Parameters = new Dictionary<string, OpenApiParameter>();
100+
_target.Components.Parameters = new Dictionary<string, OpenApiParameter>();
93101
}
94102
}
95103

96104
private void EnsureResponsesExists()
97105
{
98-
if (target.Components.Responses == null)
106+
if (_target.Components.Responses == null)
99107
{
100-
target.Components.Responses = new Dictionary<string, OpenApiResponse>();
108+
_target.Components.Responses = new Dictionary<string, OpenApiResponse>();
101109
}
102110
}
103111
}

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -20,8 +20,6 @@ public static class OpenApiFilterService
2020
/// <returns>A predicate.</returns>
2121
public static Func<OpenApiOperation, bool> CreatePredicate(string operationIds)
2222
{
23-
string predicateSource = null;
24-
2523
Func<OpenApiOperation, bool> predicate;
2624
if (operationIds != null)
2725
{
@@ -34,8 +32,6 @@ public static Func<OpenApiOperation, bool> CreatePredicate(string operationIds)
3432
var operationIdsArray = operationIds.Split(',');
3533
predicate = (o) => operationIdsArray.Contains(o.OperationId);
3634
}
37-
38-
predicateSource = $"operationIds: {operationIds}";
3935
}
4036

4137
else

0 commit comments

Comments
 (0)