Skip to content

Commit 3c6ae93

Browse files
committed
Start of params
1 parent 1b1197f commit 3c6ae93

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Mvc/Mvc.ApiExplorer/src/EndpointMethodInfoApiDescriptionProvider.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using Microsoft.AspNetCore.Http;
77
using Microsoft.AspNetCore.Mvc.Abstractions;
8+
using Microsoft.AspNetCore.Mvc.ModelBinding;
89
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
910
using Microsoft.AspNetCore.Routing;
1011
using Microsoft.AspNetCore.Routing.Patterns;
@@ -32,6 +33,9 @@ public void OnProvidersExecuting(ApiDescriptionProviderContext context)
3233
&& routeEndpoint.Metadata.GetMetadata<MethodInfo>() is { } methodInfo
3334
&& routeEndpoint.Metadata.GetMetadata<IHttpMethodMetadata>() is { } httpMethodMetadata)
3435
{
36+
// REVIEW: Should we add an ApiDescription for endpoints without IHttpMethodMetadata? Swagger doesn't handle
37+
// a null HttpMethod even though it's nullable on ApiDescription, so we'd need to define "default" HTTP methods.
38+
// In practice, the Delegate will be called for any HTTP method if there is no IHttpMethodMetadata.
3539
foreach (var httpMethod in httpMethodMetadata.HttpMethods)
3640
{
3741
context.Results.Add(CreateApiDescription(routeEndpoint.RoutePattern, httpMethod, methodInfo));
@@ -62,6 +66,11 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
6266
},
6367
};
6468

69+
foreach (var parameter in actionMethodInfo.GetParameters())
70+
{
71+
apiDescription.ParameterDescriptions.Add(CreateApiParameterDescription(parameter));
72+
}
73+
6574
var responseType = actionMethodInfo.ReturnType;
6675

6776
if (AwaitableInfo.IsTypeAwaitable(responseType, out var awaitableInfo))
@@ -77,6 +86,19 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
7786
return apiDescription;
7887
}
7988

89+
private static ApiParameterDescription CreateApiParameterDescription(ParameterInfo parameterInfo)
90+
{
91+
var parameterType = parameterInfo.ParameterType;
92+
93+
return new ApiParameterDescription
94+
{
95+
Name = parameterInfo.Name ?? parameterType.Name,
96+
ModelMetadata = new EndpointMethodInfoModelMetadata(ModelMetadataIdentity.ForType(parameterType)),
97+
Source = BindingSource.Path,
98+
DefaultValue = parameterInfo.DefaultValue,
99+
};
100+
}
101+
80102
private static ApiResponseType? CreateApiResponseType(Type responseType)
81103
{
82104
if (typeof(IResult).IsAssignableFrom(responseType))

0 commit comments

Comments
 (0)