Skip to content

Commit d817ab6

Browse files
committed
Keep empty fields for fields validation, but not for documentation
1 parent 3a378da commit d817ab6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

internal/docs/exported_fields.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func renderExportedFields(fieldsParentDir string) (string, error) {
2727
// Keep External parameter when rendering fields, so we can render
2828
// documentation for empty groups imported from ECS, for backwards compatibility.
2929
KeepExternal: true,
30+
31+
// SkipEmptyFields parameter when rendering fields. In other cases we want to
32+
// keep them to accept them for validation.
33+
SkipEmptyFields: true,
3034
}
3135
validator, err := fields.CreateValidatorForDirectory(fieldsParentDir, fields.WithInjectFieldsOptions(injectOptions))
3236
if err != nil {

internal/fields/dependency_manager.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ type InjectFieldsOptions struct {
145145
// in previous versions on lazy resolution of external fields.
146146
KeepExternal bool
147147

148+
// SkipEmptyFields can be set to true to skip empty groups when injecting fields.
149+
SkipEmptyFields bool
150+
148151
root string
149152
}
150153

@@ -210,7 +213,7 @@ func (dm *DependencyManager) injectFieldsWithOptions(defs []common.MapStr, optio
210213
}
211214
}
212215

213-
if skipField(def) {
216+
if options.SkipEmptyFields && skipField(def) {
214217
continue
215218
}
216219
updated = append(updated, def)

0 commit comments

Comments
 (0)