Finalized jquery proxy script generation.

pull/122/head
Halil İbrahim Kalkan 7 years ago
parent d62424ebe3
commit c3f77c1229

@ -84,7 +84,7 @@ namespace Volo.Abp.AspNetCore.Mvc
method,
apiDescription.RelativePath,
apiDescription.HttpMethod,
setting?.ApiVersions.Select(v => v.ToString()).ToList() ?? new List<string>()
setting?.ApiVersions.Select(v => v.ToString()).ToList() ?? new List<string>() //TODO: Also get from ApiVersion attributes if available..?
));
AddParameterDescriptionsToModel(actionModel, method, apiDescription);

@ -132,8 +132,8 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{
var apiVersion = FindBestApiVersion(action);
//TODO: Make names configurable!
var versionParam = action.Parameters.FirstOrDefault(p => p.Name == "apiVersion") ??
//TODO: Make names configurable?
var versionParam = action.Parameters.FirstOrDefault(p => p.Name == "apiVersion" && p.BindingSourceId == ParameterBindingSources.Path) ??
action.Parameters.FirstOrDefault(p => p.Name == "api-version" && p.BindingSourceId == ParameterBindingSources.Query);
return new ApiVersionInfo(versionParam?.BindingSourceId, apiVersion);

@ -80,6 +80,16 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams");
script.AppendLine($" {controllerName}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(normalizedActionName.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");
var versionParam = action.Parameters.FirstOrDefault(p => p.Name == "apiVersion" && p.BindingSourceId == ParameterBindingSources.Path) ??
action.Parameters.FirstOrDefault(p => p.Name == "api-version" && p.BindingSourceId == ParameterBindingSources.Query);
if (versionParam != null)
{
var version = FindBestApiVersion(action);
script.AppendLine($" var {ProxyScriptingJsFuncHelper.NormalizeJsVariableName(versionParam.Name)} = '{version}';");
}
script.AppendLine(" return abp.ajax($.extend(true, {");
AddAjaxCallParameters(script, action);
@ -88,6 +98,24 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
script.AppendLine(" };");
}
private static string FindBestApiVersion(ActionApiDescriptionModel action)
{
//var configuredVersion = GetConfiguredApiVersion(); //TODO: Implement
string configuredVersion = null;
if (action.SupportedVersions.IsNullOrEmpty())
{
return configuredVersion ?? "1.0";
}
if (action.SupportedVersions.Contains(configuredVersion))
{
return configuredVersion;
}
return action.SupportedVersions.Last(); //TODO: Ensure to get the latest version!
}
private static void AddAjaxCallParameters(StringBuilder script, ActionApiDescriptionModel action)
{
var httpMethod = action.HttpMethod?.ToUpperInvariant() ?? "POST";

@ -0,0 +1,9 @@
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1
{
public class CallDto : EntityDto<int>
{
public string Number { get; set; }
}
}

@ -1,13 +1,12 @@
using System.Collections.Generic;
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")]
[Route("api/v{apiVersion:apiVersion}/calls")]
public class CallsController : AbpController, IRemoteService
{
private static readonly List<CallDto> Calls = new List<CallDto>
@ -22,9 +21,4 @@ namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests.V1
return Calls;
}
}
public class CallDto : EntityDto<int>
{
public string Number { get; set; }
}
}

@ -8,7 +8,7 @@ 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")]
[Route("api/v{apiVersion:apiVersion}/calls")]
public class CallsController : AbpController, IRemoteService
{
private static List<CallDto> _calls = new List<CallDto>

@ -8,7 +8,7 @@ namespace Volo.Abp.Identity
//TODO: This is just a test controller and will be removed later
[ApiVersion("3.0")]
[ApiVersion("2.0", Deprecated = true)]
[Route("api/v{api-version:apiVersion}/identity/fixture")]
[Route("api/v{apiVersion:apiVersion}/identity/fixture")]
public class FixtureController : AbpController, IRemoteService
{
private readonly IRequestedApiVersion _requestedApiVersion;

@ -7,7 +7,7 @@ namespace Volo.Abp.Identity.V4
{
//TODO: This is just a test controller and will be removed later
[ApiVersion("4.0")]
[Route("api/v{api-version:apiVersion}/identity/fixture")]
[Route("api/v{apiVersion:apiVersion}/identity/fixture")]
public class FixtureController : AbpController, IRemoteService
{
private readonly IRequestedApiVersion _requestedApiVersion;

Loading…
Cancel
Save