Closed captainsafia closed 1 month ago
[API Review]
ParameterInfo
or can we provide a subset of that info?IEnumerable<IParameterBindingMetadata>
(to which we might need to add IsOptional
)?Making updates to the proposal in response to the feedback that I received and some additional work in the area:
// Assembly: Microsoft.AspNetCore.Http.Abstractions
namespace Microsoft.AspNetCore.Http.Metadata;
+ public interface IParameterBindingMetadata
+ {
+ string Name { get; }
+ bool HasTryParse { get; }
+ bool HasBindAsync { get; }
+ bool IsOptional { get; }
+ ParameterInfo ParameterInfo { get; }
+ }
public interface IProducesResponseTypeMetadata
{
+ bool IsAwaitable { get; }
}
One open question from review was:
Do we need a full ParameterInfo or can we provide a subset of that info?
Although we only look at certain parts of the ParameterInfo (custom attributes to figure out the binding source, parameter name, type, etc.), ApiExplorer still requires that we encapsulate the ParameterInfo into the EndpointParameterDescriptor
object so we can't get away with totally removing references to it (ref).
Or, could it be IEnumerable
(to which we might need to add IsOptional)?
I opted to not make the metadata contain an IEnumerable
mostly to make unwrapping the collection a little bit easier.
var bindingMetadata = endpoint.Metadata.GetOrderedMetadata<IParameterBindingMetadata>();
// vs
var bindingMetadata = endpoint.Metadata.GetOrderedMetadata<SomeContainerType>().BindingMetadata;
[API Review]
HasTryParse
true?
true
indicates that Type
is an unwrapped typeTask
?
Task
and ValueTask
in RDG (but not in RDF)Seems promising, but let's try to get rid of IProducesResponseTypeMetadata.IsAwaitable
.
IParameterBindingMetadata
changes approved!
Background and Motivation
The
EndpointMetadataApiDescriptionProvider
is a an implementation ofIApiDescriptionProvider
that is used to generateApiDescription
instances for minimal APIs that can be used by consumers of ApiExplorer (likeMicrosoft.AspNetCore.OpenApi
) when generating descriptions of the API implementation.EndpointMetadataApiDescriptionProvider
currently relies on unbounded reflection in all scenarios (whether using minimal APIs with static code gen via RequestDelegateGenerator or dynamic code gen via RequestDelegateFactory) to resolve the following information:TryParse
method or implementsIParsable
BindAsync
[AsParameters]
attributeIt resolves this information using the existing APIs exposed in the
ParameterBindingCache
. The use of unbounded reflection in this class prevents us from making the entire OpenAPI pipeline trim friendly. To resolve this issue, we will introduce a new metadata type (IParameterBindingMetadata
) that will be inserted into endpoints by either RDG or RDF when the endpoints are compiled and used.Proposed API
Usage Examples
Alternative Designs
IParameterBindingMetadata
instance for each parameter, we could instead expose a single metadata item that allows lookup into a collection of instances using the parameter name as a key.Risks
ParameterBindingCache
for method resolution. If the parameter binding implementation for minimal APIs changes in the future, the shape of this API will have to be modified.