Skip to content

Commit 2976fad

Browse files
Fixes route template parameter name binding. Fixes #40 (#41)
1 parent 4bf4ef8 commit 2976fad

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

samples/webapi/BasicODataWebApiSample/Controllers/People2Controller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public IHttpActionResult Get( ODataQueryOptions<Person> options ) =>
2020

2121
// GET ~/v3/people(1)
2222
// GET ~/api/people(1)?api-version=3.0
23-
[ODataRoute( "({key})" )]
23+
[ODataRoute( "({id})" )]
2424
public IHttpActionResult Get( [FromODataUri] int id, ODataQueryOptions<Person> options ) =>
2525
Ok( new Person() { Id = id, FirstName = "Bill", LastName = "Mei", Email = "bill.mei@somewhere.com", Phone = "555-555-5555" } );
2626
}

src/Microsoft.AspNet.OData.Versioning/Web.OData/Routing/VersionedAttributeRoutingConvention.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public override bool ShouldMapController( HttpControllerDescriptor controller )
7676
return true;
7777
}
7878

79-
var apiVersion = Model.GetAnnotationValue<ApiVersion>( Model );
79+
var apiVersion = Model.GetAnnotationValue<ApiVersionAnnotation>( Model )?.ApiVersion;
8080

8181
return apiVersion != null && versionModel.DeclaredApiVersions.Contains( apiVersion );
8282
}

src/Microsoft.AspNet.OData.Versioning/Web.OData/Routing/VersionedODataPathRouteConstraint.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public override bool Match( HttpRequestMessage request, IHttpRoute route, string
6767

6868
if ( routeDirection == UriGeneration )
6969
{
70-
return true;
70+
return base.Match( request, route, parameterName, values, routeDirection );
7171
}
7272

7373
var requestedVersion = request.GetRequestedApiVersionOrReturnBadRequest();
@@ -112,7 +112,11 @@ private static void DecorateUrlHelperWithApiVersionRouteValueIfNecessary( HttpRe
112112
}
113113

114114
var requestContext = request.GetRequestContext();
115-
requestContext.Url = new VersionedUrlHelperDecorator( requestContext.Url, apiVersion );
115+
116+
if ( !( requestContext.Url is VersionedUrlHelperDecorator ) )
117+
{
118+
requestContext.Url = new VersionedUrlHelperDecorator( requestContext.Url, apiVersion );
119+
}
116120
}
117121
}
118122
}

src/Microsoft.AspNet.OData.Versioning/project.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version": "2.0.0-*",
2+
"version": "2.0.1-*",
33
"authors": [ "Microsoft" ],
44
"title": "Microsoft ASP.NET Web API Versioning for OData v4.0",
55
"copyright": "Copyright \u00A9 2016. Microsoft Corporation. All rights reserved.",
66
"description": "A service API versioning library for Microsoft ASP.NET Web API and OData v4.0.",
77
"language": "en",
88

99
"dependencies": {
10-
"Microsoft.AspNet.OData": "5.9.1",
10+
"Microsoft.AspNet.OData": "[5.9.1,6.0.0)",
1111
"Microsoft.AspNet.WebApi.Versioning": "2.0.0-*"
1212
},
1313

@@ -26,7 +26,7 @@
2626
"summary": "Provides API versioning for RESTful services created using ASP.NET Web API and OData v4.0",
2727
"tags": [ "Microsoft", "AspNet", "AspNetWebAPI", "OData", "Versioning" ],
2828
"owners": [ "Microsoft" ],
29-
"releaseNotes": "",
29+
"releaseNotes": "\u2022 Fixes route template parameter name binding (Issue #40)",
3030
"iconUrl": "http://go.microsoft.com/fwlink/?LinkID=288890",
3131
"licenseUrl": "https://raw.githubusercontent.com/Microsoft/aspnet-api-versioning/master/LICENSE",
3232
"requireLicenseAcceptance": true,

test/Microsoft.AspNet.OData.Versioning.Tests/Web.OData/Routing/VersionedAttributeRoutingConventionTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public void should_map_controller_should_return_true_for_versionX2Dneutral_contr
4747
var model = new ODataModelBuilder().GetEdmModel();
4848
var controller = new HttpControllerDescriptor( new HttpConfiguration(), string.Empty, typeof( NeutralController ) );
4949
var convention = new VersionedAttributeRoutingConvention( model, new HttpControllerDescriptor[0] );
50+
var annotation = new ApiVersionAnnotation( new ApiVersion( 1, 0 ) );
5051

51-
model.SetAnnotationValue( model, new ApiVersion( 1, 0 ) );
52+
model.SetAnnotationValue( model, annotation );
5253

5354
// act
5455
var result = convention.ShouldMapController( controller );
@@ -66,8 +67,9 @@ public void should_map_controller_should_return_expected_result_for_controller_v
6667
var model = new ODataModelBuilder().GetEdmModel();
6768
var controller = new HttpControllerDescriptor( new HttpConfiguration(), string.Empty, typeof( ControllerV1 ) );
6869
var convention = new VersionedAttributeRoutingConvention( model, new HttpControllerDescriptor[0] );
70+
var annotation = new ApiVersionAnnotation( new ApiVersion( majorVersion, 0 ) );
6971

70-
model.SetAnnotationValue( model, new ApiVersion( majorVersion, 0 ) );
72+
model.SetAnnotationValue( model, annotation );
7173

7274
// act
7375
var result = convention.ShouldMapController( controller );

0 commit comments

Comments
 (0)