@@ -21,6 +21,7 @@ internal class EndpointMethodInfoApiDescriptionProvider : IApiDescriptionProvide
21
21
private readonly EndpointDataSource _endpointDataSource ;
22
22
23
23
// Executes before MVC's DefaultApiDescriptionProvider and GrpcHttpApiDescriptionProvider
24
+ // REVIEW: Does order matter here? Should this run after MVC?
24
25
public int Order => - 1100 ;
25
26
26
27
public EndpointMethodInfoApiDescriptionProvider ( EndpointDataSource endpointDataSource )
@@ -71,7 +72,7 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
71
72
72
73
foreach ( var parameter in actionMethodInfo . GetParameters ( ) )
73
74
{
74
- apiDescription . ParameterDescriptions . Add ( CreateApiParameterDescription ( parameter ) ) ;
75
+ apiDescription . ParameterDescriptions . Add ( CreateApiParameterDescription ( parameter , pattern ) ) ;
75
76
}
76
77
77
78
var responseType = actionMethodInfo . ReturnType ;
@@ -91,11 +92,11 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
91
92
return apiDescription ;
92
93
}
93
94
94
- private static ApiParameterDescription CreateApiParameterDescription ( ParameterInfo parameter )
95
+ private static ApiParameterDescription CreateApiParameterDescription ( ParameterInfo parameter , RoutePattern pattern )
95
96
{
96
97
var parameterType = parameter . ParameterType ;
97
98
98
- var ( source , name ) = GetBindingSourceAndName ( parameter ) ;
99
+ var ( source , name ) = GetBindingSourceAndName ( parameter , pattern ) ;
99
100
100
101
return new ApiParameterDescription
101
102
{
@@ -108,7 +109,7 @@ private static ApiParameterDescription CreateApiParameterDescription(ParameterIn
108
109
109
110
// TODO: Share more of this logic with RequestDelegateFactory.CreateArgument(...) using RequestDelegateFactoryUtilities
110
111
// which is shared source.
111
- private static ( BindingSource , string ) GetBindingSourceAndName ( ParameterInfo parameter )
112
+ private static ( BindingSource , string ) GetBindingSourceAndName ( ParameterInfo parameter , RoutePattern pattern )
112
113
{
113
114
var attributes = parameter . GetCustomAttributes ( ) ;
114
115
@@ -137,9 +138,15 @@ private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo par
137
138
}
138
139
else if ( parameter . ParameterType == typeof ( string ) || RequestDelegateFactoryUtilities . HasTryParseMethod ( parameter ) )
139
140
{
140
- // TODO: Look at the pattern and infer whether it's really the path or query.
141
- // This cannot be done by RequestDelegateFactory currently because of the layering, but could be done here.
142
- return ( BindingSource . PathOrQuery , parameter . Name ?? string . Empty ) ;
141
+ // Path vs query cannot be determined by RequestDelegateFactory at startup currently because of the layering, but can be done here.
142
+ if ( parameter . Name is { } name && pattern . GetParameter ( name ) is not null )
143
+ {
144
+ return ( BindingSource . Path , name ) ;
145
+ }
146
+ else
147
+ {
148
+ return ( BindingSource . Query , parameter . Name ?? string . Empty ) ;
149
+ }
143
150
}
144
151
else
145
152
{
0 commit comments