I'm using Swashbuckle.AspNetCore.SwaggerUI package in one of my projects. We're versioning our endpoints using SwaggerEndpoint() method like so:
app.UseSwaggerUI(options => {
foreach (var description in provider.ApiVersionDescriptions) {
options.SwaggerEndpoint(
$"/{basePath}/swagger/{description.GroupName}/swagger.json",
description.GroupName.ToUpperInvariant()
);
}
});
This results in multiple definitions within the dropdown in upper-right corner of the UI.
My question: is there any way to specify which of those definitions is selected by default when the UI first opens?
I've searched the Swashbuckle GitHub and also Stack Overflow, but not finding what I'm looking for.
There are a couple of possible solutions. The API version descriptions will be sorted by their API version in ascending order by default. If you prefer to have the latest version (e.g. the highest API version), then simply reversing the order will do the trick:
If you want to want to set some arbitrary definition, then you need to configure the
urls.primaryNamesettings in the configuration.This example continues to set the highest API version as the current item because it's the last item when sorted in ascending order. If you have something more complex, just change the logic in setting the value.