Skip to content

Commit 31b23fc

Browse files
authored
flattenField() - include non-leaf fields (#3)
Include fields that are not declared as type=group when they contain sub-fields. Given `a` and `a.b` are both declared as keyword fields then flattenField() will now return them both. Previously the type of `a` would have been ignored because it was assumed that `a` must be a type=group. But sometimes this is not true (though it may be an invalid definition).
1 parent 807ee12 commit 31b23fc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fields.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ func flattenField(key []string, f Field) ([]Field, error) {
167167
flat = append(flat, tmpFlats...)
168168
}
169169

170+
// I would consider this to be an incorrect definition to
171+
// have sub-fields in a field not declared as a type=group.
172+
// This will include those fields in the list in order to not
173+
// mask bad definitions.
174+
if f.Type != "" && f.Type != "group" {
175+
parent := f
176+
parent.Name = strings.Join(parentName, ".")
177+
parent.Fields = nil
178+
flat = append(flat, parent)
179+
}
180+
170181
return flat, nil
171182
}
172183

0 commit comments

Comments
 (0)