Skip to content

Commit

Permalink
Keep empty fields for fields validation, but not for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Jul 3, 2023
1 parent 3a378da commit d817ab6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/docs/exported_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion internal/fields/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d817ab6

Please sign in to comment.