OData / OData/AspNetCoreOData

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

Open
#606 2 comments 0 reactions 1 assignee View on GitHub

@corranrogue9 is already working on this.

Since May 31, 2022.

investigating
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description


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?
  • 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.