feat:support array root

This commit is contained in:
xiaolipro 2025-08-01 10:56:07 +08:00
parent aa2212f05e
commit fefc6d1d63
5 changed files with 42 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using Newtonsoft.Json;
using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Contracts.Dtos.Interface;
using InterfaceForward.Application.Helpers; using InterfaceForward.Application.Helpers;
using InterfaceForward.Application.Services.Parameter; using InterfaceForward.Application.Services.Parameter;
using InterfaceForward.Domain.Shared;
using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Domain.Shared.Enum;
using InterfaceForward.Repositories; using InterfaceForward.Repositories;
using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Entitys;
@ -130,6 +131,17 @@ public class ServiceProviderInterfaceService : ApplicationService
[HttpPost("Interface/SaveServiceProviderInterface")] [HttpPost("Interface/SaveServiceProviderInterface")]
public async Task<int> SaveServiceProviderInterfaceAsync(ServiceProviderInterfaceInput input) public async Task<int> SaveServiceProviderInterfaceAsync(ServiceProviderInterfaceInput input)
{ {
input.InParameterList.ForEach(x =>
{
if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName)
x.Name = string.Empty;
});
input.OutParameterList.ForEach(x =>
{
if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName)
x.Name = string.Empty;
});
switch (input.OptionType) switch (input.OptionType)
{ {
case OptionType.: case OptionType.:

View File

@ -4,6 +4,7 @@ using Newtonsoft.Json;
using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Contracts.Dtos.Interface;
using InterfaceForward.Application.Helpers; using InterfaceForward.Application.Helpers;
using InterfaceForward.Application.Services.Parameter; using InterfaceForward.Application.Services.Parameter;
using InterfaceForward.Domain.Shared;
using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Domain.Shared.Enum;
using InterfaceForward.Repositories; using InterfaceForward.Repositories;
using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Entitys;
@ -139,6 +140,17 @@ public class SystemInterfaceService : ApplicationService
[HttpPost("Interface/SaveSystemInterface")] [HttpPost("Interface/SaveSystemInterface")]
public async Task SaveSystemInterfaceAsync(SystemInterfaceInput input) public async Task SaveSystemInterfaceAsync(SystemInterfaceInput input)
{ {
input.InParameterList.ForEach(x =>
{
if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName)
x.Name = string.Empty;
});
input.OutParameterList.ForEach(x =>
{
if (x.PId == 0 && x.Type == ParameterType.Array && x.Name == GlobalConst.RootParameterName)
x.Name = string.Empty;
});
switch (input.OptionType) switch (input.OptionType)
{ {
case OptionType.: case OptionType.:

View File

@ -5,6 +5,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Contracts.Dtos.Interface;
using InterfaceForward.Application.Helpers; using InterfaceForward.Application.Helpers;
using InterfaceForward.Domain.Shared;
using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Domain.Shared.Enum;
using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Entitys;
using InterfaceForward.Repositories.Interface.Services; using InterfaceForward.Repositories.Interface.Services;
@ -195,7 +196,8 @@ public class ParameterService : ApplicationService
{ {
idx++; idx++;
var res = JArray2List(arr, ref idx, 1); var res = JArray2List(arr, ref idx, 1);
res.Insert(0, new(1, 0, "arr", ParameterType.Array, annotation)); var name = pid == 0 ? GlobalConst.RootParameterName : "arr";
res.Insert(0, new(1, 0, name, ParameterType.Array, annotation));
return res; return res;
} }

View File

@ -25,6 +25,11 @@ public static class GlobalConst
/// </summary> /// </summary>
public const string AppId = nameof(AppId); public const string AppId = nameof(AppId);
/// <summary>
/// 参数根类型为数组时,参数的命名
/// </summary>
public const string RootParameterName = "array";
/// <summary> /// <summary>
/// 服务商接口qps redis key前缀 /// 服务商接口qps redis key前缀
/// </summary> /// </summary>

View File

@ -1,5 +1,6 @@
using InterfaceForward.Domain.Shared.Enum; using InterfaceForward.Domain.Shared.Enum;
using InterfaceForward.Application.Contracts.Dtos.Interface; using InterfaceForward.Application.Contracts.Dtos.Interface;
using InterfaceForward.Domain.Shared;
using InterfaceForward.Repositories.Interface.Entitys; using InterfaceForward.Repositories.Interface.Entitys;
using InterfaceForward.Repositories.Interface.ValueObjects; using InterfaceForward.Repositories.Interface.ValueObjects;
using InterfaceForward.Repositories.Parameter.VO; using InterfaceForward.Repositories.Parameter.VO;
@ -70,7 +71,15 @@ public class InterfaceRepository : BasicRepository<InterfaceEntity>, IInterfaceR
.WhereIF(onlyLeafs, x => x.Type != ParameterType.Object && x.Type != ParameterType.Array) .WhereIF(onlyLeafs, x => x.Type != ParameterType.Object && x.Type != ParameterType.Array)
.OrderBy(x => x.Sort); .OrderBy(x => x.Sort);
return await query.Select<InterfaceParameterOutputValueObject>().ToListAsync(); var res = await query.Select<InterfaceParameterOutputValueObject>().ToListAsync();
res.ForEach(x =>
{
if (x.PId == 0 && x.Type == (int)ParameterType.Array && x.Name == string.Empty)
x.Name = GlobalConst.RootParameterName;
});
return res;
} }
/// <inheritdoc /> /// <inheritdoc />