-
Notifications
You must be signed in to change notification settings - Fork 709
Version Selector ignored for OData Controllers #471
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
Looks like your setup is correct; however, in order for the IApiVersionSelector to come into play (currently), no API version must be requested by the client. When a client specifies an API version, that value takes precedence and is always honored first. The server should always honor information provided by the client. There is currently no hook that would allow you to easily change this behavior. This behavior isn't limited to OData. The only feasible workaround, which I don't recommend, would be to use a query parameter that isn't known to API versioning so that it will have the appearance that no API version was specified. This can be achieved by passing an empty list to the QueryStringApiVersionReader or creating and replacing the configured IApiVersionReader with an implementation that always returns
I hope that helps. |
I understand that. But i'm not requesting a specific version via the client. I simple call '/api/People'. No header, no query, no api version in url, no version anywhere else. Still i'm getting the default version. |
Inferring some more information. I see that you are using ASP.NET Core as well as mixing OData and non-Data route. Which routing method is configured? OData doesn't work with Endpoint Routing. |
As I said, I'm using the samples in this repository: The only problem is when I omit the api version. Thus I request the latest implement version (after adding code snippet above). However I get the default 1.0, because apparently the VersionSelector is never called. You can (or should be able to) reproduce that easily:
|
Are there still question or is the problem not reproducible? |
Apologies for the lapse in response. Been busy with the j-o-b recently. Your information and repro was perfect and got right to the crux of the problem. I can confirm that this particular configuration yields a bug. >_< The root of the problem is in the VersionedODataPathRouteConstraint; mainly here. I love OData as a protocol, but I really loathe the implementation sometimes. Rather than conform (e.g. rethink) to the routing in ASP.NET Core, the OData team has continued down the path of doing their own thing; specifically, the ODataPathRouteConstraint. API versioning and, hence, the IApiVersionSelector needs all candidates before it can make a decision, which isn't available at this point in the pipeline. The OData implementation always assumes there will only be one possible match (I guess based on the assumption of a single EDM). I'm about to head out for vacation so it will probably be close to two weeks before I can commit serious time to resolving this. In the interim, there may be a possible workaround. If you set |
On a side note, I wanted to set the default version to the latest for other reasons. The implementation is based on the SwaggerODataSample and I added |
Just a quick update. I had to do some refactoring, but I have a reliable, long-term solution for this. I'm working on knocking out as many issues in the next release as possible. The fix for this will be included. Stay tuned. Thanks for your patience. |
I cannot get the api version selector to work when using OData.
I used the samples (ODataBasicSample, BasicSample) to verify that.
Added the following into the respective
startup.cs
When omitting the api version (query parameter) in the BasicSample (without OData) the latest version is used.
For the ODataBasicSample the default version "1.0" is used.
I replaced the ApiVersionSelector with a custom one. It appears the SelectVersion Method is never called.
The text was updated successfully, but these errors were encountered: