-
Notifications
You must be signed in to change notification settings - Fork 712
Versioned OData attribute routing not working on ASP.NET Core 3.1 and ASP.NET Core 5.0 (with or without Endpoint routing enabled) #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Duplicate of #689 and #698. Do not use odata attribute routing with Microsoft.AspNetCore.OData.Versioning 5.0.0, it just behave same as convention routing (and GetWeatherForecasts is not allowed). If you decide to continue to use Microsoft.AspNetCore.OData.Versioning 5.0.0, also look at #695 and #693 |
I'm seeing the same behavior on ASP.NET Core 3.1 with Microsoft.AspNetCore.OData.Versioning 5.0.0, worked fine in 4.1.1. It appears that |
It's taken a while to circle back on this, but I can confirm it's a bug. There is a copy and paste error here. This tests whether a controller action maps to an OData action or function. In other words, The reason things likely worked in earlier versions was due to a different bug that didn't have this test. In that issue, it was possible that a function was incorrectly matched for a entity set. OData has a huge number of combinations and test matrix. Unfortunately, this is further conflated by 3 routing models now! >_< I try to cover as many as I can, but it's a lot of work. OData has historically continued to choose not to adopt the standard attribute routing system (though This will be fixed in the next patch. In the meantime, you can work around the by using the short, method-only form. Honestly, I find it not only more succinct, but clearer in meaning. |
@commonsensesoftware we ran into the same. Do you have a timeline on when you would be able to release a quick patch? P.S. are you still working for Microsoft? |
|
|
Getting custom routing conventions to work is a real pain. The built-in conventions are hard enough to deal with. The pain will only get worse if you ever want to support OpenAPI/Swagger. |
|
|
|
|
I am not sure if it is fixed. I am running the ASP.NET Core SwaggerODataSample
Swagger wouldn't recognize the method.
|
@ntonyho OData is heavily dependent on specific conventions and provides virtually no support for OpenAPI/Swagger. To achieve any of that functionality I've had to implement my own Attribute Routing, which builds the OData template from attributes or just the type information. Even with the Endpoint Routing support, it's still a 🐶 and 🐴 show under the hood in The issue here is that the code can't tell if this action is an entity set operation, a function, or an action. This is internally nasty to check. Without the check, it's possible to incorrectly match an action/function to an entity set operation. Technically, that would be a developer mistake, but there's no way to really distinguish that without strictly enforcing the convention. I manually debugged this path and explicitly made it resolve this to an entity set operation. The action is correctly discovered with the appropriate OData route template, but it didn't match at runtime (e.g. 404 + Unsupported API Version). That could be a different issue, but it's hard to tell at this point. I'll continue to consider whether this is a problem because I know there are a few other edge case issues in the Speaking of, be careful adding
In the specific scenario that you changed, there would be no dire consequences since the route template should be |
Thanks you for repeated quick response. Much appreciated. To give a bit more context, I am trying to do While you did mention it could be done via
As far as I can tell, the out-of-box OData convention routing doesn't support that. Hence, my original attempt in using AttributeRouting (using ODataRoutePrefix + ODataRoute). Slightly off topic, did you take a look at OData v8 RC3? It seems to support some form of versioning, defining multiple EdmModels, and have support for OpenAPI/Swagger (granted, swagger will render all the versions in the same views). Do they finally incorporate your work into OData release or are they doing things very differently? |
If you don't want to go the route of Sorry, you have misunderstood. I definite do not ignore any routing configuration a user provides. A long-standing design principle is to not change the functional setup and understanding of routing. The issue is that OData only provides a means of matching an action. It provides no out-of-the-box mechanism to document or otherwise provide route template information. This has to be computed at app start-up time because it's a one-time operation that is read-only in the app's lifecycle. This impacts OpenAPI/Swagger the most, which makes it an unfortunate cost if you're not using it. However, since the route templates are constructed, it makes the matching logic much easier. I suggested that the OData team use a similar approach and I think I've seen various parts of The OData team has not incorporated any of my work that I'm aware of unless they silently forked something in. I've tried collaborating with them a few times, but it's mostly a one-way conversation. I'm happy to expand the thread or move it over to discussions. |
(please correct me if i am not getting the terminologies right)
|
Hi,
I'm using Microsoft.AspNetCore.OData.Versioning version 5.0.0.
I just created a sample WeatherForecastsController project for ASP.NET Core 5.0, added the recommended startup settings (along with the ones for versioning the API), decorated the controller and the action methods with the OData routing attributes but it's not working as expected. Note: This used to work for me in ASP.NET Core 2.2 with the API versioning. I tried with Endpoint routing enabled as well as disabled with no luck. I don't know what changed or if I'm doing anything wrong.
I have 3 methods defined in the controller:
As you can see from the REST requests below, it's not honoring the OData routes and seems to be only going by convention:
When I rename the List method (GetWeatherForecasts) to just "Get", the List call starts working again:
Same with POST - when I rename it to PostWeatherForecast or just Post, it works; not otherwise.
The test code is available at: https://github.com/deepakku-work/WeatherForecast. For reference, the relevant details are shared below. Any pointers on what I'm doing wrong / if this is a known issue / pointers on how I can debug this further will be very much appreciated.
Project file:
Startup.cs:
WeatherForecast model:
WeatherForecastODataConfiguration:
WeatherForecastsController:
The text was updated successfully, but these errors were encountered: