Skip to content

Commit 1553a0c

Browse files
committed
Code refactoring
1 parent 849d841 commit 1553a0c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/Microsoft.OpenApi.Tool/OpenApiService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ public static void ProcessOpenApiDocument(
4545
document = result.OpenApiDocument;
4646

4747
// Check if filter options are provided, then execute
48-
if (!string.IsNullOrEmpty(filterbyOperationIds) || !string.IsNullOrEmpty(filterByTags))
48+
if (!string.IsNullOrEmpty(filterbyOperationIds))
4949
{
50-
var predicate = OpenApiFilterService.CreatePredicate(filterbyOperationIds, filterByTags);
50+
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterbyOperationIds);
51+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
52+
}
53+
if (!string.IsNullOrEmpty(filterByTags))
54+
{
55+
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
5156
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
5257
}
5358

src/Microsoft.OpenApi.Tool/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ static async Task<int> Main(string[] args)
2626
new Option("--format", "File format",typeof(OpenApiFormat) ),
2727
new Option("--inline", "Inline $ref instances", typeof(bool) ),
2828
new Option("--resolveExternal","Resolve external $refs", typeof(bool)),
29-
new Option("--filterByOperationId", "Filters OpenApiDocument by OperationId provided", typeof(string)),
30-
new Option("--filterByTag", "Filters OpenApiDocument by Tag(s) provided", typeof(string))
29+
new Option("--filterByOperationIds", "Filters OpenApiDocument by OperationId provided", typeof(string)),
30+
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string))
3131
};
3232
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, string, string, bool, bool>(
3333
OpenApiService.ProcessOpenApiDocument);

test/Microsoft.OpenApi.Tests/Services/OpenApiFilterServiceTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public OpenApiFilterServiceTests()
2525
[InlineData("graphService.GetGraphService", null)]
2626
[InlineData(null, "users.user")]
2727
[InlineData(null, "applications.application")]
28+
[InlineData(null, "reports.Functions")]
2829
public void ReturnFilteredOpenApiDocumentBasedOnOperationIds(string operationIds, string tags)
2930
{
3031
// Act
@@ -47,8 +48,8 @@ public void ReturnFilteredOpenApiDocumentBasedOnOperationIds(string operationIds
4748
public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidOperationIdIsSpecified()
4849
{
4950
// Act and Assert
50-
var message = Assert.Throws<InvalidOperationException>(() =>OpenApiFilterService.CreatePredicate(null)).Message;
51-
Assert.Equal("OperationId needs to be specified.", message);
51+
var message = Assert.Throws<InvalidOperationException>(() =>OpenApiFilterService.CreatePredicate(null, null)).Message;
52+
Assert.Equal("Either operationId(s) or tag(s) need to be specified.", message);
5253
}
5354
}
5455
}

0 commit comments

Comments
 (0)