From 4a36812cd5543bf2e1cbef0a77af0567a805cda4 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 8 Dec 2025 20:59:23 +0800 Subject: [PATCH] Improve nullable type detection in API modeling --- .../src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs | 8 +++++++- .../Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) 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 0118fd9874..f6375118ec 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs @@ -86,7 +86,7 @@ public static class TypeHelper { return default; } - + if (IsPrimitiveExtended(typeof(TProperty), includeEnums: true)) { var conversionType = typeof(TProperty); @@ -116,6 +116,12 @@ public static class TypeHelper return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); } + public static bool IsNullableOrNotValueType(Type type) + { + return (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) || + !type.IsValueType; + } + public static bool IsNullableEnum(Type type) { return type.IsGenericType && 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 e018782308..b30dc89615 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 @@ -42,7 +42,7 @@ public class PropertyApiDescriptionModel Type = ApiTypeNameHelper.GetTypeName(propertyInfo.PropertyType), TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType), IsRequired = customAttributes.OfType().Any() || propertyInfo.GetCustomAttributesData().Any(attr => attr.AttributeType.Name == "RequiredMemberAttribute"), - IsNullable = TypeHelper.IsNullable(propertyInfo.PropertyType), + IsNullable = TypeHelper.IsNullableOrNotValueType(propertyInfo.PropertyType), Minimum = customAttributes.OfType().Select(x => x.Minimum).FirstOrDefault()?.ToString(), Maximum = customAttributes.OfType().Select(x => x.Maximum).FirstOrDefault()?.ToString(), MinLength = customAttributes.OfType().FirstOrDefault()?.Length ?? customAttributes.OfType().FirstOrDefault()?.MinimumLength,