5
5
using System . Reflection ;
6
6
using Microsoft . AspNetCore . Http ;
7
7
using Microsoft . AspNetCore . Mvc . Abstractions ;
8
+ using Microsoft . AspNetCore . Mvc . ModelBinding ;
8
9
using Microsoft . AspNetCore . Mvc . ModelBinding . Metadata ;
9
10
using Microsoft . AspNetCore . Routing ;
10
11
using Microsoft . AspNetCore . Routing . Patterns ;
@@ -32,6 +33,9 @@ public void OnProvidersExecuting(ApiDescriptionProviderContext context)
32
33
&& routeEndpoint . Metadata . GetMetadata < MethodInfo > ( ) is { } methodInfo
33
34
&& routeEndpoint . Metadata . GetMetadata < IHttpMethodMetadata > ( ) is { } httpMethodMetadata )
34
35
{
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.
35
39
foreach ( var httpMethod in httpMethodMetadata . HttpMethods )
36
40
{
37
41
context . Results . Add ( CreateApiDescription ( routeEndpoint . RoutePattern , httpMethod , methodInfo ) ) ;
@@ -62,6 +66,11 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
62
66
} ,
63
67
} ;
64
68
69
+ foreach ( var parameter in actionMethodInfo . GetParameters ( ) )
70
+ {
71
+ apiDescription . ParameterDescriptions . Add ( CreateApiParameterDescription ( parameter ) ) ;
72
+ }
73
+
65
74
var responseType = actionMethodInfo . ReturnType ;
66
75
67
76
if ( AwaitableInfo . IsTypeAwaitable ( responseType , out var awaitableInfo ) )
@@ -77,6 +86,19 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
77
86
return apiDescription ;
78
87
}
79
88
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
+
80
102
private static ApiResponseType ? CreateApiResponseType ( Type responseType )
81
103
{
82
104
if ( typeof ( IResult ) . IsAssignableFrom ( responseType ) )
0 commit comments