Skip to content

Commit 4dc0f64

Browse files
Fix case-insensitive group name matching in OpenAPI document filtering (#64353)
* Initial plan * Fix case-insensitive group name matching in OpenAPI Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
1 parent 9de03d5 commit 4dc0f64

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/OpenApi/src/Services/OpenApiOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class OpenApiOptions
2929
/// </summary>
3030
public OpenApiOptions()
3131
{
32-
ShouldInclude = (description) => description.GroupName == null || description.GroupName == DocumentName;
32+
ShouldInclude = (description) => description.GroupName == null || string.Equals(description.GroupName, DocumentName, StringComparison.OrdinalIgnoreCase);
3333
}
3434

3535
/// <summary>

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.Paths.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Net.Http;
55
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.OpenApi;
67
using Microsoft.AspNetCore.Routing;
78

89
public partial class OpenApiDocumentServiceTests : OpenApiDocumentServiceTestBase
@@ -67,6 +68,31 @@ await VerifyOpenApiDocument(builder, document =>
6768
});
6869
}
6970

71+
[Fact]
72+
public async Task GetOpenApiPaths_RespectsShouldInclude_CaseInsensitive()
73+
{
74+
// Arrange
75+
var builder = CreateBuilder();
76+
var openApiOptions = new OpenApiOptions { DocumentName = "firstgroup" };
77+
78+
// Act
79+
builder.MapGet("/api/todos", () => { }).WithMetadata(new EndpointGroupNameAttribute("FirstGroup"));
80+
builder.MapGet("/api/users", () => { }).WithMetadata(new EndpointGroupNameAttribute("SecondGroup"));
81+
82+
// Assert -- The default `ShouldInclude` implementation should include endpoints that
83+
// match the document name case-insensitively. The document name is "firstgroup" (lowercase)
84+
// but the endpoint group name is "FirstGroup" (mixed case), and it should still match.
85+
await VerifyOpenApiDocument(builder, openApiOptions, document =>
86+
{
87+
Assert.Collection(document.Paths.OrderBy(p => p.Key),
88+
path =>
89+
{
90+
Assert.Equal("/api/todos", path.Key);
91+
}
92+
);
93+
});
94+
}
95+
7096
[Fact]
7197
public async Task GetOpenApiPaths_RespectsSamePaths()
7298
{

0 commit comments

Comments
 (0)