diff --git a/Directory.Build.props b/Directory.Build.props index 9784edbb4..2d54a4ded 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -48,7 +48,6 @@ [IDE0059] Unnecessary assignment of a value [IDE0060] Remove unused parameter [IDE0090] 'new' expression can be simplified - [IDE0100] Remove redundant equality [IDE0130] Namespace does not match folder structure [IDE0160] Convert to block scoped namespace [IDE0290] Use primary constructor @@ -59,7 +58,7 @@ [CA1870] Use a cached 'SearchValues' instance for improved searching performance [CA2263] Prefer the generic overload 'System.Enum.GetValues()' --> - $(NoWarn);IDE0008;IDE0021;IDE0022;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0057;IDE0059;IDE0060;IDE0090;IDE0100;IDE0130;IDE0160;IDE0290;CA1200;CA1510;CA1716;CA1720;CA1870;CA2263 + $(NoWarn);IDE0008;IDE0021;IDE0022;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0057;IDE0059;IDE0060;IDE0090;IDE0130;IDE0160;IDE0290;CA1200;CA1510;CA1716;CA1720;CA1870;CA2263 diff --git a/src/NJsonSchema.CodeGeneration.CSharp/CSharpValueGenerator.cs b/src/NJsonSchema.CodeGeneration.CSharp/CSharpValueGenerator.cs index 78c16d0d9..592a90313 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/CSharpValueGenerator.cs +++ b/src/NJsonSchema.CodeGeneration.CSharp/CSharpValueGenerator.cs @@ -59,7 +59,7 @@ public CSharpValueGenerator(CSharpGeneratorSettings settings) var isOptional = schema is JsonSchemaProperty { IsRequired: false }; schema = schema.ActualSchema; - if (schema != null && allowsNull == false && isOptional == false) + if (schema != null && !allowsNull && !isOptional) { if (schema.Type.IsArray() || schema.Type.IsObject()) diff --git a/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs b/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs index a76846d30..8a8ee6854 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs +++ b/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs @@ -60,10 +60,8 @@ public PropertyModel( /// Gets a value indicating whether this is an array property which cannot be null. public bool HasSetter => - (_property.IsNullable(_settings.SchemaType) == false && ( - (_property.ActualTypeSchema.IsArray && _settings.GenerateImmutableArrayProperties) || - (_property.ActualTypeSchema.IsDictionary && _settings.GenerateImmutableDictionaryProperties) - )) == false; + _property.IsNullable(_settings.SchemaType) || (!_property.ActualTypeSchema.IsArray || !_settings.GenerateImmutableArrayProperties) && + (!_property.ActualTypeSchema.IsDictionary || !_settings.GenerateImmutableDictionaryProperties); /// Gets the json property required. public string JsonPropertyRequiredCode diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/Models/ClassTemplateModel.cs b/src/NJsonSchema.CodeGeneration.TypeScript/Models/ClassTemplateModel.cs index 4c1bc4a2e..c9c2ccc99 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/Models/ClassTemplateModel.cs +++ b/src/NJsonSchema.CodeGeneration.TypeScript/Models/ClassTemplateModel.cs @@ -37,8 +37,7 @@ public ClassTemplateModel(string typeName, string discriminatorName, ClassName = typeName; Properties = _schema.ActualProperties.Values - .Where(v => settings.TypeStyle == TypeScriptTypeStyle.Interface || - v.IsInheritanceDiscriminator == false) + .Where(v => settings.TypeStyle == TypeScriptTypeStyle.Interface || !v.IsInheritanceDiscriminator) .Select(property => new PropertyModel(this, property, ClassName, _resolver, _settings)) .ToList(); } diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptTypeResolver.cs b/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptTypeResolver.cs index c0665e663..e4f12f7c7 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptTypeResolver.cs +++ b/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptTypeResolver.cs @@ -298,8 +298,8 @@ private string ResolveArrayOrTuple(JsonSchema schema, string? typeNameHint, bool { if (schema.Item != null) { - var isObject = schema.Item.ActualSchema.Type.IsObject() == true; - var isDictionary = schema.Item.ActualSchema.IsDictionary == true; + var isObject = schema.Item.ActualSchema.Type.IsObject(); + var isDictionary = schema.Item.ActualSchema.IsDictionary; var prefix = addInterfacePrefix && SupportsConstructorConversion(schema.Item) && isObject && !isDictionary ? "I" : ""; if (Settings.UseLeafType) diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptValueGenerator.cs b/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptValueGenerator.cs index bad5e5b65..b6f00d82e 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptValueGenerator.cs +++ b/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptValueGenerator.cs @@ -67,7 +67,7 @@ schema.Format is not null && } } - if (!allowsNull && schema is JsonSchemaProperty { IsRequired: false } == false) + if (!allowsNull && schema is not JsonSchemaProperty { IsRequired: false }) { if (typeResolver.GeneratesType(schema) && !schema.ActualTypeSchema.IsEnumeration && diff --git a/src/NJsonSchema.CodeGeneration/Models/PropertyModelBase.cs b/src/NJsonSchema.CodeGeneration/Models/PropertyModelBase.cs index a6fcdcd44..bea8168f8 100644 --- a/src/NJsonSchema.CodeGeneration/Models/PropertyModelBase.cs +++ b/src/NJsonSchema.CodeGeneration/Models/PropertyModelBase.cs @@ -74,7 +74,7 @@ protected PropertyModelBase( protected string GetTypeNameHint() { var propertyName = PropertyName; - if (_property.IsEnumeration == false) + if (!_property.IsEnumeration) { return propertyName; } diff --git a/src/NJsonSchema.CodeGeneration/TypeResolverBase.cs b/src/NJsonSchema.CodeGeneration/TypeResolverBase.cs index 7887bbacc..a24583e26 100644 --- a/src/NJsonSchema.CodeGeneration/TypeResolverBase.cs +++ b/src/NJsonSchema.CodeGeneration/TypeResolverBase.cs @@ -137,7 +137,7 @@ protected string ResolveDictionaryValueType(JsonSchema schema, string fallbackTy return Resolve(schema.AdditionalPropertiesSchema, schema.AdditionalPropertiesSchema.ActualSchema.IsNullable(_settings.SchemaType), null); } - if (schema.AllowAdditionalProperties == false && schema.PatternProperties.Any()) + if (!schema.AllowAdditionalProperties && schema.PatternProperties.Any()) { var valueTypes = new HashSet(schema.PatternProperties .Select(p => Resolve(p.Value, p.Value.IsNullable(_settings.SchemaType), null)) diff --git a/src/NJsonSchema.CodeGeneration/ValueGeneratorBase.cs b/src/NJsonSchema.CodeGeneration/ValueGeneratorBase.cs index 7d54ef6f9..ee29157a3 100644 --- a/src/NJsonSchema.CodeGeneration/ValueGeneratorBase.cs +++ b/src/NJsonSchema.CodeGeneration/ValueGeneratorBase.cs @@ -59,7 +59,7 @@ protected ValueGeneratorBase(CodeGeneratorSettingsBase settings) return GetEnumDefaultValue(schema, actualSchema, typeNameHint, typeResolver); } - if (schema.Type.IsString() && (schema.Format == null || _unsupportedFormatStrings.Contains(schema.Format) == false)) + if (schema.Type.IsString() && (schema.Format == null || !_unsupportedFormatStrings.Contains(schema.Format))) { return GetDefaultAsStringLiteral(schema); } diff --git a/src/NJsonSchema.NewtonsoftJson/Converters/JsonExceptionConverter.cs b/src/NJsonSchema.NewtonsoftJson/Converters/JsonExceptionConverter.cs index cb1864cba..e50108ba1 100644 --- a/src/NJsonSchema.NewtonsoftJson/Converters/JsonExceptionConverter.cs +++ b/src/NJsonSchema.NewtonsoftJson/Converters/JsonExceptionConverter.cs @@ -121,7 +121,7 @@ public override bool CanConvert(Type objectType) if (jObject.TryGetValue("discriminator", StringComparison.OrdinalIgnoreCase, out JToken? token)) { var discriminator = token.Value(); - if (objectType.Name.Equals(discriminator, StringComparison.Ordinal) == false) + if (!objectType.Name.Equals(discriminator, StringComparison.Ordinal)) { var exceptionType = Type.GetType("System." + discriminator, false); if (exceptionType != null) diff --git a/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonReflectionService.cs b/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonReflectionService.cs index ce14675b2..9f9e6f781 100644 --- a/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonReflectionService.cs +++ b/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonReflectionService.cs @@ -153,7 +153,7 @@ public override string GetPropertyName(ContextualAccessorInfo accessorInfo, Json private void LoadPropertyOrField(JsonProperty jsonProperty, ContextualAccessorInfo accessorInfo, Type parentType, JsonSchema parentSchema, NewtonsoftJsonSchemaGeneratorSettings settings, JsonSchemaGenerator schemaGenerator, JsonSchemaResolver schemaResolver) { var propertyTypeDescription = ((IReflectionService)this).GetDescription(accessorInfo.AccessorType, settings); - if (jsonProperty.Ignored == false && schemaGenerator.IsPropertyIgnoredBySettings(accessorInfo) == false) + if (!jsonProperty.Ignored && !schemaGenerator.IsPropertyIgnoredBySettings(accessorInfo)) { var propertyName = GetPropertyName(jsonProperty, accessorInfo, settings); var propertyAlreadyExists = parentSchema.Properties.ContainsKey(propertyName); diff --git a/src/NJsonSchema/Generation/JsonSchemaGenerator.cs b/src/NJsonSchema/Generation/JsonSchemaGenerator.cs index f21ea574e..c615be146 100644 --- a/src/NJsonSchema/Generation/JsonSchemaGenerator.cs +++ b/src/NJsonSchema/Generation/JsonSchemaGenerator.cs @@ -811,8 +811,8 @@ private bool TryHandleSpecialTypes(TSchemaType schema, ContextualTy return true; } - if (contextualType.OriginalType.IsAssignableToTypeName(nameof(JArray), TypeNameStyle.Name) == false && - (contextualType.OriginalType.IsAssignableToTypeName(nameof(JToken), TypeNameStyle.Name) == true || + if (!contextualType.OriginalType.IsAssignableToTypeName(nameof(JArray), TypeNameStyle.Name) && + (contextualType.OriginalType.IsAssignableToTypeName(nameof(JToken), TypeNameStyle.Name) || contextualType.OriginalType == typeof(object))) { if (Settings.SchemaType == SchemaType.Swagger2) @@ -1176,9 +1176,9 @@ public void AddProperty( } if (hasRequiredAttribute && - propertyTypeDescription.IsEnum == false && + !propertyTypeDescription.IsEnum && propertyTypeDescription.Type == JsonObjectType.String && - requiredAttribute.TryGetPropertyValue("AllowEmptyStrings", false) == false) + !requiredAttribute.TryGetPropertyValue("AllowEmptyStrings", false)) { propertySchema.MinLength = 1; } @@ -1230,7 +1230,7 @@ public virtual bool IsPropertyIgnored(ContextualAccessorInfo accessorInfo, Type return true; } - if (accessorInfo.IsAttributeDefined(true) == false && + if (!accessorInfo.IsAttributeDefined(true) && HasDataContractAttribute(parentType) && GetDataMemberAttribute(accessorInfo, parentType) == null) { diff --git a/src/NJsonSchema/Generation/ReflectionServiceBase.cs b/src/NJsonSchema/Generation/ReflectionServiceBase.cs index 447c67278..ebfd9d3ee 100644 --- a/src/NJsonSchema/Generation/ReflectionServiceBase.cs +++ b/src/NJsonSchema/Generation/ReflectionServiceBase.cs @@ -249,8 +249,7 @@ public virtual bool IsNullable(ContextualType contextualType, ReferenceTypeNullH var isValueType = contextualType.Type != typeof(string) && contextualType.TypeInfo.IsValueType; - return isValueType == false && - defaultReferenceTypeNullHandling != ReferenceTypeNullHandling.NotNull; + return !isValueType && defaultReferenceTypeNullHandling != ReferenceTypeNullHandling.NotNull; } /// Checks whether the give type is a string enum. diff --git a/src/NJsonSchema/Generation/SystemTextJsonReflectionService.cs b/src/NJsonSchema/Generation/SystemTextJsonReflectionService.cs index 8693f6a2d..17e4ff93c 100644 --- a/src/NJsonSchema/Generation/SystemTextJsonReflectionService.cs +++ b/src/NJsonSchema/Generation/SystemTextJsonReflectionService.cs @@ -30,8 +30,8 @@ public override void GenerateProperties(JsonSchema schema, ContextualType contex } if (accessorInfo.MemberInfo is PropertyInfo propertyInfo && - (propertyInfo.GetMethod == null || propertyInfo.GetMethod.IsPrivate == true || propertyInfo.GetMethod.IsStatic == true) && - (propertyInfo.SetMethod == null || propertyInfo.SetMethod.IsPrivate == true || propertyInfo.SetMethod.IsStatic == true) && + (propertyInfo.GetMethod == null || propertyInfo.GetMethod.IsPrivate || propertyInfo.GetMethod.IsStatic) && + (propertyInfo.SetMethod == null || propertyInfo.SetMethod.IsPrivate || propertyInfo.SetMethod.IsStatic) && !propertyInfo.IsDefined(typeof(DataMemberAttribute))) { continue; @@ -99,7 +99,7 @@ public override void GenerateProperties(JsonSchema schema, ContextualType contex schema.RequiredProperties.Add(propertyName); } - var isNullable = propertyTypeDescription.IsNullable && hasRequiredAttribute == false; + var isNullable = propertyTypeDescription.IsNullable && !hasRequiredAttribute; // TODO: Add default value schemaGenerator.AddProperty(schema, accessorInfo, propertyTypeDescription, propertyName, requiredAttribute, hasRequiredAttribute, isNullable, null, schemaResolver); diff --git a/src/NJsonSchema/JsonReferenceResolver.cs b/src/NJsonSchema/JsonReferenceResolver.cs index 67ef1bb04..72e6f69e2 100644 --- a/src/NJsonSchema/JsonReferenceResolver.cs +++ b/src/NJsonSchema/JsonReferenceResolver.cs @@ -312,7 +312,7 @@ private async Task ResolveUrlReferenceWithAlreadyResolvedCheckAs foreach (var member in obj .GetType() .GetContextualAccessors() - .Where(p => p.IsAttributeDefined(true) == false)) + .Where(p => !p.IsAttributeDefined(true))) { var pathSegment = member.GetName(); if (pathSegment == firstSegment) diff --git a/src/NJsonSchema/JsonSchema.Reference.cs b/src/NJsonSchema/JsonSchema.Reference.cs index 534ced1c8..125511ba3 100644 --- a/src/NJsonSchema/JsonSchema.Reference.cs +++ b/src/NJsonSchema/JsonSchema.Reference.cs @@ -51,7 +51,7 @@ public virtual JsonSchema ActualTypeSchema _patternProperties.Count == 0 && AdditionalPropertiesSchema == null && MultipleOf == null && - IsEnumeration == false && + !IsEnumeration && _allOf.Count == 1 && _allOf.Any(s => s.HasReference); @@ -64,7 +64,7 @@ public virtual JsonSchema ActualTypeSchema _patternProperties.Count == 0 && AdditionalPropertiesSchema == null && MultipleOf == null && - IsEnumeration == false && + !IsEnumeration && _oneOf.Count == 1 && _oneOf.Any(s => s.HasReference); @@ -77,7 +77,7 @@ public virtual JsonSchema ActualTypeSchema _patternProperties.Count == 0 && AdditionalPropertiesSchema == null && MultipleOf == null && - IsEnumeration == false && + !IsEnumeration && _anyOf.Count == 1 && _anyOf.Any(s => s.HasReference); @@ -91,7 +91,7 @@ static void ThrowInvalidOperationException(string message) throw new InvalidOperationException(message); } - if (checkedSchemas.Contains(this) == true) + if (checkedSchemas.Contains(this)) { ThrowInvalidOperationException("Cyclic references detected."); } diff --git a/src/NJsonSchema/JsonSchema.cs b/src/NJsonSchema/JsonSchema.cs index 3dd9ca5f2..f17a360a4 100644 --- a/src/NJsonSchema/JsonSchema.cs +++ b/src/NJsonSchema/JsonSchema.cs @@ -808,7 +808,7 @@ public JsonSchema? AdditionalPropertiesSchema _patternProperties.Count == 0 && AdditionalPropertiesSchema == null && MultipleOf == null && - IsEnumeration == false; + !IsEnumeration; #endregion diff --git a/src/NJsonSchema/JsonSchemaProperty.cs b/src/NJsonSchema/JsonSchemaProperty.cs index 2f2012840..ceb3aa63c 100644 --- a/src/NJsonSchema/JsonSchemaProperty.cs +++ b/src/NJsonSchema/JsonSchemaProperty.cs @@ -93,7 +93,7 @@ public bool IsRequired /// true if the type can be null. public override bool IsNullable(SchemaType schemaType) { - if (schemaType == SchemaType.Swagger2 && IsRequired == false) + if (schemaType == SchemaType.Swagger2 && !IsRequired) { return true; }