Refactor filter descriptor type checks in SwaggerGen#3125
Merged
martincostello merged 5 commits intodomaindrivendev:masterfrom Nov 4, 2024
iskandersierra:fix/public-api-issue
Merged
Refactor filter descriptor type checks in SwaggerGen#3125martincostello merged 5 commits intodomaindrivendev:masterfrom iskandersierra:fix/public-api-issue
martincostello merged 5 commits intodomaindrivendev:masterfrom
iskandersierra:fix/public-api-issue
Conversation
Introduce `IsAssignableTo` method in `FilterDescriptor` class to check if `FilterInstance` is an instance of a specified type or if the `Type` property is assignable to the specified type. Update `ConfigureSwaggerGeneratorOptions.cs` to use this new method. Remove direct `Type` property assignments in `SwaggerGenOptionsExtensions.cs` for various filter descriptors.
iskandersierra
commented
Nov 2, 2024
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenOptionsExtensions.cs
Show resolved
Hide resolved
Collaborator
martincostello
left a comment
There was a problem hiding this comment.
Can you add a test that validates the NullReferenceException has gone away with the change?
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenOptionsExtensions.cs
Show resolved
Hide resolved
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/SwaggerGenOptions.cs
Outdated
Show resolved
Hide resolved
test/Swashbuckle.AspNetCore.SwaggerGen.Test/ConfigureSwaggerGeneratorOptionsTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Martin Costello <martin@martincostello.com>
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #3125 +/- ##
=======================================
Coverage 91.43% 91.44%
=======================================
Files 76 76
Lines 3119 3121 +2
Branches 519 520 +1
=======================================
+ Hits 2852 2854 +2
Misses 267 267
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
martincostello
approved these changes
Nov 4, 2024
This was referenced Jul 31, 2025
Bump Swashbuckle.AspNetCore from 5.6.3 to 9.0.0
timerknight/skills-secure-repository-supply-chain#17
Open
Open
This was referenced Feb 16, 2026
Closed
Open
Bump Swashbuckle.AspNetCore from 5.6.3 to 10.1.3
EltonCoura/skills-secure-repository-supply-chain#23
Open
Open
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request
Given that the public API allows to register a filter in this form without any specific validation on not assigning the Type property:
in which case, opening the swagger UI returns a
NullReferenceException(in developer error page) with no reference to user source code.Looking into the library source code, I found out that the "proper" way to do the registration is:
but I just felt that the first option should also be available with minimal behavior changes, given that it is a possible choice in the public API.
The issue or feature being addressed
Details on the issue fix or feature implementation
I added an alternative validation on the filter type for when the
FilterInstanceis set but not theTypeof theFilterDescriptor.