Skip to content

Commit a836f16

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Fix-up binding source only for ODataQueryOptions and ODataPath
1 parent 9747d6a commit a836f16

File tree

4 files changed

+27
-54
lines changed

4 files changed

+27
-54
lines changed

src/Microsoft.AspNetCore.OData.Versioning.ApiExplorer/AspNetCore.Mvc.ApiExplorer/ODataApiDescriptionProvider.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,17 +484,28 @@ void UpdateBindingInfo( ApiParameterContext context, ParameterDescriptor paramet
484484
Contract.Requires( parameter != null );
485485
Contract.Requires( metadata != null );
486486

487-
if ( parameter.BindingInfo != null )
487+
var parameterType = parameter.ParameterType;
488+
var bindingInfo = parameter.BindingInfo;
489+
490+
if ( bindingInfo != null )
488491
{
492+
if ( ( parameterType.IsODataQueryOptions() || parameterType.IsODataPath() ) && bindingInfo.BindingSource == Custom )
493+
{
494+
bindingInfo.BindingSource = Special;
495+
}
496+
489497
return;
490498
}
491499

492-
var bindingInfo = new BindingInfo() { BindingSource = metadata.BindingSource };
493-
494-
parameter.BindingInfo = bindingInfo;
500+
parameter.BindingInfo = bindingInfo = new BindingInfo() { BindingSource = metadata.BindingSource };
495501

496502
if ( bindingInfo.BindingSource != null )
497503
{
504+
if ( ( parameterType.IsODataQueryOptions() || parameterType.IsODataPath() ) && bindingInfo.BindingSource == Custom )
505+
{
506+
bindingInfo.BindingSource = Special;
507+
}
508+
498509
return;
499510
}
500511

src/Microsoft.AspNetCore.OData.Versioning/AspNet.OData/Routing/ODataRouteBindingInfoConvention.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public void Apply( ActionDescriptorProviderContext context, ControllerActionDesc
3737
Contract.Requires( context != null );
3838
Contract.Requires( action != null );
3939

40-
// any existing AttributeRouteInfo is expected to be fake up to this point so clear it
41-
action.AttributeRouteInfo = null;
42-
4340
var model = action.GetApiVersionModel();
4441
var mappings = RouteCollectionProvider.Items;
4542
var routeInfos = new HashSet<ODataAttributeRouteInfo>( new ODataAttributeRouteInfoComparer() );
@@ -120,19 +117,30 @@ void UpdateBindingInfo( ActionParameterContext context, ParameterDescriptor para
120117
Contract.Requires( context != null );
121118
Contract.Requires( parameter != null );
122119

120+
var parameterType = parameter.ParameterType;
123121
var bindingInfo = parameter.BindingInfo;
124122

125123
if ( bindingInfo != null )
126124
{
125+
if ( ( parameterType.IsODataQueryOptions() || parameterType.IsODataPath() ) && bindingInfo.BindingSource == Custom )
126+
{
127+
bindingInfo.BindingSource = Special;
128+
}
129+
127130
return;
128131
}
129132

130-
var metadata = ModelMetadataProvider.GetMetadataForType( parameter.ParameterType );
133+
var metadata = ModelMetadataProvider.GetMetadataForType( parameterType );
131134

132135
parameter.BindingInfo = bindingInfo = new BindingInfo() { BindingSource = metadata.BindingSource };
133136

134137
if ( bindingInfo.BindingSource != null )
135138
{
139+
if ( ( parameterType.IsODataQueryOptions() || parameterType.IsODataPath() ) && bindingInfo.BindingSource == Custom )
140+
{
141+
bindingInfo.BindingSource = Special;
142+
}
143+
136144
return;
137145
}
138146

src/Microsoft.AspNetCore.OData.Versioning/AspNetCore.Mvc/Versioning/ODataMvcOptionsSetup.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Microsoft.AspNetCore.OData.Versioning/Extensions.DependencyInjection/IODataBuilderExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.AspNetCore.Mvc.Infrastructure;
1111
using Microsoft.AspNetCore.Mvc.Versioning;
1212
using Microsoft.Extensions.DependencyInjection.Extensions;
13-
using Microsoft.Extensions.Options;
1413
using System;
1514
using System.Diagnostics.Contracts;
1615
using System.Linq;
@@ -68,7 +67,6 @@ static void AddODataServices( IServiceCollection services )
6867

6968
ConfigureDefaultFeatureProviders( partManager );
7069
services.Replace( Singleton<IActionSelector, ODataApiVersionActionSelector>() );
71-
services.AddTransient<IPostConfigureOptions<MvcOptions>, ODataMvcOptionsSetup>();
7270
services.TryAdd( Transient<VersionedODataModelBuilder, VersionedODataModelBuilder>() );
7371
services.TryAdd( Singleton<IODataRouteCollectionProvider, ODataRouteCollectionProvider>() );
7472
services.AddTransient<IApplicationModelProvider, ODataApplicationModelProvider>();

0 commit comments

Comments
 (0)