-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Allow endpoint filter factories to manipulate endpoint metadata #41722
Copy link
Copy link
Closed
Labels
DocsThis issue tracks updating documentationThis issue tracks updating documentationapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Metadata
Metadata
Assignees
Labels
DocsThis issue tracks updating documentationThis issue tracks updating documentationapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Type
Fields
Give feedbackNo fields configured for issues without a type.
When adding endpoint filters via a filter factory delegate, it would sometimes be useful to be able to manipulate the endpoint's metadata too, in the case where the filter will impact the effective endpoint operation.
For example, below shows a rudimentary XML formatting filter that adds the ability for an endpoint to format its response as XML if the client supports it, instead of the usual JSON. This filter should be able to update the endpoint metadata to indicate that it can now return XML as well, so that it's described as such in
ApiExplorerand OpenAPI/Swagger.The suggested API diff:
namespace Microsoft.AspNetCore.Http; public sealed class RouteHandlerContext { - public RouteHandlerContext(MethodInfo methodInfo, EndpointMetadataCollection endpointMetadata, IServiceProvider applicationServices); + public RouteHandlerContext(MethodInfo methodInfo, IList<object> endpointMetadata, IServiceProvider applicationServices); - public EndpointMetadataCollection EndpointMetadata { get; } + public IList<object> EndpointMetadata { get; } }Ordering considerations
Imagine the above example is extended so that other methods on the
IEndpointConventionBuilderare called that also manipulate endpoint metadata, e.g.:What is the order of operations WRT to the buildup of the endpoint metadata collection?
Will the filter factory delegate see:
EndpointNameAttribute("GetTodos"), TagsAttribute("FirstTag")), and not that for the methods declared after it; orIdeally I think, it would see the endpoint metadata added by any methods declared before it in the endpoint builder (point 1), along with any metadata added by
RequestDelegateFactoryit self for the endpoint delegate.