Skip to content

Refactor filter descriptor type checks in SwaggerGen#3125

Merged
martincostello merged 5 commits into
domaindrivendev:masterfrom
iskandersierra:fix/public-api-issue
Nov 4, 2024
Merged

Refactor filter descriptor type checks in SwaggerGen#3125
martincostello merged 5 commits into
domaindrivendev:masterfrom
iskandersierra:fix/public-api-issue

Conversation

@iskandersierra

Copy link
Copy Markdown
Contributor

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:

genOptions.OperationFilterDescriptors.Add(new FilterDescriptor
{
    // Type = typeof(TdpHeaderParameter),
    FilterInstance = new TdpHeaderParameter(IRequestContext.UserIdKey, "The user ID."),
});

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:

genOptions.AddOperationFilterInstance(
    new TdpHeaderParameter(IRequestContext.TenantIdKey, "The tenant ID."));

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

NOTE: I didn't create a specific issue

Details on the issue fix or feature implementation

I added an alternative validation on the filter type for when the FilterInstance is set but not the Type of the FilterDescriptor.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants