API improvements.

pull/122/head
Halil İbrahim Kalkan 7 years ago
parent 1df5821fb6
commit f0563bd00b

@ -311,9 +311,7 @@ namespace Volo.Abp.AspNetCore.Mvc
return configuration.UrlControllerNameNormalizer(
new UrlControllerNameNormalizerContext(
rootPath,
controllerName,
action,
httpMethod
controllerName
)
);
}

@ -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;
}
}
}

@ -1,24 +1,15 @@
using Microsoft.AspNetCore.Mvc.ApplicationModels;
namespace Volo.Abp.AspNetCore.Mvc
namespace Volo.Abp.AspNetCore.Mvc
{
//TODO: Re-consider properties of this class.
public class UrlControllerNameNormalizerContext
{
public string RootPath { get; }
public string ControllerName { get; }
public ActionModel Action { get; }
public string HttpMethod { get; }
public UrlControllerNameNormalizerContext(string rootPath, string controllerName, ActionModel action, string httpMethod)
public UrlControllerNameNormalizerContext(string rootPath, string controllerName)
{
RootPath = rootPath;
ControllerName = controllerName;
Action = action;
HttpMethod = httpMethod;
}
}
}

@ -74,7 +74,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams");
script.AppendLine($" // action '{action.NameOnClass.ToCamelCase()}'");
script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.NameOnClass.ToCamelCase())} = function({parameterList}) {{");
script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.NameOnClass.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");
script.AppendLine(" return abp.ajax($.extend(true, {");
AddAjaxCallParameters(script, controller, action);

Loading…
Cancel
Save