Skip to content

Commit 6acf634

Browse files
committed
Add validation check and add test
1 parent c900208 commit 6acf634

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public static class OpenApiFilterService
2323
public static Func<OpenApiOperation, bool> CreatePredicate(string operationIds = null, string tags = null)
2424
{
2525
Func<OpenApiOperation, bool> predicate;
26+
if (!string.IsNullOrEmpty(operationIds) && !string.IsNullOrEmpty(tags))
27+
{
28+
throw new InvalidOperationException("Cannot specify both operationIds and tags at the same time.");
29+
}
2630
if (operationIds != null)
2731
{
2832
if (operationIds == "*")
@@ -49,7 +53,6 @@ public static Func<OpenApiOperation, bool> CreatePredicate(string operationIds =
4953
predicate = (o) => o.Tags.Any(t => tagsArray.Contains(t.Name));
5054
}
5155
}
52-
5356
else
5457
{
5558
throw new InvalidOperationException("Either operationId(s) or tag(s) need to be specified.");

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ public void ReturnFilteredOpenApiDocumentBasedOnOperationIdsAndTags(string opera
4646
public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidArgumentsArePassed()
4747
{
4848
// Act and Assert
49-
var message = Assert.Throws<InvalidOperationException>(() =>OpenApiFilterService.CreatePredicate(null, null)).Message;
50-
Assert.Equal("Either operationId(s) or tag(s) need to be specified.", message);
49+
var message1 = Assert.Throws<InvalidOperationException>(() => OpenApiFilterService.CreatePredicate(null, null)).Message;
50+
Assert.Equal("Either operationId(s) or tag(s) need to be specified.", message1);
51+
52+
var message2 = Assert.Throws<InvalidOperationException>(() => OpenApiFilterService.CreatePredicate("users.user.ListUser", "users.user")).Message;
53+
Assert.Equal("Cannot specify both operationIds and tags at the same time.", message2);
5154
}
5255
}
5356
}

0 commit comments

Comments
 (0)