Skip to content

Commit aa60ec4

Browse files
committed
Allow to show all warnings if there is nested type
1 parent c0dbfbb commit aa60ec4

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

internal/fields/mappings.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ func validateConstantKeywordField(path string, preview, actual map[string]any) (
485485

486486
func (v *MappingValidator) compareMappings(path string, preview, actual map[string]any) multierror.Error {
487487
var errs multierror.Error
488+
isNestedParent := false
488489

489490
isConstantKeywordType, err := validateConstantKeywordField(path, preview, actual)
490491
if err != nil {
@@ -496,8 +497,8 @@ func (v *MappingValidator) compareMappings(path string, preview, actual map[stri
496497

497498
if v.specVersion.LessThan(semver3_0_1) {
498499
if mappingParameter("type", actual) == "nested" {
499-
logger.Debugf("Skip validation of nested object (spec version %s): %s", path, v.specVersion)
500-
return nil
500+
logger.Warnf("Skip validation of nested object (spec version %s): %s", path, v.specVersion)
501+
isNestedParent = true
501502
}
502503
}
503504

@@ -512,6 +513,10 @@ func (v *MappingValidator) compareMappings(path string, preview, actual map[stri
512513
logger.Debugf("Pending to validate with the dynamic templates defined the path: %s", path)
513514
return nil
514515
} else if !isObject(preview) {
516+
if isNestedParent {
517+
logger.Warnf("skipped due to field of type \"nested\": not found properties in preview mappings for path %q", path)
518+
return nil
519+
}
515520
errs = append(errs, fmt.Errorf("not found properties in preview mappings for path: %s", path))
516521
return errs.Unique()
517522
}
@@ -527,6 +532,11 @@ func (v *MappingValidator) compareMappings(path string, preview, actual map[stri
527532
compareErrors := v.compareMappings(path, previewProperties, actualProperties)
528533
errs = append(errs, compareErrors...)
529534

535+
if isNestedParent {
536+
logger.Warnf("skip validation due to parent type nested:\n%s", errs.Unique().Error())
537+
return nil
538+
}
539+
530540
if len(errs) == 0 {
531541
return nil
532542
}
@@ -556,6 +566,10 @@ func (v *MappingValidator) compareMappings(path string, preview, actual map[stri
556566
// Compare and validate the elements under "properties": objects or fields and its parameters
557567
propertiesErrs := v.validateObjectProperties(path, containsMultifield, actual, preview)
558568
errs = append(errs, propertiesErrs...)
569+
if isNestedParent {
570+
logger.Warnf("skip validation due to parent type nested:\n%s", errs.Unique().Error())
571+
return nil
572+
}
559573
if len(errs) == 0 {
560574
return nil
561575
}
@@ -583,9 +597,8 @@ func (v *MappingValidator) validateObjectProperties(path string, containsMultifi
583597
logger.Debugf("field %q is an empty object and it does not exist in the preview", currentPath)
584598
continue
585599
}
586-
errs = append(errs,
587-
v.validateMappingsNotInPreview(currentPath, childField)...,
588-
)
600+
ecsErrors := v.validateMappingsNotInPreview(currentPath, childField)
601+
errs = append(errs, ecsErrors...)
589602
}
590603

591604
continue
@@ -626,6 +639,7 @@ func (v *MappingValidator) validateMappingsNotInPreview(currentPath string, chil
626639
}
627640

628641
if isLocalFieldTypeArray(fieldPath, v.Schema) && v.specVersion.LessThan(semver2_0_0) {
642+
// Example: https://github.com/elastic/elastic-package/blob/25344b16c6eabe1478067fc55966258a59c769cd/test/packages/parallel/nginx/data_stream/access/fields/fields.yml#L5
629643
logger.Debugf("Found field definition with type array, skipping path: %q", fieldPath)
630644
continue
631645
}

0 commit comments

Comments
 (0)