Skip to content

Commit d4451e9

Browse files
committed
Merge remote-tracking branch 'origin/vnext' into mk/add-filter-by-tags
2 parents f33d1f6 + 9f46c00 commit d4451e9

File tree

7 files changed

+69
-37
lines changed

7 files changed

+69
-37
lines changed

src/Microsoft.OpenApi.Tool/OpenApiService.cs

Lines changed: 13 additions & 13 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;
@@ -28,22 +28,28 @@ public static void ProcessOpenApiDocument(
2828
bool inline,
2929
bool resolveExternal)
3030
{
31-
if (input == null)
31+
if (string.IsNullOrEmpty(input))
3232
{
33-
throw new ArgumentNullException("input");
33+
throw new ArgumentNullException(nameof(input));
34+
}
35+
if(output == null)
36+
{
37+
throw new ArgumentException(nameof(output));
38+
}
39+
if (output.Exists)
40+
{
41+
throw new IOException("The file you're writing to already exists. Please input a new output path.");
3442
}
3543

3644
var stream = GetStream(input);
37-
38-
OpenApiDocument document;
39-
4045
var result = new OpenApiStreamReader(new OpenApiReaderSettings
4146
{
4247
ReferenceResolution = resolveExternal ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
4348
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
4449
}
4550
).ReadAsync(stream).GetAwaiter().GetResult();
4651

52+
OpenApiDocument document;
4753
document = result.OpenApiDocument;
4854

4955
// Check if filter options are provided, then execute
@@ -65,7 +71,7 @@ public static void ProcessOpenApiDocument(
6571

6672
var context = result.OpenApiDiagnostic;
6773

68-
if (context.Errors.Count != 0)
74+
if (context.Errors.Count > 0)
6975
{
7076
var errorReport = new StringBuilder();
7177

@@ -77,11 +83,6 @@ public static void ProcessOpenApiDocument(
7783
throw new ArgumentException(string.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
7884
}
7985

80-
if (output.Exists)
81-
{
82-
throw new IOException("The file you're writing to already exists.Please input a new output path.");
83-
}
84-
8586
using var outputStream = output?.Create();
8687

8788
var textWriter = outputStream != null ? new StreamWriter(outputStream) : Console.Out;
@@ -137,7 +138,6 @@ internal static void ValidateOpenApiDocument(string input)
137138

138139
document = new OpenApiStreamReader(new OpenApiReaderSettings
139140
{
140-
//ReferenceResolution = resolveExternal == true ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
141141
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
142142
}
143143
).Read(stream, out var context);

src/Microsoft.OpenApi/Services/CopyReferences.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
using System.Collections.Generic;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Collections.Generic;
25
using Microsoft.OpenApi.Interfaces;
36
using Microsoft.OpenApi.Models;
47

58
namespace Microsoft.OpenApi.Services
69
{
710
internal class CopyReferences : OpenApiVisitorBase
811
{
9-
private readonly OpenApiDocument target;
10-
public OpenApiComponents Components = new OpenApiComponents();
12+
private readonly OpenApiDocument _target;
13+
public OpenApiComponents Components = new();
1114

1215
public CopyReferences(OpenApiDocument target)
1316
{
14-
this.target = target;
17+
_target = target;
1518
}
1619

20+
/// <summary>
21+
/// Visits IOpenApiReferenceable instances that are references and not in components.
22+
/// </summary>
23+
/// <param name="referenceable"> An IOpenApiReferenceable object.</param>
1724
public override void Visit(IOpenApiReferenceable referenceable)
1825
{
1926
switch (referenceable)
@@ -51,6 +58,10 @@ public override void Visit(IOpenApiReferenceable referenceable)
5158
base.Visit(referenceable);
5259
}
5360

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

6980
private void EnsureComponentsExists()
7081
{
71-
if (target.Components == null)
82+
if (_target.Components == null)
7283
{
73-
target.Components = new OpenApiComponents();
84+
_target.Components = new OpenApiComponents();
7485
}
7586
}
7687

7788
private void EnsureSchemasExists()
7889
{
79-
if (target.Components.Schemas == null)
90+
if (_target.Components.Schemas == null)
8091
{
81-
target.Components.Schemas = new Dictionary<string, OpenApiSchema>();
92+
_target.Components.Schemas = new Dictionary<string, OpenApiSchema>();
8293
}
8394
}
8495

8596
private void EnsureParametersExists()
8697
{
87-
if (target.Components.Parameters == null)
98+
if (_target.Components.Parameters == null)
8899
{
89-
target.Components.Parameters = new Dictionary<string, OpenApiParameter>();
100+
_target.Components.Parameters = new Dictionary<string, OpenApiParameter>();
90101
}
91102
}
92103

93104
private void EnsureResponsesExists()
94105
{
95-
if (target.Components.Responses == null)
106+
if (_target.Components.Responses == null)
96107
{
97-
target.Components.Responses = new Dictionary<string, OpenApiResponse>();
108+
_target.Components.Responses = new Dictionary<string, OpenApiResponse>();
98109
}
99110
}
100111
}

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public static class OpenApiFilterService
2222
/// <returns>A predicate.</returns>
2323
public static Func<OpenApiOperation, bool> CreatePredicate(string operationIds = null, string tags = null)
2424
{
25-
string predicateSource = null;
26-
2725
Func<OpenApiOperation, bool> predicate;
2826
if (operationIds != null)
2927
{
@@ -36,8 +34,6 @@ public static Func<OpenApiOperation, bool> CreatePredicate(string operationIds =
3634
var operationIdsArray = operationIds.Split(',');
3735
predicate = (o) => operationIdsArray.Contains(o.OperationId);
3836
}
39-
40-
predicateSource = $"operationIds: {operationIds}";
4137
}
4238
else if (tags != null)
4339
{
@@ -77,8 +73,13 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun
7773
{
7874
Info = new OpenApiInfo()
7975
{
80-
Title = source.Info.Title + " - subset",
81-
Version = source.Info.Version
76+
Title = source.Info.Title + " - Subset",
77+
Description = source.Info.Description,
78+
TermsOfService = source.Info.TermsOfService,
79+
Contact = source.Info.Contact,
80+
License = source.Info.License,
81+
Version = source.Info.Version,
82+
Extensions = source.Info.Extensions
8283
},
8384

8485
Components = new OpenApiComponents()
@@ -92,7 +93,7 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun
9293
foreach (var result in results)
9394
{
9495
OpenApiPathItem pathItem;
95-
string pathKey = result.CurrentKeys.Path;
96+
var pathKey = result.CurrentKeys.Path;
9697

9798
if (subset.Paths == null)
9899
{

src/Microsoft.OpenApi/Services/OperationSearch.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@
88

99
namespace Microsoft.OpenApi.Services
1010
{
11+
/// <summary>
12+
/// Visits OpenApi operations and parameters.
13+
/// </summary>
1114
public class OperationSearch : OpenApiVisitorBase
1215
{
1316
private readonly Func<OpenApiOperation, bool> _predicate;
1417
private readonly List<SearchResult> _searchResults = new();
1518

19+
/// <summary>
20+
/// A list of operations from the operation search.
21+
/// </summary>
1622
public IList<SearchResult> SearchResults => _searchResults;
1723

24+
/// <summary>
25+
/// The OperationSearch constructor.
26+
/// </summary>
27+
/// <param name="predicate">A predicate function.</param>
1828
public OperationSearch(Func<OpenApiOperation, bool> predicate)
1929
{
2030
_predicate = predicate ?? throw new ArgumentNullException(nameof(predicate));

src/Microsoft.OpenApi/Services/SearchResult.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55

66
namespace Microsoft.OpenApi.Services
77
{
8+
/// <summary>
9+
/// Defines a search result model for visited operations.
10+
/// </summary>
811
public class SearchResult
912
{
13+
/// <summary>
14+
/// An object containing contextual information based on where the walker is currently referencing in an OpenApiDocument.
15+
/// </summary>
1016
public CurrentKeys CurrentKeys { get; set; }
17+
18+
/// <summary>
19+
/// An Operation object.
20+
/// </summary>
1121
public OpenApiOperation Operation { get; set; }
1222
}
1323
}

test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void PathParameterNotInThePathShouldReturnAnError()
218218
}
219219

220220
[Fact]
221-
public void PathParameterInThePastShouldBeOk()
221+
public void PathParameterInThePathShouldBeOk()
222222
{
223223
// Arrange
224224
IEnumerable<OpenApiError> errors;

test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs

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

44
using System;
55
using System.Collections.Generic;
@@ -12,7 +12,7 @@
1212

1313
namespace Microsoft.OpenApi.Tests
1414
{
15-
15+
1616
public class OpenApiWorkspaceTests
1717
{
1818
[Fact]
@@ -61,7 +61,7 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther()
6161
}
6262
}
6363
}
64-
}
64+
}
6565
}
6666
});
6767
workspace.AddDocument("common", new OpenApiDocument() {
@@ -111,7 +111,7 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther_short()
111111
re.CreateContent("application/json", co =>
112112
co.Schema = new OpenApiSchema()
113113
{
114-
Reference = new OpenApiReference() // Reference
114+
Reference = new OpenApiReference() // Reference
115115
{
116116
Id = "test",
117117
Type = ReferenceType.Schema,

0 commit comments

Comments
 (0)