Replies: 2 comments 1 reply
-
I think I understand what you are asking. I gather that you have something like: [ApiVersion(1.0)]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
public class BarController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
} and now you want to want to have it be supported in This is an implementation detail on the server side more than anything. API versions must be explicit. That's the only way that provable decisions can be made. How would the framework know that you want this it be auto-magically included? Your intention might have been to completely remove the API in One of the best things you can do is define a sound versioning policy upfront - say What some people are looking for is what I call Symmetrical Versioning. Typically, it's more flexible to allow your APIs to evolve with their own, independent versions over time, but some people want every release to have the same API versions across the board, even if there is no change. In other words, they want the versions to be symmetrical. If you're building a broad service or platform, from the client's perspective that can make sense. The implementation as to how you achieve that can vary. The most straight forward and easiest to rationalize about is to explicitly version each API. It is also possible to automate that process by examining a set of known API versions from configuration or by what already exists and then fill in the blanks. I provided a skeleton of how that might be achieved in 900. Keep in mind that you still have to account for APIs that might be completely sunset and make sure you don't accidentally pick up new APIs in older versions. This is the type of use case the API Explorer extensions can provide for verification in tests that have nothing to do with OpenAPI (formerly Swagger). Hopefully, that gives you some ideas to get started and the potential risks of filling in the blanks to make all of the versions symmetrical. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your helpful response. I don't wish to give a generous open source developer a hard time but I must say that I find it really surprising that this kind of fallback to previous isn't a built in option, or indeed the default behavior. Without it, do we really have to decorate every method with an attribute for every version in the version history then? Either that or require that clients specify the version they require endpoint by endpoint, rather than for the API as a whole, and in that case you're left with some pretty strange swagger documentation, where the doc pages for each version only include the endpoints changed in that version, so you can't see the whole thing in one go. I tried the customisation suggested in #900 (comment), but as far as I can see this only has the same effect that decorating each controller with its version history would do, which means that the individual methods fall back to the first not the latest previous version, i.e. in the following a request to
|
Beta Was this translation helpful? Give feedback.
-
I've got a large existing API which I want to add versioning to. So I set
AssumeDefaultVersionWhenUnspecified = true
andDefaultApiVersion = new ApiVersion(1, 0)
and add[ApiVersion(1)]
to all my controllers and everything is great - my clients can continue as they are requestingapi/foo
etc, or start requestingapi/v1/foo
.Now I want to release a version 2 of the API with breaking changes to a couple of methods. I create new versions of those methods at same routes but with
[ApiVersion(2)]
attributes. My clients update their code and set their API version to be 2 and now all theirapi/v2/foo
requests at those routes get served by the new methods and any client still requestingapi/v1/foo
or justapi/foo
continue to be served by the old method as before.However, now all requests to
api/v2/bar
and any other existing route get anUnsupportedApiVersion
error! Obviously we wouldn't want a long trail of ApiVersion attributes building up all over the place as new versions are introduced, so how do I make sure requests fall back to the highest available version not exceeding their requested version?Beta Was this translation helpful? Give feedback.
All reactions