ProducesResponseTypeAttribute is the only direct concrete implementation of IFilterMetadata #5251
Description
Another nitpicky issue from your friendly neighborhood nitpicker.
The two following interfaces are not derived from IFilterMetadata
:
IApiRequestMetadataProvider
- Places that look for it in the action's filters:
DefaultApiDescriptionProvider
- Classes that implement it:
ConsumesAttribute
- Places that look for it in the action's filters:
IApiResponseMetadataProvider
- Places that look for it in the action's filters:
DefaultApiDescriptionProvider
FormatFilter
- Classes that implement it:
ProducesAttribute
ProducesResponseTypeAttribute
- Places that look for it in the action's filters:
Because of this, ProducesResponseTypeAttribute
is the only direct concrete implementation of IFilterMetadata
.
Now it's clear that the concept of 'filters' is overloaded to the effect that a 'filter' doesn't have to do anything, and it can instead just supply some kind of token to influence behavior or provide some kind of metadata. There are several examples of such interfaces deriving from IFilterMetadata
:
IFormatFilter
FormatFilter
IAllowAnonymousFilter
AllowAnonymousFilter
IAntiForgeryPolicy
IgnoreAntiForgeryTokenAttribute
ValidateAntiForgeryTokenAuthorizationFilter
AutoValidateAntiForgeryTokenAuthorizationFilter
Furthermore, we see several out-of-the-box examples demonstrating that implementations of IFilterMetadata
do not strictly have to be attributes.
Considering that, I think that IApiRequestMetadataProvider
and IApiResponseMetadataProvider
should derive from IFilterMetadata
in order to:
- Be consistent with other interfaces in how they are retrieved from actions' filter collections, and
- Have all out-of-the-box implementations of
IFilterMetadata
such asProducesResponseTypeAttribute
implementIFilterMetadata
via a more specialized, purposeful interface rather than directly.