diff --git a/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs b/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs index d828aea00..41bf31c7c 100644 --- a/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs +++ b/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs @@ -331,10 +331,7 @@ private string GetOperationId(OpenApiDocument document, string controllerName, M } else { - if (controllerName.EndsWith("Controller", StringComparison.Ordinal)) - { - controllerName = controllerName.Substring(0, controllerName.Length - 10); - } + controllerName = RemoveControllerSuffix(controllerName); operationId = $"{controllerName}_{GetActionName(method)}"; } @@ -352,7 +349,7 @@ private string GetOperationId(OpenApiDocument document, string controllerName, M private List GetHttpPaths(Type controllerType, MethodInfo method) { var httpPaths = new List(); - var controllerName = controllerType.Name.Replace("Controller", string.Empty); + var controllerName = RemoveControllerSuffix(controllerType.Name); var routeAttributes = GetRouteAttributes(method.GetCustomAttributes()).ToList(); @@ -663,5 +660,14 @@ private static IEnumerable GetSupportedHttpMethodsFromAttributes(MethodI } } } + + private static string RemoveControllerSuffix(string controllerName) + { + if (controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase)) + { + controllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length); + } + return controllerName; + } } }