Fix case-insensitive group name matching in OpenAPI document filtering #64353
+27
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix case-insensitive comparison for endpoint group names
Description
OpenAPI document filtering excluded endpoints when
.WithGroupName()casing differed from.AddOpenApi()document name. Since document names are lowercased but endpoint metadata preserves original casing, case-sensitive comparison caused exclusion.Changes:
ShouldIncludepredicate inOpenApiOptionsto useStringComparison.OrdinalIgnoreCaseFixes #64335
Original prompt
This section details on the original issue you should resolve
<issue_title>OpenAPI Generation No Longer Groups Endpoints Using WithGroupName</issue_title>
<issue_description>### Is there an existing issue for this?
Describe the bug
In .NET 9, multiple Open API spec docs could be generated with a specific name utilizing the
.WithGroupNameextension method on either the group itself or particular endpoints. This allowed for a name other than the group's prefix to be used for grouping endpoints into an OpenAPI document that utilized a name other than the group's route prefix.Now, it seems that the OpenAPI generator does not group those endpoints into the related spec document and instead excludes them entirely.
Expected Behavior
I should be able to group endpoints in an OpenAPI Spec document named something other than the Group prefix, utilizing
.WithGroupName("MyGroupName")and.AddOpenApi("MyGroupName").Steps To Reproduce
I have a minimal repro solution that demonstrates the behaviors here:
https://github.com/GoValidate/AspNetCore-Net10-OpenApi-Repro
The OpenApiNet9 and OpenApiNet10 are carbon copies of each other, with one targeting .NET 9 (and the .NET 9 version of AspNetCore OpenAPI) and the other targeting .NET 10 (and the .NET 10 version of AspNetCore OpenAPI). The code in both cases is the same:
New NET 10 Behavior
The following Open API docs are generated in NET 10:
https://localhost:5001/openapi/FirstGroup.json{ "openapi": "3.1.1", "info": { "title": "OpenApiNet10 | firstgroup", "version": "1.0.0" }, "servers": [ { "url": "https://localhost:5001/" } ], "paths": { } }https://localhost:5001/openapi/SecondGroup.json{ "openapi": "3.1.1", "info": { "title": "OpenApiNet10 | secondgroup", "version": "1.0.0" }, "servers": [ { "url": "https://localhost:5001/" } ], "paths": { } }Expected Behavior
In OpenApiNet9, the following swagger docs are generated:
https://localhost:7001/openapi/FirstGroup.json{ "openapi": "3.0.1", "info": { "title": "OpenApiNet9 | FirstGroup", "version": "1.0.0" }, "servers": [ { "url": "https://localhost:7001/" } ], "paths": { "/first-group/explicit": { "get": { "tags": [ "OpenApiNet9" ], "responses": { "200": { "description": "OK", "content": { "text/plain": { "schema": { "type": "string" } } } } } } } }, "components": { }, "tags": [ { "name": "OpenApiNet9" } ] }https://localhost:7001/openapi/SecondGroup.json{ "openapi": "3.0.1", "info": { "title": "OpenApiNet9 | SecondGroup", "version": "1.0.0" }, "servers": [ { "url": "https://localhost:7001/" } ], "paths": { "/second-group/implicit": { "get": { "tags": [ "OpenApiNet9" ], "responses": { "200": { "description": "OK", "content": { "text/plain": { "schema": { "type": "string" } } } } } } } }, "components": { }, "tags": [ { "name": "OpenApiNet9" } ] }Exceptions (if any)
No response
.NET Version
10.0.100
Anything else?
IDE is Rider (though this exhibits with
dotnet run).Output from
dotnet --info