Skip to content

Instantly share code, notes, and snippets.

@mattruma

mattruma/Startup.cs Secret

Created Nov 20, 2020
Embed
What would you like to do?
Grouping Controllers in Swagger
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>")]
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddCors();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = $"{Configuration["SwaggerDocs_ProductName"]} API",
Contact = new OpenApiContact
{
Name = Configuration["SwaggerDocs_ContactName"],
Email = Configuration["SwaggerDocs_ContactEmail"]
}
});
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
c.TagActionsBy(api =>
{
if (api.GroupName != null)
{
return new[] { api.GroupName };
}
if (api.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
return new[] { controllerActionDescriptor.ControllerName };
}
throw new InvalidOperationException("Unable to determine tag for endpoint.");
});
c.DocInclusionPredicate((name, api) => true);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.