I use Swagger in my .NET 6.0 API, and I want to use different SwaggerEndpoint to group my API. Here is the code I set in Program.cs
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Blog API",
Version = "v1"
});
options.SwaggerDoc("v2", new OpenApiInfo
{
Title = "Blog API",
Version = "v2"
});
}
// ...
if (app.Environment.IsDevelopment())
{
app.UseSwaggerUI(options =>
{
options.InjectStylesheet("/swagger-ui/custom.css");
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Blog API V1");
options.SwaggerEndpoint("/swagger/v2/swagger.json", "Blog API V2");
});
}
And I set Attribute [ApiExplorerSettings(GroupName = "v2")] or v1 in controller.
In swagger UI, when I select the option, it cannot filter my API (It still display all API both in two options).
