Skip to content

Commit dae55f1

Browse files
Remove unused parameter
- Remove unused parameter from change in #3377. - Simplify duplicated condition.
1 parent 557d074 commit dae55f1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private OpenApiSchema GenerateSchemaForMember(
6060

6161
var requiredAttribute = customAttributes.OfType<RequiredAttribute>().FirstOrDefault();
6262

63-
if (!IsNullable(customAttributes, requiredAttribute, dataProperty, memberInfo))
63+
if (!IsNullable(requiredAttribute, dataProperty, memberInfo))
6464
{
6565
modelType = Nullable.GetUnderlyingType(modelType) ?? modelType;
6666
}
@@ -87,7 +87,7 @@ private OpenApiSchema GenerateSchemaForMember(
8787
{
8888
var requiredAttribute = customAttributes.OfType<RequiredAttribute>().FirstOrDefault();
8989

90-
schema.Nullable = IsNullable(customAttributes, requiredAttribute, dataProperty, memberInfo);
90+
schema.Nullable = IsNullable(requiredAttribute, dataProperty, memberInfo);
9191

9292
schema.ReadOnly = dataProperty.IsReadOnly;
9393
schema.WriteOnly = dataProperty.IsWriteOnly;
@@ -137,11 +137,16 @@ private OpenApiSchema GenerateSchemaForMember(
137137
return schema;
138138
}
139139

140-
private bool IsNullable(IEnumerable<object> customAttributes, RequiredAttribute requiredAttribute, DataProperty dataProperty, MemberInfo memberInfo)
140+
private bool IsNullable(RequiredAttribute requiredAttribute, DataProperty dataProperty, MemberInfo memberInfo)
141141
{
142-
return _generatorOptions.SupportNonNullableReferenceTypes
143-
? dataProperty.IsNullable && requiredAttribute == null && !memberInfo.IsNonNullableReferenceType()
144-
: dataProperty.IsNullable && requiredAttribute == null;
142+
var nullable = dataProperty.IsNullable && requiredAttribute == null;
143+
144+
if (_generatorOptions.SupportNonNullableReferenceTypes)
145+
{
146+
nullable &= !memberInfo.IsNonNullableReferenceType();
147+
}
148+
149+
return nullable;
145150
}
146151

147152
private OpenApiSchema GenerateSchemaForParameter(

0 commit comments

Comments
 (0)