-
Notifications
You must be signed in to change notification settings - Fork 707
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
Incomplete response when incorrect version requested #876
Comments
The short answer, which you're probably not going to like, is that this is (now) by design. I really try to avoid breaking changes - especially behavioral changes, but sometimes it's unavoidable. This behavioral, breaking change has been called out in the roadmap and release notes since the first previews. As you pointed out, changing from The primary reason that the functionality is not preserved is simply due to implementation oversights in ASP.NET Core itself. This is being tracked in dotnet/aspnetcore#32957, but it will not land until .NET 7.0. I've even commented further on the issue. I'm not sure there is a way to address the issue. If you have an idea or proposal as to how it might be mitigated, I'm open to it. TL;DRThis history of how and why this happened is a bit long-winded. It started with #744. That issue uncovered a bug, which I thought was a bug in the ASP.NET Core routing system, which I reported in dotnet/aspnetcore#33865. After further analysis, I determined that it was not a bug, but rather a misunderstanding by me as to how the routing system works. Previously, API Verisoning's role in routing was pretty simple - allow duplicate routes to match and disambiguate by API version. There have always been edge cases, namely There are a couple of consequences to this change. First, there are some cases where you'll now get The other I've always felt it was interesting and useful for a client to know when a server supports an API, but not the version requested; that's how the
|
Unfortunately, sunsetting is not an approach that would work in our particular scenario since there is no guarantee that any given client would attempt to connect to the REST API during a sunsetting period. As I mentioned above, the 400 vs 404 result isn't really a big issue for us as long as there's some way to detect the version incompatibility in the response that is sent when a client requests an unsupported version. Are there plans for making that possible again, or should we be looking for other ways to support that going forward? (Version 5.0 is working fine for us at the moment, so we could just stick with it for now.) |
If dotnet/aspnetcore#32957 does the right thing and enables the necessary hooks, then - yes - the functionality will return in the |
Fingers crossed in that case -- thanks! |
In revisiting this for .NET 7, I think there may be some possibility to improve things. In previous versions, it was assumed that candidates could simply be eliminated by API version. That is ultimately how the old Starting in 6.0 the graph for endpoints built by the routing system has an API version node (the acceptance tests output a link you can use to view the graph in a browser). This allows making routing decisions earlier, which improves performance and solves the other edge cases, such as One thing that I did notice, however, is that the In short, this could work: GET /api/values?api-version=5.0 HTTP/2
Host: localhost:5000 HTTP/2 404 Not Found
Content-Type: application/problem+json
Content-Length: 420
{
"type": "https://docs.api-versioning.org/problems#unsupported",
"title": "Unsupported API version",
"status": 404,
"detail": "The HTTP resource that matches the request URI 'https://localhost:5001/api/values' does not support the API version '5.0'."
} As opposed to: GET /api/fake?api-version=1.0 HTTP/2
Host: localhost:5000 HTTP/2 404 Not Found Which would be something that truly doesn't exist. I have to do some more research, but it might - just might - be possible to report API versions if I can capture supported and deprecated separately. In theory, if there's no match, we've already reached |
That's good news! 🤞 |
My preliminary research shows that I can collate supported and deprecated API versions as they are built up in the routing system. The metadata for each endpoint has already been computed so I do know what has been defined. The issue is that the only thing I have to pivot on from a policy standpoint is the incoming API version. I'd have to rely on the way the routing system builds the route tree based on templates to collate and report the appropriate versions. Honestly, it's best effort. As far as I can tell, it does seem to produce the correct and expected behavior, but I can't be 100% certain and there may be edge cases that I've missed. I don't have control over how the routing system builds the tree from route templates and even if I could change it, I'm not sure I want to. It's very complex. The case I worry about is logically different APIs that overlap by template, but are technically different APIs. For example, is I think this is a reasonable compromise. My investigation suggests that getting an understated or overstated set of supported and deprecated API versions is unlikely with this approach. This has certainly been a challenge. I actually didn't think that many people liked this in the error case. There have certainly been more voiced opinions on the opposite side (voting for |
Thanks! In the long term, I'm not overly bothered by the exact response status code as long as there's some way for the client to infer that it's trying to use a version that isn't supported. A |
Is there an existing issue for this?
Describe the bug
We use this library for versioning of a .NET 6.0 REST API for which supporting forced update of client application is a key requirement. Unfortunately, after update to v6.0.0, it seems that the information that would help the client determine that there is a version mismatch is no longer exposed in the HTTP response.
The change in status code from 400 to 404 is a minor inconvenience that we can work around. However, when an incorrect API version is requested, there does not seem to be any information returned in the response that would help identify the problem:
api-supported-versions
is absent from the response even ifApiVersioningOptions.ReportApiVersions
has been set totrue
.This behaviour can be easily reproduced using the
BasicExample
at https://github.com/dotnet/aspnet-api-versioning/tree/main/examples/AspNetCore/WebApi/BasicExample:api-supported-versions
header.api-supported-versions
header.Expected Behavior
When an unsupported API version is requested, a problem details response identifying the problem should be returned. If supported version reporting has been enabled via
ApiVersioningOptions.ReportApiVersions
, anapi-supported-versions
header should be included in the response.Steps To Reproduce
Run the
BasicExample
from this repo and request an unsupported API version (e.g.: https://localhost:5001/api/values?api-version=5.0).Exceptions (if any)
No response
.NET Version
6.0.400
Anything else?
We see 400 responses with meaningful problem details when using v5.0.0 of this library with .NET 6.0, so this does not appear to be a .NET 6.0 issue.
The text was updated successfully, but these errors were encountered: