AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

OData conventional routing not supports multiple endpoint for a entity with different prefix in path

Open javiercn opened this issue 2 years ago • 2 comments


Issue moved from dotnet/aspnetcore#41864

  • Please respond to @padhumailin.

From @padhumailin on Thursday, May 26, 2022 9:03:02 AM

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

We have an endpoints already clients are using it currently and we don't want to change them. and could not add multiple endpoints for a entity with different prefix in path.

i have attached a sample project to reproduce the scenario: https://github.com/padhumailin/ODataRouteComponent

for example our existing endpoints : http://localhost:9542/general/api/devices http://localhost:9542/private/api/devices

http://localhost:9542/general/api/customers/{Country}/{type} http://localhost:9542/private/api/customers/{Country}/{type}

following error occurs when register the multiple endpoints for same entity in start up: Error : AmbiguousMatchException: The request matched multiple endpoints. Matches: ODataRouteComponent.Controllers.DevicesController.GetPublicDevices (ODataRouteComponent) Microsoft.AspNetCore.OData.Routing.Controllers.MetadataController.GetServiceDocument (Microsoft.AspNetCore.OData)

i arrived a workaround for this issue :

  1. These endpoints not registered in startup, but register without prefix
  2. Redirect to a another action method where prefix is send as route parameter

redirected endpoints as follows: http://localhost:9542/api/devices/{accessType} -> prefix 'general' is send as route parameter {accessType} http://localhost:9542/api/customers/{accessType}/{Country}/{type}

My Question : Is this right way of implementation? or have any better solution

Another Issue :

For route parameters, DynamicSegmentTemplate is applied in odata routing convention. this causes @odata.type in response and @odata.context metadata url not working its returning 404 image

is there any way hide this from response. i tried with custom serialization but not works and any solution for @odata.context to work.

Another Issue : using KeySegmentTemplate instead of DynamicSegmentTemplate, causing issue in open api swagger , the route parameters are shown as key value pair. and this occurs only for muttiple routeparams. image

Odata V8 EF core 6 Net core 6

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

core 6

Anything else?

No response

javiercn avatar May 26 '22 09:05 javiercn

We have an endpoints already clients are using it currently and we don't want to change them. and could not add multiple endpoints for a entity with different prefix in path.

i have attached a sample project to reproduce the scenario: https://github.com/padhumailin/ODataRouteComponent

for example our existing endpoints : http://localhost:9542/general/api/devices http://localhost:9542/private/api/devices

http://localhost:9542/general/api/customers/{Country}/{type} http://localhost:9542/private/api/customers/{Country}/{type}

following error occurs when register the multiple endpoints for same entity in start up: Error : AmbiguousMatchException: The request matched multiple endpoints. Matches: ODataRouteComponent.Controllers.DevicesController.GetPublicDevices (ODataRouteComponent) Microsoft.AspNetCore.OData.Routing.Controllers.MetadataController.GetServiceDocument (Microsoft.AspNetCore.OData)

i arrived a workaround for this issue :

These endpoints not registered in startup, but register without prefix Redirect to a another action method where prefix is send as route parameter redirected endpoints as follows: http://localhost:9542/api/devices/{accessType} -> prefix 'general' is send as route parameter {accessType} http://localhost:9542/api/customers/{accessType}/{Country}/{type}

My Question : Is this right way of implementation? or have any better solution

Another Issue :

For route parameters, DynamicSegmentTemplate is applied in odata routing convention. this causes @odata.type in response and @odata.context metadata url not working its returning 404 image

is there any way hide this from response. i tried with custom serialization but not works and any solution for @odata.context to work.

Another Issue : using KeySegmentTemplate instead of DynamicSegmentTemplate, causing issue in open api swagger , the route parameters are shown as key value pair. and this occurs only for muttiple routeparams. image

Odata V8 EF core 6 Net core 6

for swagger url issue (), tried routeOptions.UrlKeyDelimiter = ODataUrlKeyDelimiter.Slash; in ConfigureServices method startup.cs but not working.

We have an endpoints already clients are using it currently and we don't want to change them. and could not add multiple endpoints for a entity with different prefix in path.

i have attached a sample project to reproduce the scenario: https://github.com/padhumailin/ODataRouteComponent

for example our existing endpoints : http://localhost:9542/general/api/devices http://localhost:9542/private/api/devices

http://localhost:9542/general/api/customers/{Country}/{type} http://localhost:9542/private/api/customers/{Country}/{type}

following error occurs when register the multiple endpoints for same entity in start up: Error : AmbiguousMatchException: The request matched multiple endpoints. Matches: ODataRouteComponent.Controllers.DevicesController.GetPublicDevices (ODataRouteComponent) Microsoft.AspNetCore.OData.Routing.Controllers.MetadataController.GetServiceDocument (Microsoft.AspNetCore.OData)

i arrived a workaround for this issue :

  1. These endpoints not registered in startup, but register without prefix
  2. Redirect to a another action method where prefix is send as route parameter

redirected endpoints as follows: http://localhost:9542/api/devices/{accessType} -> prefix 'general' is send as route parameter {accessType} http://localhost:9542/api/customers/{accessType}/{Country}/{type}

My Question : Is this right way of implementation? or have any better solution

Another Issue 2:

For route parameters, DynamicSegmentTemplate is applied in odata routing convention. this causes @odata.type in response and @odata.context metadata url not working its returning 404 image

is there any way hide this from response. i tried with custom serialization but not works and any solution for @odata.context to work.

Another Issue 3: using KeySegmentTemplate instead of DynamicSegmentTemplate, causing issue in open api swagger , the route parameters are shown as key value pair. and this occurs only for muttiple routeparams. image

Odata V8 EF core 6 Net core 6

padhumailin avatar May 30 '22 06:05 padhumailin

for Another Issue 3 mentioned above, i have tried routeOptions.UrlKeyDelimiter = ODataUrlKeyDelimiter.Slash; in ConfigureServices, but not working

padhumailin avatar May 30 '22 06:05 padhumailin