-
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
Migration from Microsoft.AspNetCore.Mvc.Versioning to Asp.Versioning.Mvc causes versioning to no longer work #917
Comments
Thanks for the repro. It's very helpful. Interestingly, there is a 🐞 , but not quite for the reason you may think. I'm surprised this hasn't been hit before. I'd have to dig up the issue, but there was a much older problem where unversioned APIs that could show up in OpenAPI were completely discarded. While that's probably what most people wanted (as you expect here), it's wrong and it was a problem for people that wanted it. Unfortunately, that fix didn't make it into any of the There are a number of other problems however:
The setup should look like: builder.Services.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.ApiVersionReader = new UrlSegmentApiVersionReader();
})
.AddMvc() // ← new; brings in MVC Core support
.AddApiExplorer(options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
}); |
Thank you for the fast response, i was able to get the demo repo working after applying the steps you provided. Regarding the individual points:
Thank you for the example provided. I will leave a link to a new working demo repo in case somebody stumbles on this issue so they can have a baseline to start and compare differences to the 5.0.0 version. Link to working demo repo: https://github.com/ustarrenato/WebAppWithVersioningWorkingSample |
FYI, |
Is there an existing issue for this?
Describe the bug
Hi,
We are currently in a process of migrating our codebase to .NET 6, and we noticed we no longer could get versioning to work.
I have successfully recreated the issue in a new .NET 6 ASP.NET Core project, and was able to confirm that using Microsoft.AspNetCore.Mvc.Versioning (5.0.0) and AddVersionedApiExplorer, IApiVersionDescriptionProvider works as expected.
This means that IApiVersionDescriptionProvider is able to pick up two versions specified in a versioned controller, and this can then be passed to Swagger UI.
Using Asp.Versioning.Mvc.ApiExplorer (6.2.1, 6.2.0, 6.0.0) and AddApiExplorer causes IApiVersionDescriptionProvider to only show default API version (defaulting to 1.0 when not specified) and does not register any versioning applied to the versioned controller.
I have included link to a solution containing two projects, one which uses the latest Microsoft.AspNetCore.Mvc.Versioning at the time of writing (5.0.0), and one that uses the latest Asp.Versioning.Mvc (6.2.1).
I would kindly ask to confirm if this is indeed the BUG, or am I simply missing something in the configuration.
I should also note InfoController is simply added to test that endpoints are mapped correctly, and is not used as a part of versioning (And the issue persists even if the controller is removed).
Expected Behavior
After successful build, both projects should be able to display swagger UI with two versions, 2.0 and 3.0.
Steps To Reproduce
Link to repo:
https://github.com/ustarrenato/WebAppWithVersioning
Setting the breakpointing in Program.cs line 70 in VS shows that apiVersionDescriptionProvider?.ApiVersionDescriptions has only one version in WebAppWithVersioning (1.0) while WebAppWithVersioningMicrosoft5 has two (2.0, 3.0).
Exceptions (if any)
No response
.NET Version
7.0.100
Anything else?
Microsoft.NETCore.App 6.0.11
Visual Studio 2022 Version 17.4.0
Microsoft .NET Framework 4.8.09037
ASP.NET and Web Tools 17.4.326.54890
Swagger 6.4.0
The text was updated successfully, but these errors were encountered: