Skip to content

Commit

Permalink
flattenField() - include non-leaf fields (#3)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
andrewkroh authored Jun 27, 2023
1 parent 807ee12 commit 31b23fc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ func flattenField(key []string, f Field) ([]Field, error) {
flat = append(flat, tmpFlats...)
}

// I would consider this to be an incorrect definition to
// have sub-fields in a field not declared as a type=group.
// This will include those fields in the list in order to not
// mask bad definitions.
if f.Type != "" && f.Type != "group" {
parent := f
parent.Name = strings.Join(parentName, ".")
parent.Fields = nil
flat = append(flat, parent)
}

return flat, nil
}

Expand Down

0 comments on commit 31b23fc

Please sign in to comment.