-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Richard Beauchamp
committed
Dec 19, 2015
1 parent
fc3fd1f
commit 08daf8e
Showing
39 changed files
with
1,079 additions
and
61 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Swashbuckle.OData.Sample/App_Start/CustomNavigationPropertyRoutingConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Web.Http.Controllers; | ||
using System.Web.OData.Routing; | ||
using System.Web.OData.Routing.Conventions; | ||
using SwashbuckleODataSample.ODataControllers; | ||
|
||
namespace SwashbuckleODataSample | ||
{ | ||
public class CustomNavigationPropertyRoutingConvention : EntitySetRoutingConvention | ||
{ | ||
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap) | ||
{ | ||
var controllerType = controllerContext.Controller.GetType(); | ||
|
||
if (typeof (CustomersController) == controllerType) | ||
{ | ||
} | ||
else if (typeof (OrdersController) == controllerType) | ||
{ | ||
if (odataPath.PathTemplate.Equals("~/entityset/key/navigation")) //POST OR GET | ||
{ | ||
controllerContext.RouteData.Values["customerID"] = (odataPath.Segments[1] as KeyValuePathSegment).Value; | ||
return controllerContext.Request.Method.ToString(); | ||
} | ||
if (odataPath.PathTemplate.Equals("~/entityset/key/navigation/key")) //PATCH OR DELETE | ||
{ | ||
controllerContext.RouteData.Values["customerID"] = (odataPath.Segments[1] as KeyValuePathSegment).Value; | ||
|
||
controllerContext.RouteData.Values["key"] = (odataPath.Segments[3] as KeyValuePathSegment).Value; | ||
return controllerContext.Request.Method.ToString(); | ||
} | ||
} | ||
|
||
return base.SelectAction(odataPath, controllerContext, actionMap); | ||
} | ||
|
||
public override string SelectController(ODataPath odataPath, HttpRequestMessage request) | ||
{ | ||
// We use always use the last naviation as the controller vs. the initial entityset | ||
if (odataPath.PathTemplate.Contains("~/entityset/key/navigation")) | ||
{ | ||
// Find controller. Controller should be last navigation property | ||
return ODataSegmentKinds.Navigation == odataPath.Segments[odataPath.Segments.Count - 1].SegmentKind | ||
? odataPath.Segments[odataPath.Segments.Count - 1].ToString() | ||
: odataPath.Segments[odataPath.Segments.Count - 2].ToString(); | ||
} | ||
return base.SelectController(odataPath, request); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.Owin.Hosting; | ||
using NUnit.Framework; | ||
using Swashbuckle.OData.Tests.WebHost; | ||
using Swashbuckle.Swagger; | ||
using SwashbuckleODataSample; | ||
|
||
namespace Swashbuckle.OData.Tests | ||
{ | ||
[TestFixture] | ||
public class CustomRouteTests | ||
{ | ||
[Test] | ||
public async Task It_allows_definition_of_custom_routes() | ||
{ | ||
using (WebApp.Start(TestWebApiStartup.BaseAddress, appBuilder => new TestWebApiStartup().Configuration(appBuilder))) | ||
{ | ||
// Arrange | ||
var httpClient = HttpClientUtils.GetHttpClient(TestWebApiStartup.BaseAddress, ODataConfig.ODataRoutePrefix); | ||
|
||
// Act | ||
var swaggerDocument = await httpClient.GetJsonAsync<SwaggerDocument>("swagger/docs/v1"); | ||
|
||
// Assert | ||
PathItem pathItem; | ||
swaggerDocument.paths.TryGetValue("/odata/Customers({Id})/Orders", out pathItem); | ||
pathItem.Should().NotBeNull(); | ||
pathItem.post.Should().NotBeNull(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.