-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce AspNetCoreApiDescriptionModelProviderOptions.
Resolve #5921
- Loading branch information
Showing
2 changed files
with
66 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...bp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProviderOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using Volo.Abp.Application.Services; | ||
using Volo.Abp.AspNetCore.Mvc.Conventions; | ||
|
||
namespace Volo.Abp.AspNetCore.Mvc | ||
{ | ||
public class AspNetCoreApiDescriptionModelProviderOptions | ||
{ | ||
public Func<Type, ConventionalControllerSetting, string> ControllerNameGenerator { get; set; } | ||
|
||
public Func<MethodInfo, string> ActionNameGenerator { get; set; } | ||
|
||
public AspNetCoreApiDescriptionModelProviderOptions() | ||
{ | ||
ControllerNameGenerator = (controllerType, setting) => | ||
{ | ||
var controllerName = controllerType.Name.RemovePostFix("Controller") | ||
.RemovePostFix(ApplicationService.CommonPostfixes); | ||
if (setting?.UrlControllerNameNormalizer != null) | ||
{ | ||
controllerName = | ||
setting.UrlControllerNameNormalizer( | ||
new UrlControllerNameNormalizerContext(setting.RootPath, controllerName)); | ||
} | ||
return controllerName; | ||
}; | ||
|
||
ActionNameGenerator = (method) => | ||
{ | ||
var methodNameBuilder = new StringBuilder(method.Name); | ||
var parameters = method.GetParameters(); | ||
if (parameters.Any()) | ||
{ | ||
methodNameBuilder.Append("By"); | ||
for (var i = 0; i < parameters.Length; i++) | ||
{ | ||
if (i > 0) | ||
{ | ||
methodNameBuilder.Append("And"); | ||
} | ||
methodNameBuilder.Append(parameters[i].Name.ToPascalCase()); | ||
} | ||
} | ||
return methodNameBuilder.ToString(); | ||
}; | ||
} | ||
} | ||
} |