-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
The new minimal API feature in ASP.NET Core 6 doesn't populate the ApiDescription.ActionDescriptor.AttributeRouteInfo property which is used by Swashbuckle by default to set the operation ID. Minimal APIs can have an endpoint name set via endpoint metadata however so if Swashbuckle's default behavior were updated to fallback to using the EndpointNameMetadata in ApiDescription.ActionDescriptor.EndpointMetadata then it would be simple for operation IDs to be configured on minimal APIs without having to configure Swashbuckle manually.
e.g. change in src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGeneratorOptions.cs
namespace Swashbuckle.AspNetCore.SwaggerGen
{
public class SwaggerGeneratorOptions
{
...
private string DefaultOperationIdSelector(ApiDescription apiDescription)
{
return
apiDescription.ActionDescriptor.AttributeRouteInfo?.Name
?? (apiDescription.ActionDescriptor.EndpointMetadata
.FirstOrDefault(m => m is EndpointNameMetadata) as EndpointNameMetadata)?.EndpointName;
}
}
}Example minimal API:
app.MapGet("/", () => "Hello World")
.WithMetadata(new EndpointNameMetadata("HelloWorldApi"));It might be worth considering including RouteNameMetadata as a value to look for too, rather than relying solely on AttributeRouteInfo.