Skip to content
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

My API is not displaying all the versions. #1085

Open
1 task done
GProGamer opened this issue Apr 28, 2024 · 4 comments
Open
1 task done

My API is not displaying all the versions. #1085

GProGamer opened this issue Apr 28, 2024 · 4 comments

Comments

@GProGamer
Copy link

GProGamer commented Apr 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In my project, I'm specifying two versions for the CountriesController controller.

I have two classes within the same namespace, one is CountriesV2Controller [ApiVersion("2.0")] and the other is CountriesController [ApiVersion("1.0")]. Both versions have the same route [Route("api/v{version:apiVersion}/countries")], so I don't understand why I have this problem.

But only version 1 is being displayed and accessible.

When I was using Microsoft.AspNetCore.Mvc.Versioning, everything worked fine, without any issues with my current configuration.

Any help is appreciated :)

Expected Behavior

I should be able to access both versions of the controller.

api-supported-versions: 1.0 , 2.0

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

net7.0

Anything else?

Asp.Versioning.Mvc" Version ->7.1.1
Asp.Versioning.Mvc.ApiExplorer ->Version=7.1.0

repo: https://github.com/GProGamer/HotelListing

@commonsensesoftware
Copy link
Collaborator

On the line:

https://github.com/GProGamer/HotelListing/blob/master/HotelListing.API/Program.cs#L52

you need to add .AddMvc(). Starting in API Versioning 6.0, this call is now required to bring in MVC Core. Without this call, only Minimal APIs are considered. The fact that anything works at all is a coincidence. I suspect after you add that, things will work as expected.

Note: this calls IApiVersioningBuilder.AddMvc and not IServiceCollectionBuilder.AddMvc, which does something different

@GProGamer
Copy link
Author

GProGamer commented May 5, 2024

I've forgot to say that I've already try to add .AddMvc(). I've tried again but I'm still getting the same weird behaviour:
it just shows version 1
image
image
image

but not version 2:

image

Help me please

@commonsensesoftware
Copy link
Collaborator

I browsed over the repro a little too fast. There's actually a number of things missing from your configuration that should be there. This information is provided in the wiki and example projects with OpenAPI and Swashbuckle. Ultimately, you need to use the API Explorer extensions provided by API Versioning to drive the generation of OpenAPI documents with Swashbuckle. There is no formal concept of versioning in the API Explorer, so Swashbuckle does not know how to use the information without a little help.

Since you provided a repro, you can apply the following Git patch and you should be only your way.

fix-config.patch

@GProGamer
Copy link
Author

GProGamer commented May 8, 2024

Hi Chris.
It works, I really appreciate it, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants