-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix exception sorting operation tags #3652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix `SwaggerGeneratorException` caused by an `InvalidOperationException` when attempting to compare `OpenApiTagReference` instances in a `SortedSet<T>`. Resolves #3650.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a SwaggerGeneratorException caused by attempting to sort OpenApiTagReference instances in a SortedSet<T> without providing a proper comparer, which previously resulted in an InvalidOperationException.
- Introduces a new
OpenApiTagComparerclass to enable sorting ofOpenApiTagandOpenApiTagReferenceinstances - Updates
AnnotationsOperationFilterandAnnotationsDocumentFilterto use the new comparer when creatingSortedSetcollections - Updates test fixtures to reflect that tags are now sorted alphabetically
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/OpenApiTagComparer.cs | New comparer implementation for OpenApiTag and OpenApiTagReference with case-sensitive alphabetical sorting |
| src/Swashbuckle.AspNetCore.Annotations/AnnotationsOperationFilter.cs | Added comparer parameter to SortedSet<OpenApiTagReference> instantiation |
| src/Swashbuckle.AspNetCore.Annotations/AnnotationsDocumentFilter.cs | Added comparer parameter to SortedSet<OpenApiTag> instantiation |
| src/Swashbuckle.AspNetCore.Annotations/Swashbuckle.AspNetCore.Annotations.csproj | Linked the shared OpenApiTagComparer.cs file into the project |
| test/Swashbuckle.AspNetCore.Annotations.Test/Fixtures/FakeControllerWithSwaggerAnnotations.cs | Updated test fixture from single tag "foobar" to two tags ["foo", "bar"] |
| test/Swashbuckle.AspNetCore.Annotations.Test/AnnotationsOperationFilterTests.cs | Updated assertion to expect sorted tags ["bar", "foo"] |
Comments suppressed due to low confidence (1)
src/Shared/OpenApiTagComparer.cs:130
string value = obj?.Name ?? obj.Reference.Id;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3652 +/- ##
==========================================
- Coverage 94.75% 94.53% -0.23%
==========================================
Files 110 111 +1
Lines 3834 3861 +27
Branches 764 778 +14
==========================================
+ Hits 3633 3650 +17
- Misses 201 211 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Remove double calls to `ReferenceEquals()`.
Add missing `?` usage.
Fix
SwaggerGeneratorExceptioncaused by anInvalidOperationExceptionwhen attempting to compareOpenApiTagReferenceinstances in aSortedSet<T>.Resolves #3650.