Skip to content

Fix Swagger sort key fallback for empty endpoint tags metadata - #4125

Merged
martincostello merged 1 commit into
domaindrivendev:masterfrom
AleksaMCode:fix/4124-empty-tags-swagger-crash
Aug 25, 2026
Merged

martincostello merged 1 commit into
domaindrivendev:masterfrom
AleksaMCode:fix/4124-empty-tags-swagger-crash

Conversation

@AleksaMCode

Copy link
Copy Markdown
Contributor

Fixes Swagger generation failure when endpoint tags metadata is empty (for example WithTags() with no values or [Tags()]), which currently throws InvalidOperationException: Sequence contains no elements from the default sort key selector.

The issue or feature being addressed

Fixes #4124

Details on the issue fix or feature implementation

  • Updated the default sort key selection in SwaggerGeneratorOptions to handle empty tags safely.
  • Kept existing behavior for normal cases: when tags exist, the first tag is still used as the sort key.
  • Added fallback chain for empty-tag scenarios:
    1. first tag (if present)
    2. ApiDescription.RelativePath
    3. ApiDescription.ActionDescriptor?.DisplayName
    4. empty string
  • Added a test in SwaggerGeneratorTests: GetSwagger_DoesNotThrow_WhenTagsMetadataIsEmpty

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.21%. Comparing base (eedf135) to head (09d555b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4125   +/-   ##
=======================================
  Coverage   95.21%   95.21%           
=======================================
  Files         111      111           
  Lines        4115     4118    +3     
  Branches      843      844    +1     
=======================================
+ Hits         3918     3921    +3     
  Misses        197      197           
Flag Coverage Δ
Linux 95.21% <100.00%> (+<0.01%) ⬆️
Windows 95.21% <100.00%> (+<0.01%) ⬆️
macOS 95.21% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@martincostello martincostello left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@martincostello martincostello added this to the v10.2.4 milestone Aug 25, 2026
@martincostello
martincostello merged commit 0b99b04 into domaindrivendev:master Aug 25, 2026
14 checks passed
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution @AleksaMCode - the changes from this pull request have been published as part of version 10.3.0 📦, which is now available from NuGet.org 🚀

This was referenced Oct 7, 2026
This was referenced Oct 11, 2026
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]: Swagger generation fails with empty endpoint tags metadata (WithTags()/[Tags()])

2 participants