|
|
|
@ -1,8 +1,8 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using System.Text; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc.Abstractions; |
|
|
|
using Microsoft.AspNetCore.Mvc.ApiExplorer; |
|
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.AspNetCore.Mvc.Utils; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Http.Modeling; |
|
|
|
@ -38,6 +39,8 @@ namespace Volo.Abp.AspNetCore.Mvc |
|
|
|
|
|
|
|
public ApplicationApiDescriptionModel CreateApiModel() |
|
|
|
{ |
|
|
|
//TODO: Can cache the model?
|
|
|
|
|
|
|
|
var model = ApplicationApiDescriptionModel.Create(); |
|
|
|
|
|
|
|
foreach (var descriptionGroupItem in _descriptionProvider.ApiDescriptionGroups.Items) |
|
|
|
@ -59,10 +62,11 @@ namespace Volo.Abp.AspNetCore.Mvc |
|
|
|
private void AddApiDescriptionToModel(ApiDescription apiDescription, ApplicationApiDescriptionModel model) |
|
|
|
{ |
|
|
|
var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(); |
|
|
|
var setting = FindSetting(controllerType); |
|
|
|
|
|
|
|
var moduleModel = model.GetOrAddModule(GetRootPath(controllerType)); |
|
|
|
var moduleModel = model.GetOrAddModule(GetRootPath(controllerType, setting)); |
|
|
|
|
|
|
|
var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, controllerType, _modelOptions.IgnoredInterfaces); |
|
|
|
var controllerModel = moduleModel.GetOrAddController(CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces); |
|
|
|
|
|
|
|
var method = apiDescription.ActionDescriptor.GetMethodInfo(); |
|
|
|
|
|
|
|
@ -83,6 +87,18 @@ namespace Volo.Abp.AspNetCore.Mvc |
|
|
|
AddParameterDescriptionsToModel(actionModel, method, apiDescription); |
|
|
|
} |
|
|
|
|
|
|
|
private static string CalculateControllerName(Type controllerType, AbpControllerAssemblySetting setting) |
|
|
|
{ |
|
|
|
var controllerName = controllerType.Name.RemovePostFix("Controller").RemovePostFix(ApplicationService.CommonPostfixes); |
|
|
|
|
|
|
|
if (setting?.UrlControllerNameNormalizer != null) |
|
|
|
{ |
|
|
|
controllerName = setting.UrlControllerNameNormalizer(new UrlControllerNameNormalizerContext(setting.RootPath, controllerName)); |
|
|
|
} |
|
|
|
|
|
|
|
return controllerName; |
|
|
|
} |
|
|
|
|
|
|
|
private static string GetUniqueActionName(MethodInfo method) |
|
|
|
{ |
|
|
|
var methodNameBuilder = new StringBuilder(method.Name); |
|
|
|
@ -152,19 +168,11 @@ namespace Volo.Abp.AspNetCore.Mvc |
|
|
|
return modelNameProvider.Name; |
|
|
|
} |
|
|
|
|
|
|
|
private string GetRootPath(Type controllerType) |
|
|
|
private static string GetRootPath([NotNull] Type controllerType, [CanBeNull] AbpControllerAssemblySetting setting) |
|
|
|
{ |
|
|
|
if (controllerType == null) |
|
|
|
if (setting != null) |
|
|
|
{ |
|
|
|
return ModuleApiDescriptionModel.DefaultRootPath; |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings) |
|
|
|
{ |
|
|
|
if(controllerSetting.ControllerTypes.Contains(controllerType)) |
|
|
|
{ |
|
|
|
return controllerSetting.RootPath; |
|
|
|
} |
|
|
|
return setting.RootPath; |
|
|
|
} |
|
|
|
|
|
|
|
var areaAttr = controllerType.GetCustomAttributes().OfType<AreaAttribute>().FirstOrDefault(); |
|
|
|
@ -175,5 +183,19 @@ namespace Volo.Abp.AspNetCore.Mvc |
|
|
|
|
|
|
|
return ModuleApiDescriptionModel.DefaultRootPath; |
|
|
|
} |
|
|
|
|
|
|
|
[CanBeNull] |
|
|
|
private AbpControllerAssemblySetting FindSetting(Type controllerType) |
|
|
|
{ |
|
|
|
foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings) |
|
|
|
{ |
|
|
|
if (controllerSetting.ControllerTypes.Contains(controllerType)) |
|
|
|
{ |
|
|
|
return controllerSetting; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|