Skip to content

Commit

Permalink
Do not add as exception fields leaf objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodm committed Dec 13, 2024
1 parent b088e6f commit 50ac264
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/fields/exception_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (v *Validator) listExceptionFieldsMapElement(root string, elem common.MapSt
default:
if skipLeafOfObject(root, name, v.specVersion, v.Schema) {
// Till some versions we skip some validations on leaf of objects, check if it is the case.
all = append(all, root)
break
}

Expand Down Expand Up @@ -124,6 +123,7 @@ func (v *Validator) parseExceptionField(key string, definition FieldDefinition,
return v.parseExceptionField(key, definition, val)
case definition.Type == "object" && definition.ObjectType == "":
// Legacy mapping, ambiguous definition not allowed by recent versions of the spec, ignore it.
logger.Warnf("Skip legacy mapping: object field without \"object_type\" parameter: %q", key)
return []string{key}
}

Expand Down
14 changes: 7 additions & 7 deletions internal/fields/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func getMappingDefinitionsField(field string, definition map[string]any) (map[st
anyValue := definition[field]
object, ok := anyValue.(map[string]any)
if !ok {
return nil, fmt.Errorf("unexpected type found for %s: %T ", field, anyValue)
return nil, fmt.Errorf("unexpected type found for %q: %T ", field, anyValue)
}
return object, nil
}
Expand Down Expand Up @@ -493,22 +493,22 @@ func (v *MappingValidator) compareMappings(path string, preview, actual map[stri
}

if slices.Contains(v.exceptionFields, path) {
logger.Warnf("Found exception field, skip its validation: %s", path)
logger.Warnf("Found exception field, skip its validation: %q", path)
return nil
}

if isObjectFullyDynamic(actual) {
logger.Debugf("Dynamic object found but no fields ingested under path: %s.*", path)
logger.Debugf("Dynamic object found but no fields ingested under path: \"%s.*\"", path)
return nil
}

if isObject(actual) {
if isObjectFullyDynamic(preview) {
// TODO: Skip for now, it should be required to compare with dynamic templates
logger.Debugf("Pending to validate with the dynamic templates defined the path: %s", path)
logger.Debugf("Pending to validate with the dynamic templates defined the path: %q", path)
return nil
} else if !isObject(preview) {
errs = append(errs, fmt.Errorf("not found properties in preview mappings for path: %s", path))
errs = append(errs, fmt.Errorf("not found properties in preview mappings for path: %q", path))
return errs.Unique()
}
previewProperties, err := getMappingDefinitionsField("properties", preview)
Expand All @@ -531,7 +531,7 @@ func (v *MappingValidator) compareMappings(path string, preview, actual map[stri
containsMultifield := isMultiFields(actual)
if containsMultifield {
if !isMultiFields(preview) {
errs = append(errs, fmt.Errorf("not found multi_fields in preview mappings for path: %s", path))
errs = append(errs, fmt.Errorf("not found multi_fields in preview mappings for path: %q", path))
return errs.Unique()
}
previewFields, err := getMappingDefinitionsField("fields", preview)
Expand Down Expand Up @@ -604,7 +604,7 @@ func (v *MappingValidator) validateMappingsNotInPreview(currentPath string, chil

for fieldPath, object := range flattenFields {
if slices.Contains(v.exceptionFields, fieldPath) {
logger.Warnf("Found exception field, skip its validation: %s", fieldPath)
logger.Warnf("Found exception field, skip its validation: %q", fieldPath)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/fields/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestComparingMappings(t *testing.T) {
},
schema: []FieldDefinition{},
expectedErrors: []string{
`not found multi_fields in preview mappings for path: foo`,
`not found multi_fields in preview mappings for path: "foo"`,
},
},
{
Expand Down

0 comments on commit 50ac264

Please sign in to comment.