-
Notifications
You must be signed in to change notification settings - Fork 712
remove -status in AddVersionedApiExplorer not work #983
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
Can you quantify what you mean by it doesn't work? What happens? What do you expect to happen? As shown, this is what will happen: var apiVersion = new ApiVersion( 1, 0 , "Public");
Console.WriteLine( apiVersion.ToString( "V" ) ); Output:
The full formatting options are documented in the wiki under the version format topic. The status is fundamentally part of the API version when you use it. It is possible to format parts of an API version for display purposes, but you cannot abuse to formatting create a 🐶 and 🐴 show where the client asks for some API version - say You can hide the status when formatting the API version used for grouping purposes. For example, you can show |
my purpose is to divide definitions in swagger like this |
Based on what you are showing, it would appear your goal is to provide an additional level of organization or grouping to a set of APIs. An API version status is not meant for that. There are multiple ways that you can provide additional grouping, but at the end of the day, the Swagger UI only affords for a single dropdown without some significant customization to the UI. I can't say exactly how, nor can think of someone that has put forth that much effort, but it is technically possible. ASP.NET Core and the API Explorer explorer do provide a way to define a group, but that typically conflicts with using the API version itself as the group once you add versioning. The desire to have both has come up enough that now there is a built in feature to support it. Let's assume you have the following controller. [ApiVersion(1.0)]
[ApiController]
[ApiExplorerSettings(GroupName="Admin")]
[Route("admin/[controller]")]
public class SecretsController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
} This defines the group services.AddApiVersioning()
.AddApiExplorer(options =>
{
options.GroupNameFormat = "V";
options.FormatGroupName = (group, version) => $"API v{version}-{group}";
options.SubstitutionFormat = "V";
options.SubstituteApiVersionInUrl = true;
}); In order for the If you did this for all of your controllers, that will display in the list as you've shown. The actually API version is still Also be aware that you've changed the |
Is there an existing issue for this?
Describe the bug
i use [ApiVersion("1.0-Public")] attribute
for split definitions in Swagger after that for routing just added
to set the major version
[Route("v{version:apiVersion}/[controller]/[action]")]
this sample works fine
but in asp.net core APIs formatting of the version doesn't work
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
5.0.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: