Revised API and script creation.

pull/122/head
Halil İbrahim Kalkan 7 years ago
parent f0563bd00b
commit 0635e74ed6

@ -66,7 +66,7 @@ namespace Volo.Abp.AspNetCore.Mvc
var moduleModel = model.GetOrAddModule(GetRootPath(controllerType, setting));
var controllerModel = moduleModel.GetOrAddController(CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);
var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);
var method = apiDescription.ActionDescriptor.GetMethodInfo();
@ -77,9 +77,8 @@ namespace Volo.Abp.AspNetCore.Mvc
return;
}
var actionModel = controllerModel.AddAction(ActionApiDescriptionModel.Create(
var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
method,
uniqueMethodName,
apiDescription.RelativePath,
apiDescription.HttpMethod
));
@ -101,7 +100,7 @@ namespace Volo.Abp.AspNetCore.Mvc
private static string GetUniqueActionName(MethodInfo method)
{
var methodNameBuilder = new StringBuilder(method.Name);
var methodNameBuilder = new StringBuilder(method.Name.RemovePostFix("Async"));
var parameters = method.GetParameters();
if (parameters.Any())

@ -35,7 +35,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
foreach (var action in controller.Actions.Values)
{
if (action.NameOnClass == method.Name && action.ParametersOnMethod.Count == methodParameters.Length)
if (action.Name == method.Name && action.ParametersOnMethod.Count == methodParameters.Length)
{
var found = true;

@ -9,9 +9,7 @@ namespace Volo.Abp.Http.Modeling
[Serializable]
public class ActionApiDescriptionModel
{
public string UniqueName { get; set; }
public string NameOnClass { get; set; }
public string Name { get; set; }
public string HttpMethod { get; set; }
@ -28,12 +26,11 @@ namespace Volo.Abp.Http.Modeling
}
public static ActionApiDescriptionModel Create(MethodInfo method, string uniqueName, string url, string httpMethod)
public static ActionApiDescriptionModel Create(MethodInfo method, string url, string httpMethod)
{
return new ActionApiDescriptionModel
{
UniqueName = uniqueName,
NameOnClass = method.Name,
Name = method.Name,
Url = url,
HttpMethod = httpMethod,
ReturnValue = ReturnValueApiDescriptionModel.Create(method.ReturnType),

@ -36,16 +36,16 @@ namespace Volo.Abp.Http.Modeling
};
}
public ActionApiDescriptionModel AddAction(ActionApiDescriptionModel action)
public ActionApiDescriptionModel AddAction(string uniqueName, ActionApiDescriptionModel action)
{
if (Actions.ContainsKey(action.UniqueName))
if (Actions.ContainsKey(uniqueName))
{
throw new AbpException(
$"Can not add more than one action with same name to the same controller. Controller: {ControllerName}, Action: {action.UniqueName}."
);
$"Can not add more than one action with same name to the same controller. Controller: {ControllerName}, Action: {action.Name}."
);
}
return Actions[action.UniqueName] = action;
return Actions[uniqueName] = action;
}
public ControllerApiDescriptionModel CreateSubModel(string[] actions)
@ -58,11 +58,11 @@ namespace Volo.Abp.Http.Modeling
Actions = new Dictionary<string, ActionApiDescriptionModel>()
};
foreach (var action in Actions.Values)
foreach (var action in Actions)
{
if (actions == null || actions.Contains(action.UniqueName))
if (actions == null || actions.Contains(action.Key))
{
subModel.AddAction(action);
subModel.AddAction(action.Key, action.Value);
}
}

@ -41,9 +41,9 @@ namespace Volo.Abp.Http.Modeling
return Controllers[controller.ControllerName] = controller;
}
public ControllerApiDescriptionModel GetOrAddController(string name, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
public ControllerApiDescriptionModel GetOrAddController(string uniqueName, string name, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
{
return Controllers.GetOrAdd(name, () => ControllerApiDescriptionModel.Create(name, type, ignoredInterfaces));
return Controllers.GetOrAdd(uniqueName, () => ControllerApiDescriptionModel.Create(name, type, ignoredInterfaces));
}
public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions)

@ -73,8 +73,8 @@ 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.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");
script.AppendLine($" // action '{action.Name.ToCamelCase()}'");
script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.Name.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");
script.AppendLine(" return abp.ajax($.extend(true, {");
AddAjaxCallParameters(script, controller, action);

@ -47,7 +47,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators
if (parameters.Length > 1)
{
throw new AbpException(
$"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But {action.UniqueName} ({action.Url}) contains more than one!"
$"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But {action.Name} ({action.Url}) contains more than one!"
);
}

@ -9,10 +9,12 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1;
using Volo.Abp.Modularity;
namespace Volo.Abp.Identity.HttpApi.Host
@ -25,8 +27,6 @@ namespace Volo.Abp.Identity.HttpApi.Host
var hostingEnvironment = services.GetSingletonInstance<IHostingEnvironment>(); //TOD: Move to BuildConfiguration method
var configuration = BuildConfiguration(hostingEnvironment);
services.AddOptions(); //TODO: Remove later, for test purposes
services.Configure<DbConnectionOptions>(configuration);
services.Configure<AbpDbContextOptions>(options =>
@ -88,6 +88,20 @@ namespace Volo.Abp.Identity.HttpApi.Host
//options.IncludeXmlComments(XmlCommentsFilePath); //TODO: Add XML comments!
});
services.Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.AppServiceControllers.Create(typeof(AbpIdentityHttpApiHostModule).Assembly, o =>
{
o.TypePredicate = t => t == typeof(CallsController);
});
options.AppServiceControllers.Create(typeof(AbpIdentityHttpApiHostModule).Assembly, o =>
{
o.TypePredicate = t => t == typeof(Host.VersioningTests.V2.CallsController);
o.RootPath = "app/compat";
});
});
services.AddAssemblyOf<AbpIdentityHttpApiHostModule>();
}

@ -5,7 +5,6 @@ namespace Volo.Abp.Identity.HttpApi.Host.Controllers
{
public class HomeController : AbpController
{
[HttpPost]
public IActionResult Index()
{
return Redirect("/swagger");

@ -1,16 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1
{
[ApiVersion("1.0")]
[Route("api/v{api-version:apiVersion}/calls")]
public class CallsController : AbpController
public class CallsController : AbpController, IRemoteService
{
private static List<CallDto> _calls = new List<CallDto>
private static readonly List<CallDto> Calls = new List<CallDto>
{
new CallDto {Id = 1, Number = "123456"},
new CallDto { Id = 2, Number = "123457" }
@ -19,7 +19,7 @@ namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1
[HttpGet]
public List<CallDto> GetList()
{
return _calls;
return Calls;
}
}
@ -27,29 +27,4 @@ namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1
{
public string Number { get; set; }
}
[ApiVersion("2.0")]
[Route("api/v{api-version:apiVersion}/calls")]
[ControllerName("Calls")]
public class Calls2Controller : AbpController
{
private static List<CallDto> _calls = new List<CallDto>
{
new CallDto {Id = 1, Number = "123456000"},
new CallDto { Id = 2, Number = "123457000" }
};
[HttpGet]
public List<CallDto> GetList()
{
return _calls;
}
[HttpGet]
[Route("by-filter")]
public List<CallDto> GetList(string num)
{
return _calls.Where(c => c.Number.Contains(num)).ToList();
}
}
}

@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1;
namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests.V2
{
[ApiVersion("2.0")]
[Route("api/v{api-version:apiVersion}/calls")]
public class CallsController : AbpController, IRemoteService
{
private static List<CallDto> _calls = new List<CallDto>
{
new CallDto {Id = 1, Number = "123456000"},
new CallDto { Id = 2, Number = "123457000" }
};
[HttpGet]
public List<CallDto> GetList()
{
return _calls;
}
[HttpGet]
[Route("by-filter")]
public List<CallDto> GetList(string num)
{
return _calls.Where(c => c.Number.Contains(num)).ToList();
}
}
}
Loading…
Cancel
Save