diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs index cab8c41b2c..a9f21c5a0d 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs @@ -57,8 +57,14 @@ namespace Volo.Abp.Reflection return t; } - public static bool IsEnumerable(Type type, out Type itemType) + public static bool IsEnumerable(Type type, out Type itemType, bool includePrimitives = true) { + if (!includePrimitives && IsPrimitiveExtended(type)) + { + itemType = null; + return false; + } + var enumerableTypes = ReflectionHelper.GetImplementedGenericTypes(type, typeof(IEnumerable<>)); if (enumerableTypes.Count == 1) { diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs index 8c6ea9e678..ca8af7f22a 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Volo.Abp.Reflection; namespace Volo.Abp.Http.Modeling { @@ -15,11 +16,30 @@ namespace Volo.Abp.Http.Modeling //TODO: Validation rules for this property public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo) { + string typeName; + string simpleTypeName; + + if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false)) + { + typeName = $"[{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]"; + simpleTypeName = $"[{ModelingTypeHelper.GetSimplifiedName(itemType)}]"; + } + else if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType)) + { + typeName = $"{{{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}"; + simpleTypeName = $"{{{ModelingTypeHelper.GetSimplifiedName(keyType)}:{ModelingTypeHelper.GetSimplifiedName(valueType)}}}"; + } + else + { + typeName = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType); + simpleTypeName = ModelingTypeHelper.GetSimplifiedName(propertyInfo.PropertyType); + } + return new PropertyApiDescriptionModel { Name = propertyInfo.Name, - Type = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType), - TypeSimple = ModelingTypeHelper.GetSimplifiedName(propertyInfo.PropertyType) + Type = typeName, + TypeSimple = simpleTypeName }; } }