Skip to content

Commit

Permalink
removed redundant parens
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Feb 21, 2024
1 parent 0bdf290 commit 178ff8a
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void ApplySwaggerTagAttribute(
{
Name = controllerName,
Description = swaggerTagAttribute.Description,
ExternalDocs = (swaggerTagAttribute.ExternalDocsUrl != null)
ExternalDocs = swaggerTagAttribute.ExternalDocsUrl != null
? new OpenApiExternalDocs { Url = new Uri(swaggerTagAttribute.ExternalDocsUrl) }
: null
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public bool Validate(
}

// maxItems
if (schema.MaxItems.HasValue && (arrayInstance.Count() > schema.MaxItems.Value))
if (schema.MaxItems.HasValue && arrayInstance.Count() > schema.MaxItems.Value)
errorMessagesList.Add($"Path: {instance.Path}. Array size is greater than maxItems");

// minItems
if (schema.MinItems.HasValue && (arrayInstance.Count() < schema.MinItems.Value))
if (schema.MinItems.HasValue && arrayInstance.Count() < schema.MinItems.Value)
errorMessagesList.Add($"Path: {instance.Path}. Array size is less than minItems");

// uniqueItems
if (schema.UniqueItems.HasValue && (arrayInstance.Count() != arrayInstance.Distinct().Count()))
if (schema.UniqueItems.HasValue && arrayInstance.Count() != arrayInstance.Distinct().Count())
errorMessagesList.Add($"Path: {instance.Path}. Array does not contain uniqueItems");

errorMessages = errorMessagesList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public bool Validate(
var errorMessagesList = new List<string>();

// multipleOf
if (schema.MultipleOf.HasValue && ((numberValue % schema.MultipleOf.Value) != 0))
if (schema.MultipleOf.HasValue && numberValue % schema.MultipleOf.Value != 0)
errorMessagesList.Add($"Path: {instance.Path}. Number is not evenly divisible by multipleOf");

// maximum & exclusiveMaximum
if (schema.Maximum.HasValue)
{
var exclusiveMaximum = schema.ExclusiveMaximum.HasValue ? schema.ExclusiveMaximum.Value : false;

if (exclusiveMaximum && (numberValue >= schema.Maximum.Value))
if (exclusiveMaximum && numberValue >= schema.Maximum.Value)
errorMessagesList.Add($"Path: {instance.Path}. Number is greater than, or equal to, maximum");
else if (numberValue > schema.Maximum.Value)
errorMessagesList.Add($"Path: {instance.Path}. Number is greater than maximum");
Expand All @@ -44,7 +44,7 @@ public bool Validate(
{
var exclusiveMinimum = schema.ExclusiveMinimum.HasValue ? schema.ExclusiveMinimum.Value : false;

if (exclusiveMinimum && (numberValue <= schema.Minimum.Value))
if (exclusiveMinimum && numberValue <= schema.Minimum.Value)
errorMessagesList.Add($"Path: {instance.Path}. Number is less than, or equal to, minimum");
else if (numberValue < schema.Minimum.Value)
errorMessagesList.Add($"Path: {instance.Path}. Number is less than minimum");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public bool Validate(
var errorMessagesList = new List<string>();

// maxLength
if (schema.MaxLength.HasValue && (stringValue.Length > schema.MaxLength.Value))
if (schema.MaxLength.HasValue && stringValue.Length > schema.MaxLength.Value)
errorMessagesList.Add($"Path: {instance.Path}. String length is greater than maxLength");

// minLength
if (schema.MinLength.HasValue && (stringValue.Length < schema.MinLength.Value))
if (schema.MinLength.HasValue && stringValue.Length < schema.MinLength.Value)
errorMessagesList.Add($"Path: {instance.Path}. String length is less than minLength");

// pattern
if ((schema.Pattern != null) && !Regex.IsMatch(stringValue, schema.Pattern))
if (schema.Pattern != null && !Regex.IsMatch(stringValue, schema.Pattern))
errorMessagesList.Add($"Path: {instance.Path}. String does not match pattern");

errorMessages = errorMessagesList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public bool Validate(
JToken instance,
out IEnumerable<string> errorMessages)
{
schema = (schema.Reference != null)
schema = schema.Reference != null
? (OpenApiSchema)openApiDocument.ResolveReference(schema.Reference)
: schema;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal static bool TryParse(this OpenApiSchema schema, string stringValue, out

else if (schema.Type == "array")
{
var arrayValue = (schema.Items == null)
var arrayValue = schema.Items == null
? stringValue.Split(',')
: stringValue.Split(',').Select(itemStringValue =>
{
Expand Down
6 changes: 3 additions & 3 deletions src/DotSwashbuckle.AspNetCore.ApiTesting/RequestValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static IEnumerable<OpenApiParameter> ExpandParameterSpecs(
.Concat(operationSpec.Parameters)
.Select(p =>
{
return (p.Reference != null)
return p.Reference != null
? (OpenApiParameter)openApiDocument.ResolveReference(p.Reference)
: p;
});
Expand Down Expand Up @@ -103,7 +103,7 @@ private void ValidateParameters(

if (value == null || parameterSpec.Schema == null) continue;

var schema = (parameterSpec.Schema.Reference != null)
var schema = parameterSpec.Schema.Reference != null
? (OpenApiSchema)openApiDocument.ResolveReference(parameterSpec.Schema.Reference)
: parameterSpec.Schema;

Expand All @@ -114,7 +114,7 @@ private void ValidateParameters(

private void ValidateContent(OpenApiRequestBody requestBodySpec, OpenApiDocument openApiDocument, HttpContent content)
{
requestBodySpec = (requestBodySpec.Reference != null)
requestBodySpec = requestBodySpec.Reference != null
? (OpenApiRequestBody)openApiDocument.ResolveReference(requestBodySpec.Reference)
: requestBodySpec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public DataContract GetDataContractForType(Type type)
var enumValues = jsonContract.UnderlyingType.GetEnumValues();

//Test to determine if the serializer will treat as string
var serializeAsString = (enumValues.Length > 0)
var serializeAsString = enumValues.Length > 0
&& JsonConverterFunc(enumValues.GetValue(0)).StartsWith("\"");

var primitiveTypeAndFormat = serializeAsString
Expand Down Expand Up @@ -108,7 +108,7 @@ public DataContract GetDataContractForType(Type type)
{
typeNameProperty = "$type";

typeNameValue = (_serializerSettings.TypeNameAssemblyFormatHandling == TypeNameAssemblyFormatHandling.Full)
typeNameValue = _serializerSettings.TypeNameAssemblyFormatHandling == TypeNameAssemblyFormatHandling.Full
? jsonObjectContract.UnderlyingType.AssemblyQualifiedName
: $"{jsonObjectContract.UnderlyingType.FullName}, {jsonObjectContract.UnderlyingType.Assembly.GetName().Name}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DataContract GetDataContractForType(Type type)
var enumValues = type.GetEnumValues();

//Test to determine if the serializer will treat as string
var serializeAsString = (enumValues.Length > 0)
var serializeAsString = enumValues.Length > 0
&& JsonConverterFunc(enumValues.GetValue(0)).StartsWith("\"");

var primitiveTypeAndFormat = serializeAsString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private OpenApiSchema CreateObjectSchema(DataContract dataContract, SchemaReposi
if (_generatorOptions.IgnoreObsoleteProperties && customAttributes.OfType<ObsoleteAttribute>().Any())
continue;

schema.Properties[dataProperty.Name] = (dataProperty.MemberInfo != null)
schema.Properties[dataProperty.Name] = dataProperty.MemberInfo != null
? GenerateSchemaForMember(dataProperty.MemberType, schemaRepository, dataProperty.MemberInfo, dataProperty)
: GenerateSchemaForType(dataProperty.MemberType, schemaRepository);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async Task<IDictionary<string, OpenApiSecurityScheme>> GetSecurityScheme
return new Dictionary<string, OpenApiSecurityScheme>(_options.SecuritySchemes);
}

var authenticationSchemes = (_authenticationSchemeProvider is not null)
var authenticationSchemes = _authenticationSchemeProvider is not null
? await _authenticationSchemeProvider.GetAllSchemesAsync()
: Enumerable.Empty<AuthenticationScheme>();

Expand Down Expand Up @@ -141,7 +141,7 @@ private IList<OpenApiServer> GenerateServers(string host, string basePath)
return new List<OpenApiServer>(_options.Servers);
}

return (host == null && basePath == null)
return host == null && basePath == null
? new List<OpenApiServer>()
: new List<OpenApiServer> { new OpenApiServer { Url = $"{host}{basePath}" } };
}
Expand Down Expand Up @@ -193,7 +193,7 @@ private IDictionary<OperationType, OpenApiOperation> GenerateOperations(
group.First().RelativePath,
string.Join(",", group.Select(apiDesc => apiDesc.ActionDescriptor.DisplayName))));

var apiDescription = (group.Count() > 1) ? _options.ConflictingActionsResolver(group) : group.Single();
var apiDescription = group.Count() > 1 ? _options.ConflictingActionsResolver(group) : group.Single();

operations.Add(OperationTypeMap[httpMethod.ToUpper()], GenerateOperation(apiDescription, schemaRepository));
};
Expand Down Expand Up @@ -352,7 +352,7 @@ private IList<OpenApiParameter> GenerateParameters(ApiDescription apiDescription
.Where(apiParam =>
{
return !apiParam.IsFromBody() && !apiParam.IsFromForm()
&& (!apiParam.CustomAttributes().OfType<BindNeverAttribute>().Any())
&& !apiParam.CustomAttributes().OfType<BindNeverAttribute>().Any()
&& (apiParam.ModelMetadata == null || apiParam.ModelMetadata.IsBindingAllowed);
});

Expand All @@ -369,13 +369,13 @@ private OpenApiParameter GenerateParameter(
? apiParameter.Name.ToCamelCase()
: apiParameter.Name;

var location = (apiParameter.Source != null && ParameterLocationMap.TryGetValue(apiParameter.Source, out var value))
var location = apiParameter.Source != null && ParameterLocationMap.TryGetValue(apiParameter.Source, out var value)
? value
: ParameterLocation.Query;

var isRequired = apiParameter.IsRequiredParameter();

var schema = (apiParameter.ModelMetadata != null)
var schema = apiParameter.ModelMetadata != null
? GenerateSchema(
apiParameter.Type,
schemaRepository,
Expand Down Expand Up @@ -558,7 +558,7 @@ private OpenApiSchema GenerateSchemaFromFormParameters(
? formParameter.Name.ToCamelCase()
: formParameter.Name;

var schema = (formParameter.ModelMetadata != null)
var schema = formParameter.ModelMetadata != null
? GenerateSchema(
formParameter.Type,
schemaRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public static MethodInfo GetUnderlyingGenericTypeMethod(this MethodInfo construc
var candidateMethods = genericTypeDefinition.GetMethods()
.Where(m =>
{
return (m.Name == constructedTypeMethod.Name)
&& (m.GetParameters().Length == constructedTypeMethod.GetParameters().Length);
return m.Name == constructedTypeMethod.Name
&& m.GetParameters().Length == constructedTypeMethod.GetParameters().Length;
});


// If inconclusive, just return null
return (candidateMethods.Count() == 1) ? candidateMethods.First() : null;
return candidateMethods.Count() == 1 ? candidateMethods.First() : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static string GetMemberNameForType(Type type)

public static string GetMemberNameForFieldOrProperty(MemberInfo fieldOrPropertyInfo)
{
var builder = new StringBuilder(((fieldOrPropertyInfo.MemberType & MemberTypes.Field) != 0) ? "F:" : "P:");
var builder = new StringBuilder((fieldOrPropertyInfo.MemberType & MemberTypes.Field) != 0 ? "F:" : "P:");
builder.Append(QualifiedNameFor(fieldOrPropertyInfo.DeclaringType));
builder.Append($".{fieldOrPropertyInfo.Name}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void Validate_ThrowsException_IfQueryParameterIsNotOfSpecifiedType(
Schema = new OpenApiSchema
{
Type = specifiedType,
Items = (specifiedItemsType != null) ? new OpenApiSchema { Type = specifiedItemsType } : null
Items = specifiedItemsType != null ? new OpenApiSchema { Type = specifiedItemsType } : null
}
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ public void Validate_ThrowsException_IfHeaderParameterIsNotOfSpecifiedType(
Schema = new OpenApiSchema
{
Type = specifiedType,
Items = (specifiedItemsType != null) ? new OpenApiSchema { Type = specifiedItemsType } : null
Items = specifiedItemsType != null ? new OpenApiSchema { Type = specifiedItemsType } : null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Validate_ThrowsException_IfHeaderIsNotOfSpecifiedType(
Schema = new OpenApiSchema
{
Type = specifiedType,
Items = (specifiedItemsType != null) ? new OpenApiSchema { Type = specifiedItemsType } : null
Items = specifiedItemsType != null ? new OpenApiSchema { Type = specifiedItemsType } : null
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/WebSites/Dummy/Dumbs/Types/Types (907).cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ public virtual bool ShouldSerializeDescription()
/// </summary>
public virtual bool ShouldSerializeAttributeID()
{
return (AttributeID != null);
return AttributeID != null;
}

/// <summary>
/// Do mine Positionruby should businessol reDFed
/// </summary>
public virtual bool ShouldSerializePositionruby()
{
return (Positionruby != null);
return Positionruby != null;
}

/// <summary>
/// Do mine Descriptionruby should businessol reDFed
/// </summary>
public virtual bool ShouldSerializeDescriptionruby()
{
return (Descriptionruby != null);
return Descriptionruby != null;
}
}
}
Expand Down

0 comments on commit 178ff8a

Please sign in to comment.