in code/go/internal/validator/semantic/validate_visualizations_used_by_value.go [28:63]
func ValidateVisualizationsUsedByValue(fsys fspath.FS) specerrors.ValidationErrors {
var errs specerrors.ValidationErrors
filePaths := path.Join("kibana", "dashboard", "*.json")
objectFiles, err := pkgpath.Files(fsys, filePaths)
if err != nil {
errs = append(errs, specerrors.NewStructuredErrorf("error finding Kibana Dashboard files: %w", err))
return errs
}
for _, objectFile := range objectFiles {
filePath := objectFile.Path()
objectReferences, err := objectFile.Values(`$.references`)
if err != nil {
// no references key in dashboard json
continue
}
references, err := anyReference(objectReferences)
if err != nil {
errs = append(errs, specerrors.NewStructuredErrorf("error getting references in file: %s: %w", fsys.Path(filePath), err))
}
if len(references) > 0 {
s := fmt.Sprintf("%s (%s)", references[0].ID, references[0].Type)
for _, ref := range references[1:] {
s = fmt.Sprintf("%s, %s (%s)", s, ref.ID, ref.Type)
}
err = fmt.Errorf("references found in dashboard %s: %s", filePath, s)
errs = append(errs, specerrors.NewStructuredError(err, specerrors.CodeVisualizationByValue))
}
}
return errs
}