Skip to content

Conversation

@martincostello
Copy link
Collaborator

Fix SwaggerGeneratorException caused by an InvalidOperationException when attempting to compare OpenApiTagReference instances in a SortedSet<T>.

Resolves #3650.

Fix `SwaggerGeneratorException` caused by an `InvalidOperationException` when attempting to compare `OpenApiTagReference` instances in a `SortedSet<T>`.

Resolves #3650.
@martincostello martincostello added this to the v10.0.1 milestone Nov 12, 2025
Copilot AI review requested due to automatic review settings November 12, 2025 13:59
Copilot finished reviewing on behalf of martincostello November 12, 2025 14:01
Copy link

Copilot AI left a 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 OpenApiTagComparer class to enable sorting of OpenApiTag and OpenApiTagReference instances
  • Updates AnnotationsOperationFilter and AnnotationsDocumentFilter to use the new comparer when creating SortedSet collections
  • 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

  • Variable obj may be null at this access as suggested by this null check.
        string value = obj?.Name ?? obj.Reference.Id;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 65.51724% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.53%. Comparing base (5bb0e76) to head (1da893c).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Shared/OpenApiTagComparer.cs 62.96% 10 Missing ⚠️
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     
Flag Coverage Δ
Linux 94.53% <65.51%> (-0.23%) ⬇️
Windows 94.53% <65.51%> (-0.23%) ⬇️
macOS 94.53% <65.51%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Remove double calls to `ReferenceEquals()`.
Add missing `?` usage.
@martincostello martincostello merged commit 11db6ef into master Nov 12, 2025
12 of 14 checks passed
@martincostello martincostello deleted the gh-3650 branch November 12, 2025 14:20
This was referenced Nov 12, 2025
This was referenced Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SwaggerOperation.Tags

2 participants