Browse Source
Improve nullable type detection in API modeling
pull/24335/head
maliming
2 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
8 additions and
2 deletions
-
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
-
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.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 && |
|
|
|
|
|
|
|
@ -42,7 +42,7 @@ public class PropertyApiDescriptionModel |
|
|
|
Type = ApiTypeNameHelper.GetTypeName(propertyInfo.PropertyType), |
|
|
|
TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType), |
|
|
|
IsRequired = customAttributes.OfType<RequiredAttribute>().Any() || propertyInfo.GetCustomAttributesData().Any(attr => attr.AttributeType.Name == "RequiredMemberAttribute"), |
|
|
|
IsNullable = TypeHelper.IsNullable(propertyInfo.PropertyType), |
|
|
|
IsNullable = TypeHelper.IsNullableOrNotValueType(propertyInfo.PropertyType), |
|
|
|
Minimum = customAttributes.OfType<RangeAttribute>().Select(x => x.Minimum).FirstOrDefault()?.ToString(), |
|
|
|
Maximum = customAttributes.OfType<RangeAttribute>().Select(x => x.Maximum).FirstOrDefault()?.ToString(), |
|
|
|
MinLength = customAttributes.OfType<MinLengthAttribute>().FirstOrDefault()?.Length ?? customAttributes.OfType<StringLengthAttribute>().FirstOrDefault()?.MinimumLength, |
|
|
|
|