From d817ab63cd7c1978b56b39ef182e381362c7b5cf Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 3 Jul 2023 16:35:30 +0200 Subject: [PATCH] Keep empty fields for fields validation, but not for documentation --- internal/docs/exported_fields.go | 4 ++++ internal/fields/dependency_manager.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/docs/exported_fields.go b/internal/docs/exported_fields.go index d5bd2a66a..df5830484 100644 --- a/internal/docs/exported_fields.go +++ b/internal/docs/exported_fields.go @@ -27,6 +27,10 @@ func renderExportedFields(fieldsParentDir string) (string, error) { // Keep External parameter when rendering fields, so we can render // documentation for empty groups imported from ECS, for backwards compatibility. KeepExternal: true, + + // SkipEmptyFields parameter when rendering fields. In other cases we want to + // keep them to accept them for validation. + SkipEmptyFields: true, } validator, err := fields.CreateValidatorForDirectory(fieldsParentDir, fields.WithInjectFieldsOptions(injectOptions)) if err != nil { diff --git a/internal/fields/dependency_manager.go b/internal/fields/dependency_manager.go index 5841dd954..da6cdf63a 100644 --- a/internal/fields/dependency_manager.go +++ b/internal/fields/dependency_manager.go @@ -145,6 +145,9 @@ type InjectFieldsOptions struct { // in previous versions on lazy resolution of external fields. KeepExternal bool + // SkipEmptyFields can be set to true to skip empty groups when injecting fields. + SkipEmptyFields bool + root string } @@ -210,7 +213,7 @@ func (dm *DependencyManager) injectFieldsWithOptions(defs []common.MapStr, optio } } - if skipField(def) { + if options.SkipEmptyFields && skipField(def) { continue } updated = append(updated, def)