-
Notifications
You must be signed in to change notification settings - Fork 712
ApiVersionCollator does not filter actions for IApiBehaviorMetadata leading to actions with same controller name as api controller names getting grouped with it and leading to "Unsupported API Version" errors. #839
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
Do you happen to have a simple repro for this? It would seem there is a particular combination that results in this behavior. API Versioning doesn't specifically care about Using the filter in the ... 🤔 As I'm typing this out and reviewing the code, it would seem that the real issue is that otherwise unversioned endpoints are receiving collated metadata that they shouldn't. This would be a reason to run through the filter again. I think this might actually be a 🐞 . I'm a bit surprised it hasn't come up long before now. A little more discussion and perhaps a repro would confirm it. Fortunately, the fix is trivial. |
@commonsensesoftware here you go: https://github.com/rwasef1830/asp-versioning-bug-839-repro |
Great. Thanks. I'll look into it. |
Confirmed. It's a 🐞 . It'll be fixed in the next release. Your current workaround is feasible for your scenario. This turned out be a little trickier than I thought. The reason |
|
Hello,
ApiVersionCollator groups actions by controller name and adds versioning metadata, however it fails to filter the actions list to those that are actually defined as having
ApiBehavior
(as defined by havingIApiBehaviorMetadata
which is added by[ApiController]
attribute on such controllers or base classes thereof).This leads to the side effect that if a user had 2 controllers with the same name, but different area and different namespace and different everything, one of them is an API and the other is not, accessing the non-API controller will lead to thrown errors from Endpoint routing about unsupported or unspecified API version (depending on whether
ApiVersioningOptions.AssumeDefaultVersionWhenUnspecified
is true or false respectively).This behavior is very confusing and unreasonable for users with no clear way to debug or disambiguate, and there is no logging in the API collation process to troubleshoot this issue.
This kind of scenario is very common in applications such as ecommerce where there will be an API for retrieving products while at the same time an administration controller with the same name to manage such products on the store.
Note: It appears there's some filtering in another area of the library to check for this case, but this filtering is not done on the routing side which I guess is a simple oversight. Anyway, thanks for a very useful library regardless.
Here is a workaround to save others time:
then in the Startup sequence after calling
AddApiVersioning().AddMvc()
, search in the service collection for the descriptor having implementation typeApiVersionCollator
and replace it with the one above.Hope this helps someone.
The text was updated successfully, but these errors were encountered: