Fix handling of duplicate enum values for dictionaries#3839
Fix handling of duplicate enum values for dictionaries#3839martincostello merged 2 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a Swagger schema generation regression when dictionary keys are enums that contain multiple named members with the same underlying value (enum aliases), preventing ArgumentException during ToDictionary key materialization.
Changes:
- Deduplicate serialized enum key representations via
Distinct()when building known dictionary keys inJsonSerializerDataContractResolver. - Add a regression test covering dictionary schema generation for enums with duplicate underlying values.
- Add a new test fixture enum that includes duplicate underlying values (alias member).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Swashbuckle.AspNetCore.TestSupport/Fixtures/Enums.cs | Adds an enum fixture with aliased/duplicate underlying values for regression coverage. |
| test/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.cs | Adds a regression test asserting duplicate enum values don’t break dictionary schema generation. |
| src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/JsonSerializerDataContractResolver.cs | Applies Distinct() to enum key JSON values to avoid duplicate dictionary keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3839 +/- ##
==========================================
+ Coverage 94.67% 94.95% +0.28%
==========================================
Files 111 111
Lines 3868 3886 +18
Branches 780 783 +3
==========================================
+ Hits 3662 3690 +28
+ Misses 206 196 -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:
|
Pull Request
The issue or feature being addressed
Resolves #2956.
Details on the issue fix or feature implementation
Add
Distinct()to remove repeated declarations of the same enum values to avoidArgumentException.Supersedes #3742.