Support explicit operation IDs (#13449)
This commit is contained in:
@@ -61,6 +61,18 @@ public class ManagementApiComposer : IComposer
|
||||
{
|
||||
swaggerGenOptions.CustomOperationIds(e =>
|
||||
{
|
||||
var httpMethod = e.HttpMethod?.ToLower().ToFirstUpper() ?? "Get";
|
||||
|
||||
// if the route info "Name" is supplied we'll use this explicitly as the operation ID
|
||||
// - usage example: [HttpGet("my-api/route}", Name = "MyCustomRoute")]
|
||||
if (string.IsNullOrWhiteSpace(e.ActionDescriptor.AttributeRouteInfo?.Name) == false)
|
||||
{
|
||||
var explicitOperationId = e.ActionDescriptor.AttributeRouteInfo!.Name;
|
||||
return explicitOperationId.InvariantStartsWith(httpMethod)
|
||||
? explicitOperationId
|
||||
: $"{httpMethod}{explicitOperationId}";
|
||||
}
|
||||
|
||||
var relativePath = e.RelativePath;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(relativePath))
|
||||
@@ -68,8 +80,6 @@ public class ManagementApiComposer : IComposer
|
||||
throw new Exception($"There is no relative path for controller action {e.ActionDescriptor.RouteValues["controller"]}");
|
||||
}
|
||||
|
||||
var httpMethod = e.HttpMethod?.ToLower().ToFirstUpper() ?? "Get";
|
||||
|
||||
// Remove the prefixed base path with version, e.g. /umbraco/management/api/v1/tracked-reference/{id} => tracked-reference/{id}
|
||||
var unprefixedRelativePath = OperationIdRegexes.VersionPrefixRegex().Replace(relativePath, string.Empty);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user