From 178ff8a0b4ce27a9da7e294c5f3eaac597b63dea Mon Sep 17 00:00:00 2001 From: Havunen Date: Wed, 21 Feb 2024 22:26:48 +0200 Subject: [PATCH] removed redundant parens --- .../AnnotationsDocumentFilter.cs | 2 +- .../JsonValidation/JsonArrayValidator.cs | 6 +++--- .../JsonValidation/JsonNumberValidator.cs | 6 +++--- .../JsonValidation/JsonStringValidator.cs | 6 +++--- .../JsonValidation/JsonValidator.cs | 2 +- .../OpenApiSchemaExtensions.cs | 2 +- .../RequestValidator.cs | 6 +++--- .../NewtonsoftDataContractResolver.cs | 4 ++-- .../JsonSerializerDataContractResolver.cs | 2 +- .../SchemaGenerator/SchemaGenerator.cs | 2 +- .../SwaggerGenerator/SwaggerGenerator.cs | 14 +++++++------- .../XmlComments/MethodInfoExtensions.cs | 6 +++--- .../XmlComments/XmlCommentsNodeNameHelper.cs | 2 +- .../RequestValidatorTests.cs | 4 ++-- .../ResponseValidatorTests.cs | 2 +- test/WebSites/Dummy/Dumbs/Types/Types (907).cs | 6 +++--- 16 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/DotSwashbuckle.AspNetCore.Annotations/AnnotationsDocumentFilter.cs b/src/DotSwashbuckle.AspNetCore.Annotations/AnnotationsDocumentFilter.cs index 8a95bee422..da9acc2398 100644 --- a/src/DotSwashbuckle.AspNetCore.Annotations/AnnotationsDocumentFilter.cs +++ b/src/DotSwashbuckle.AspNetCore.Annotations/AnnotationsDocumentFilter.cs @@ -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 }); diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonArrayValidator.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonArrayValidator.cs index de291ea1a8..d4c2badfee 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonArrayValidator.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonArrayValidator.cs @@ -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; diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonNumberValidator.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonNumberValidator.cs index 6a9ea154c3..e9b26e63b5 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonNumberValidator.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonNumberValidator.cs @@ -25,7 +25,7 @@ public bool Validate( var errorMessagesList = new List(); // 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 @@ -33,7 +33,7 @@ public bool Validate( { 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"); @@ -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"); diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonStringValidator.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonStringValidator.cs index f7a26d59ba..5dff2b74a5 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonStringValidator.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonStringValidator.cs @@ -26,15 +26,15 @@ public bool Validate( var errorMessagesList = new List(); // 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; diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonValidator.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonValidator.cs index df943da2f8..2245466850 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonValidator.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/JsonValidation/JsonValidator.cs @@ -33,7 +33,7 @@ public bool Validate( JToken instance, out IEnumerable errorMessages) { - schema = (schema.Reference != null) + schema = schema.Reference != null ? (OpenApiSchema)openApiDocument.ResolveReference(schema.Reference) : schema; diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/OpenApiSchemaExtensions.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/OpenApiSchemaExtensions.cs index c97f960398..09c5980b8a 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/OpenApiSchemaExtensions.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/OpenApiSchemaExtensions.cs @@ -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 => { diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/RequestValidator.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/RequestValidator.cs index e98a35df4d..fe68b8338c 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/RequestValidator.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/RequestValidator.cs @@ -58,7 +58,7 @@ private static IEnumerable ExpandParameterSpecs( .Concat(operationSpec.Parameters) .Select(p => { - return (p.Reference != null) + return p.Reference != null ? (OpenApiParameter)openApiDocument.ResolveReference(p.Reference) : p; }); @@ -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; @@ -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; diff --git a/src/DotSwashbuckle.AspNetCore.Newtonsoft/SchemaGenerator/NewtonsoftDataContractResolver.cs b/src/DotSwashbuckle.AspNetCore.Newtonsoft/SchemaGenerator/NewtonsoftDataContractResolver.cs index b6cb4a1d3c..1b4ac8693b 100644 --- a/src/DotSwashbuckle.AspNetCore.Newtonsoft/SchemaGenerator/NewtonsoftDataContractResolver.cs +++ b/src/DotSwashbuckle.AspNetCore.Newtonsoft/SchemaGenerator/NewtonsoftDataContractResolver.cs @@ -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 @@ -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}"; } diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/JsonSerializerDataContractResolver.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/JsonSerializerDataContractResolver.cs index 403236e8b5..b7080cd3a3 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/JsonSerializerDataContractResolver.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/JsonSerializerDataContractResolver.cs @@ -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 diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs index 50ea83f540..2301fe5376 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs @@ -407,7 +407,7 @@ private OpenApiSchema CreateObjectSchema(DataContract dataContract, SchemaReposi if (_generatorOptions.IgnoreObsoleteProperties && customAttributes.OfType().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); diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index 01cced0ad0..d8f29accf6 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -111,7 +111,7 @@ private async Task> GetSecurityScheme return new Dictionary(_options.SecuritySchemes); } - var authenticationSchemes = (_authenticationSchemeProvider is not null) + var authenticationSchemes = _authenticationSchemeProvider is not null ? await _authenticationSchemeProvider.GetAllSchemesAsync() : Enumerable.Empty(); @@ -141,7 +141,7 @@ private IList GenerateServers(string host, string basePath) return new List(_options.Servers); } - return (host == null && basePath == null) + return host == null && basePath == null ? new List() : new List { new OpenApiServer { Url = $"{host}{basePath}" } }; } @@ -193,7 +193,7 @@ private IDictionary 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)); }; @@ -352,7 +352,7 @@ private IList GenerateParameters(ApiDescription apiDescription .Where(apiParam => { return !apiParam.IsFromBody() && !apiParam.IsFromForm() - && (!apiParam.CustomAttributes().OfType().Any()) + && !apiParam.CustomAttributes().OfType().Any() && (apiParam.ModelMetadata == null || apiParam.ModelMetadata.IsBindingAllowed); }); @@ -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, @@ -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, diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/MethodInfoExtensions.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/MethodInfoExtensions.cs index 1d9ec196fa..f1c778262c 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/MethodInfoExtensions.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/MethodInfoExtensions.cs @@ -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; } } } diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsNodeNameHelper.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsNodeNameHelper.cs index 5b9b60c7c9..7c6b247183 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsNodeNameHelper.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsNodeNameHelper.cs @@ -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}"); diff --git a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs index 62e0095508..ba557ac819 100644 --- a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs @@ -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 } } } @@ -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 } } } diff --git a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs index fc3c8f7de2..3ffb4e1dd4 100644 --- a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs @@ -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 } } } diff --git a/test/WebSites/Dummy/Dumbs/Types/Types (907).cs b/test/WebSites/Dummy/Dumbs/Types/Types (907).cs index 56a891283a..0ab361b408 100644 --- a/test/WebSites/Dummy/Dumbs/Types/Types (907).cs +++ b/test/WebSites/Dummy/Dumbs/Types/Types (907).cs @@ -55,7 +55,7 @@ public virtual bool ShouldSerializeDescription() /// public virtual bool ShouldSerializeAttributeID() { - return (AttributeID != null); + return AttributeID != null; } /// @@ -63,7 +63,7 @@ public virtual bool ShouldSerializeAttributeID() /// public virtual bool ShouldSerializePositionruby() { - return (Positionruby != null); + return Positionruby != null; } /// @@ -71,7 +71,7 @@ public virtual bool ShouldSerializePositionruby() /// public virtual bool ShouldSerializeDescriptionruby() { - return (Descriptionruby != null); + return Descriptionruby != null; } } }