Skip to content

Commit 4d52b67

Browse files
committed
Remove BindingSource.PathOrQuery
1 parent f6c008b commit 4d52b67

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/Mvc/Mvc.Abstractions/src/ModelBinding/BindingSource.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ public class BindingSource : IEquatable<BindingSource?>
7878
isGreedy: false,
7979
isFromRequest: true);
8080

81-
/// <summary>
82-
/// A <see cref="BindingSource"/> for the request url path or query string.
83-
/// </summary>
84-
public static readonly BindingSource PathOrQuery = new BindingSource(
85-
"PathOrQuery",
86-
"PathOrQuery",
87-
isGreedy: false,
88-
isFromRequest: true);
89-
9081
/// <summary>
9182
/// A <see cref="BindingSource"/> for request services.
9283
/// </summary>

src/Mvc/Mvc.Abstractions/src/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ abstract Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.TemplateHint.get ->
102102
static Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptorExtensions.GetProperty<T>(this Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor! actionDescriptor) -> T?
103103
static Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult.Success(object? model) -> Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult!
104104
static Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult.SuccessAsync(object? model) -> System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.Formatters.InputFormatterResult!>!
105-
static readonly Microsoft.AspNetCore.Mvc.ModelBinding.BindingSource.PathOrQuery -> Microsoft.AspNetCore.Mvc.ModelBinding.BindingSource!
106105
virtual Microsoft.AspNetCore.Mvc.Filters.ActionExecutedContext.Result.get -> Microsoft.AspNetCore.Mvc.IActionResult?
107106
virtual Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext.ActionArguments.get -> System.Collections.Generic.IDictionary<string!, object?>!
108107
virtual Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.BoundConstructorInvoker.get -> System.Func<object?[]!, object!>?

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal class EndpointMethodInfoApiDescriptionProvider : IApiDescriptionProvide
2121
private readonly EndpointDataSource _endpointDataSource;
2222

2323
// Executes before MVC's DefaultApiDescriptionProvider and GrpcHttpApiDescriptionProvider
24+
// REVIEW: Does order matter here? Should this run after MVC?
2425
public int Order => -1100;
2526

2627
public EndpointMethodInfoApiDescriptionProvider(EndpointDataSource endpointDataSource)
@@ -71,7 +72,7 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
7172

7273
foreach (var parameter in actionMethodInfo.GetParameters())
7374
{
74-
apiDescription.ParameterDescriptions.Add(CreateApiParameterDescription(parameter));
75+
apiDescription.ParameterDescriptions.Add(CreateApiParameterDescription(parameter, pattern));
7576
}
7677

7778
var responseType = actionMethodInfo.ReturnType;
@@ -91,11 +92,11 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
9192
return apiDescription;
9293
}
9394

94-
private static ApiParameterDescription CreateApiParameterDescription(ParameterInfo parameter)
95+
private static ApiParameterDescription CreateApiParameterDescription(ParameterInfo parameter, RoutePattern pattern)
9596
{
9697
var parameterType = parameter.ParameterType;
9798

98-
var (source, name) = GetBindingSourceAndName(parameter);
99+
var (source, name) = GetBindingSourceAndName(parameter, pattern);
99100

100101
return new ApiParameterDescription
101102
{
@@ -108,7 +109,7 @@ private static ApiParameterDescription CreateApiParameterDescription(ParameterIn
108109

109110
// TODO: Share more of this logic with RequestDelegateFactory.CreateArgument(...) using RequestDelegateFactoryUtilities
110111
// which is shared source.
111-
private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo parameter)
112+
private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo parameter, RoutePattern pattern)
112113
{
113114
var attributes = parameter.GetCustomAttributes();
114115

@@ -137,9 +138,15 @@ private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo par
137138
}
138139
else if (parameter.ParameterType == typeof(string) || RequestDelegateFactoryUtilities.HasTryParseMethod(parameter))
139140
{
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+
}
143150
}
144151
else
145152
{

0 commit comments

Comments
 (0)