diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs
index ab26313736..8c2142c37f 100644
--- a/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs
+++ b/framework/src/Volo.Abp.Core/Volo/Abp/Reflection/ReflectionHelper.cs
@@ -8,6 +8,26 @@ namespace Volo.Abp.Reflection;
//TODO: Consider to make internal
public static class ReflectionHelper
{
+ ///
+ /// Checks whether the property is nullable, including nullable reference types (NRT).
+ ///
+ /// Property info to check
+ public static bool IsNullable(PropertyInfo propertyInfo)
+ {
+ if (propertyInfo.PropertyType.IsValueType)
+ {
+ return false;
+ }
+
+#if NET6_0_OR_GREATER
+ var nullabilityInfoContext = new System.Reflection.NullabilityInfoContext();
+ var nullabilityInfo = nullabilityInfoContext.Create(propertyInfo);
+ return nullabilityInfo.ReadState == System.Reflection.NullabilityState.Nullable;
+#else
+ return false;
+#endif
+ }
+
//TODO: Ehhance summary
///
/// Checks whether implements/inherits .
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 55891d8cd6..cc2dcde767 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
@@ -29,6 +29,8 @@ public class PropertyApiDescriptionModel
public string? Regex { get; set; }
+ public bool IsNullable { get; set; }
+
public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo)
{
var customAttributes = propertyInfo.GetCustomAttributes(true);
@@ -39,6 +41,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 = Volo.Abp.Reflection.ReflectionHelper.IsNullable(propertyInfo),
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,
diff --git a/npm/ng-packs/packages/schematics/src/models/api-definition.ts b/npm/ng-packs/packages/schematics/src/models/api-definition.ts
index 513201f0a9..70dca68dd5 100644
--- a/npm/ng-packs/packages/schematics/src/models/api-definition.ts
+++ b/npm/ng-packs/packages/schematics/src/models/api-definition.ts
@@ -20,6 +20,7 @@ export interface PropertyDef {
type: string;
typeSimple: string;
isRequired: boolean;
+ isNullable: boolean;
}
export interface Module {
diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts
index 1ea9130ef2..40dacbdfa4 100644
--- a/npm/ng-packs/packages/schematics/src/utils/model.ts
+++ b/npm/ng-packs/packages/schematics/src/utils/model.ts
@@ -187,6 +187,7 @@ export function createRefToImportReducerCreator(params: ModelGeneratorParams) {
function isOptionalProperty(prop: PropertyDef) {
return (
+ prop.isNullable ||
prop.typeSimple.endsWith('?') ||
((prop.typeSimple === 'string' || prop.typeSimple.includes('enum')) && !prop.isRequired)
);