diff --git a/additionalProperties.go b/additionalProperties.go index d34a06e..5c312d6 100644 --- a/additionalProperties.go +++ b/additionalProperties.go @@ -41,6 +41,7 @@ func evaluateAdditionalProperties(schema *Schema, object map[string]interface{}, if !properties[propName] { result, _, _ := schema.AdditionalProperties.evaluate(propValue, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/additionalProperties/%s", propName)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/additionalProperties/%s", propName))). SetInstanceLocation(fmt.Sprintf("/%s", propName)) diff --git a/allOf.go b/allOf.go index 0698bf9..9f686b0 100644 --- a/allOf.go +++ b/allOf.go @@ -16,7 +16,7 @@ import ( // // Reference: https://json-schema.org/draft/2020-12/json-schema-core#name-allof func evaluateAllOf(schema *Schema, instance interface{}, evaluatedProps map[string]bool, evaluatedItems map[int]bool, dynamicScope *DynamicScope) ([]*EvaluationResult, *EvaluationError) { - if schema.AllOf == nil || len(schema.AllOf) == 0 { + if len(schema.AllOf) == 0 { return nil, nil // No allOf constraints to validate against. } diff --git a/anyOf.go b/anyOf.go index 367dad8..909a05a 100644 --- a/anyOf.go +++ b/anyOf.go @@ -14,7 +14,7 @@ import ( // // Reference: https://json-schema.org/draft/2020-12/json-schema-core#name-anyof func evaluateAnyOf(schema *Schema, data interface{}, evaluatedProps map[string]bool, evaluatedItems map[int]bool, dynamicScope *DynamicScope) ([]*EvaluationResult, *EvaluationError) { - if schema.AnyOf == nil || len(schema.AnyOf) == 0 { + if len(schema.AnyOf) == 0 { return nil, nil // No anyOf constraints to validate against. } diff --git a/conditional.go b/conditional.go index c7fb928..7db8cf3 100644 --- a/conditional.go +++ b/conditional.go @@ -23,6 +23,7 @@ func evaluateConditional(schema *Schema, instance interface{}, evaluatedProps ma results := []*EvaluationResult{} if ifResult != nil { + //nolint:errcheck ifResult.SetEvaluationPath("/if"). SetSchemaLocation(schema.GetSchemaLocation("/if")). SetInstanceLocation("") @@ -38,6 +39,7 @@ func evaluateConditional(schema *Schema, instance interface{}, evaluatedProps ma thenResult, thenEvaluatedProps, thenEvaluatedItems := schema.Then.evaluate(instance, dynamicScope) if thenResult != nil { + //nolint:errcheck thenResult.SetEvaluationPath("/then"). SetSchemaLocation(schema.GetSchemaLocation("/then")). SetInstanceLocation("") diff --git a/contains.go b/contains.go index f2c5d2c..e122571 100644 --- a/contains.go +++ b/contains.go @@ -28,6 +28,7 @@ func evaluateContains(schema *Schema, data []interface{}, evaluatedProps map[str result, _, _ := schema.Contains.evaluate(item, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath("/contains"). SetSchemaLocation(schema.GetSchemaLocation("/contains")). SetInstanceLocation(fmt.Sprintf("/%d", i)) diff --git a/content.go b/content.go index de500c7..f573029 100644 --- a/content.go +++ b/content.go @@ -65,6 +65,7 @@ func evaluateContent(schema *Schema, instance interface{}, evaluatedProps map[st if schema.ContentSchema != nil { result, _, _ := schema.ContentSchema.evaluate(parsedValue, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath("/contentSchema"). SetSchemaLocation(schema.GetSchemaLocation("/contentSchema")). SetInstanceLocation("") diff --git a/dependentSchemas.go b/dependentSchemas.go index 639912e..cebef04 100644 --- a/dependentSchemas.go +++ b/dependentSchemas.go @@ -15,7 +15,7 @@ import ( // // Reference: https://json-schema.org/draft/2020-12/json-schema-core#name-dependentschemas func evaluateDependentSchemas(schema *Schema, instance interface{}, evaluatedProps map[string]bool, evaluatedItems map[int]bool, dynamicScope *DynamicScope) ([]*EvaluationResult, *EvaluationError) { - if schema.DependentSchemas == nil || len(schema.DependentSchemas) == 0 { + if len(schema.DependentSchemas) == 0 { return nil, nil // No dependentSchemas constraints to validate against. } @@ -31,6 +31,7 @@ func evaluateDependentSchemas(schema *Schema, instance interface{}, evaluatedPro if depSchema != nil { result, schemaEvaluatedProps, schemaEvaluatedItems := depSchema.evaluate(object, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/dependentSchemas/%s", propName)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/dependentSchemas/%s", propName))). SetInstanceLocation(fmt.Sprintf("/%s", propName)) diff --git a/enum.go b/enum.go index c4b887f..c2aec8a 100644 --- a/enum.go +++ b/enum.go @@ -14,7 +14,7 @@ import "reflect" // // Reference: https://json-schema.org/draft/2020-12/json-schema-validation#name-enum func evaluateEnum(schema *Schema, instance interface{}) *EvaluationError { - if schema.Enum != nil && len(schema.Enum) > 0 { + if len(schema.Enum) > 0 { for _, enumValue := range schema.Enum { if reflect.DeepEqual(instance, enumValue) { return nil // Match found. diff --git a/items.go b/items.go index dede096..03995ae 100644 --- a/items.go +++ b/items.go @@ -35,6 +35,7 @@ func evaluateItems(schema *Schema, array []interface{}, evaluatedProps map[strin item := array[i] result, _, _ := schema.Items.evaluate(item, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/items/%d", i)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/items/%d", i))). SetInstanceLocation(fmt.Sprintf("/%d", i)) diff --git a/not.go b/not.go index 0875776..b40be84 100644 --- a/not.go +++ b/not.go @@ -18,6 +18,7 @@ func evaluateNot(schema *Schema, instance interface{}, evaluatedProps map[string result, _, _ := schema.Not.evaluate(instance, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath("/oneOf"). SetSchemaLocation(schema.GetSchemaLocation("/oneOf")). SetInstanceLocation("") diff --git a/oneOf.go b/oneOf.go index ae1fdbb..7f81c75 100644 --- a/oneOf.go +++ b/oneOf.go @@ -16,7 +16,7 @@ import ( // // Reference: https://json-schema.org/draft/2020-12/json-schema-core#name-oneof func evaluateOneOf(schema *Schema, instance interface{}, evaluatedProps map[string]bool, evaluatedItems map[int]bool, dynamicScope *DynamicScope) ([]*EvaluationResult, *EvaluationError) { - if schema.OneOf == nil || len(schema.OneOf) == 0 { + if len(schema.OneOf) == 0 { return nil, nil // No oneOf constraints to validate against. } diff --git a/patternProperties.go b/patternProperties.go index e50bad2..1e494dc 100644 --- a/patternProperties.go +++ b/patternProperties.go @@ -62,6 +62,7 @@ func evaluatePatternProperties(schema *Schema, object map[string]interface{}, ev // Evaluate the property value directly using the associated schema or boolean. result, _, _ := patternSchema.evaluate(propValue, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/patternProperties/%s", propName)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/patternProperties/%s", propName))). SetInstanceLocation(fmt.Sprintf("/%s", propName)) diff --git a/prefixItems.go b/prefixItems.go index e58b13c..20f5449 100644 --- a/prefixItems.go +++ b/prefixItems.go @@ -16,7 +16,7 @@ import ( // // If validation fails, it returns a EvaluationError detailing the index and discrepancy. func evaluatePrefixItems(schema *Schema, array []interface{}, evaluatedProps map[string]bool, evaluatedItems map[int]bool, dynamicScope *DynamicScope) ([]*EvaluationResult, *EvaluationError) { - if schema.PrefixItems == nil || len(schema.PrefixItems) == 0 { + if len(schema.PrefixItems) == 0 { return nil, nil // If no prefixItems are defined, there is nothing to validate against. } diff --git a/properties.go b/properties.go index c61f481..96f22f9 100644 --- a/properties.go +++ b/properties.go @@ -30,6 +30,7 @@ func evaluateProperties(schema *Schema, object map[string]interface{}, evaluated if exists { result, _, _ := propSchema.evaluate(propValue, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/properties/%s", propName)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/properties/%s", propName))). SetInstanceLocation(fmt.Sprintf("/%s", propName)) @@ -45,6 +46,7 @@ func evaluateProperties(schema *Schema, object map[string]interface{}, evaluated result, _, _ := propSchema.evaluate(nil, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/properties/%s", propName)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/properties/%s", propName))). SetInstanceLocation(fmt.Sprintf("/%s", propName)) diff --git a/propertyNames.go b/propertyNames.go index e32d8d0..d89febd 100644 --- a/propertyNames.go +++ b/propertyNames.go @@ -30,6 +30,7 @@ func evaluatePropertyNames(schema *Schema, object map[string]interface{}, evalua result, _, _ := schema.PropertyNames.evaluate(propName, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/propertyNames/%s", propName)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/propertyNames/%s", propName))). SetInstanceLocation(fmt.Sprintf("/%s", propName)) diff --git a/result.go b/result.go index 8a540cf..0110f13 100644 --- a/result.go +++ b/result.go @@ -68,7 +68,7 @@ func NewEvaluationResult(schema *Schema) *EvaluationResult { schema: schema, Valid: true, } - + //nolint:errcheck e.CollectAnnotations() return e diff --git a/unevaluatedItems.go b/unevaluatedItems.go index 52f9a52..1a4e763 100644 --- a/unevaluatedItems.go +++ b/unevaluatedItems.go @@ -34,6 +34,7 @@ func evaluateUnevaluatedItems(schema *Schema, data interface{}, evaluatedProps m if _, evaluated := evaluatedItems[i]; !evaluated { result, _, _ := schema.UnevaluatedItems.evaluate(item, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath(fmt.Sprintf("/unevaluatedItems/%d", i)). SetSchemaLocation(schema.GetSchemaLocation(fmt.Sprintf("/unevaluatedItems/%d", i))). SetInstanceLocation(fmt.Sprintf("/%d", i)) diff --git a/unevaluatedProperties.go b/unevaluatedProperties.go index b36bab9..9a179aa 100644 --- a/unevaluatedProperties.go +++ b/unevaluatedProperties.go @@ -33,6 +33,7 @@ func evaluateUnevaluatedProperties(schema *Schema, data interface{}, evaluatedPr // If property has not been evaluated, validate it against the "unevaluatedProperties" schema. result, _, _ := schema.UnevaluatedProperties.evaluate(propValue, dynamicScope) if result != nil { + //nolint:errcheck result.SetEvaluationPath("/unevaluatedProperties"). SetSchemaLocation(schema.GetSchemaLocation("/unevaluatedProperties")). SetInstanceLocation(fmt.Sprintf("/%s", propName)) diff --git a/validate.go b/validate.go index 4639a65..81e742e 100644 --- a/validate.go +++ b/validate.go @@ -18,6 +18,7 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.Boolean != nil { // Check if the schema is a boolean if err := s.evaluateBoolean(instance, evaluatedProps, evaluatedItems); err != nil { + //nolint:errcheck result.AddError(err) } } else { @@ -38,9 +39,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev refResult, props, items := s.ResolvedRef.evaluate(instance, dynamicScope) if refResult != nil { + //nolint:errcheck result.AddDetail(refResult) if !refResult.IsValid() { + //nolint:errcheck result.AddError( NewEvaluationError("$ref", "ref_mismatch", "Value does not match the reference schema"), ) @@ -65,9 +68,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev dynamicRefResult, props, items := anchorSchema.evaluate(instance, dynamicScope) if dynamicRefResult != nil { + //nolint:errcheck result.AddDetail(dynamicRefResult) if !dynamicRefResult.IsValid() { + //nolint:errcheck result.AddError( NewEvaluationError("$dynamicRef", "dynamic_ref_mismatch", "Value does not match the dynamic reference schema"), ) @@ -81,18 +86,21 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev // Validation keywords for any instance type if s.Type != nil { if err := evaluateType(s, instance); err != nil { + //nolint:errcheck result.AddError(err) } } if s.Enum != nil { if err := evaluateEnum(s, instance); err != nil { + //nolint:errcheck result.AddError(err) } } if s.Const != nil { if err := evaluateConst(s, instance); err != nil { + //nolint:errcheck result.AddError(err) } } @@ -101,9 +109,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.AllOf != nil { allOfResults, allOfError := evaluateAllOf(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, allOfResult := range allOfResults { + //nolint:errcheck result.AddDetail(allOfResult) } if allOfError != nil { + //nolint:errcheck result.AddError(allOfError) } } @@ -111,9 +121,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.AnyOf != nil { anyOfResults, anyOfError := evaluateAnyOf(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, anyOfResult := range anyOfResults { + //nolint:errcheck result.AddDetail(anyOfResult) } if anyOfError != nil { + //nolint:errcheck result.AddError(anyOfError) } } @@ -121,9 +133,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.OneOf != nil { oneOfResults, oneOfError := evaluateOneOf(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, oneOfResult := range oneOfResults { + //nolint:errcheck result.AddDetail(oneOfResult) } if oneOfError != nil { + //nolint:errcheck result.AddError(oneOfError) } } @@ -131,9 +145,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.Not != nil { notResult, notError := evaluateNot(s, instance, evaluatedProps, evaluatedItems, dynamicScope) if notResult != nil { + //nolint:errcheck result.AddDetail(notResult) } if notError != nil { + //nolint:errcheck result.AddError(notError) } } @@ -142,15 +158,17 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.If != nil || s.Then != nil || s.Else != nil { conditionalResults, conditionalError := evaluateConditional(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, conditionalResult := range conditionalResults { + //nolint:errcheck result.AddDetail(conditionalResult) } if conditionalError != nil { + //nolint:errcheck result.AddError(conditionalError) } } // Validation keywords for applying subschemas to arrays - if s.PrefixItems != nil && len(s.PrefixItems) > 0 || + if len(s.PrefixItems) > 0 || s.Items != nil || s.Contains != nil || s.MaxContains != nil || @@ -160,9 +178,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev s.UniqueItems != nil { arrayResults, arrayErrors := evaluateArray(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, arrayResult := range arrayResults { + //nolint:errcheck result.AddDetail(arrayResult) } for _, arrayError := range arrayErrors { + //nolint:errcheck result.AddError(arrayError) } } @@ -171,6 +191,7 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.MultipleOf != nil || s.Maximum != nil || s.ExclusiveMaximum != nil || s.Minimum != nil || s.ExclusiveMinimum != nil { numericErrors := evaluateNumeric(s, instance) for _, numericError := range numericErrors { + //nolint:errcheck result.AddError(numericError) } } @@ -179,6 +200,7 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.MaxLength != nil || s.MinLength != nil || s.Pattern != nil { stringErrors := evaluateString(s, instance) for _, stringError := range stringErrors { + //nolint:errcheck result.AddError(stringError) } } @@ -186,6 +208,7 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.Format != nil { formatError := evaluateFormat(s, instance) if formatError != nil { + //nolint:errcheck result.AddError(formatError) } } @@ -201,9 +224,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev len(s.DependentRequired) > 0 { objectResults, objectErrors := evaluateObject(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, objectResult := range objectResults { + //nolint:errcheck result.AddDetail(objectResult) } for _, objectError := range objectErrors { + //nolint:errcheck result.AddError(objectError) } } @@ -212,9 +237,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.DependentSchemas != nil { dependentSchemasResults, dependentSchemasError := evaluateDependentSchemas(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, dependentSchemasResult := range dependentSchemasResults { + //nolint:errcheck result.AddDetail(dependentSchemasResult) } if dependentSchemasError != nil { + //nolint:errcheck result.AddError(dependentSchemasError) } } @@ -223,9 +250,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.UnevaluatedProperties != nil { unevaluatedPropertiesResults, unevaluatedPropertiesError := evaluateUnevaluatedProperties(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, unevaluatedPropertiesResult := range unevaluatedPropertiesResults { + //nolint:errcheck result.AddDetail(unevaluatedPropertiesResult) } if unevaluatedPropertiesError != nil { + //nolint:errcheck result.AddError(unevaluatedPropertiesError) } } @@ -234,9 +263,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.UnevaluatedItems != nil { unevaluatedItemsResults, unevaluatedItemsError := evaluateUnevaluatedItems(s, instance, evaluatedProps, evaluatedItems, dynamicScope) for _, unevaluatedItemsResult := range unevaluatedItemsResults { + //nolint:errcheck result.AddDetail(unevaluatedItemsResult) } if unevaluatedItemsError != nil { + //nolint:errcheck result.AddError(unevaluatedItemsError) } } @@ -245,9 +276,11 @@ func (s *Schema) evaluate(instance interface{}, dynamicScope *DynamicScope) (*Ev if s.ContentEncoding != nil || s.ContentMediaType != nil || s.ContentSchema != nil { contentResult, contentError := evaluateContent(s, instance, evaluatedProps, evaluatedItems, dynamicScope) if contentError != nil { + //nolint:errcheck result.AddDetail(contentResult) } if contentError != nil { + //nolint:errcheck result.AddError(contentError) } } @@ -473,7 +506,7 @@ func evaluateArray(schema *Schema, data interface{}, evaluatedProps map[string]b errors := []*EvaluationError{} // Validation keywords for applying subschemas to arrays - if schema.PrefixItems != nil && len(schema.PrefixItems) > 0 { + if len(schema.PrefixItems) > 0 { prefixItemsResults, prefixItemsError := evaluatePrefixItems(schema, items, evaluatedProps, evaluatedItems, dynamicScope) if prefixItemsResults != nil {