@@ -126,10 +126,21 @@ function dedupFields(fields: Fields): Fields {
126126 if (
127127 // only merge if found is a group and field is object, nested, or group.
128128 // Or if found is object, or nested, and field is a group.
129- // This is to avoid merging two objects, or nested, or object with a nested.
129+ // This is to avoid merging two objects, or two nested, or object with a nested.
130+
131+ // we do not need to check for group-nested in this part because `field` will never have group-nested
132+ // it can only exist on `found`
130133 ( found . type === 'group' &&
131134 ( field . type === 'object' || field . type === 'nested' || field . type === 'group' ) ) ||
132- ( ( found . type === 'object' || found . type === 'nested' ) && field . type === 'group' )
135+ // as part of the loop we will be marking found.type as group-nested so found could be group-nested if it was
136+ // already processed. If we had an explicit definition of nested, and it showed up before a descendant field:
137+ // - name: a
138+ // type: nested
139+ // - name: a.b
140+ // type: keyword
141+ // then found.type will be nested and not group-nested because it won't have any fields yet until a.b is processed
142+ ( ( found . type === 'object' || found . type === 'nested' || found . type === 'group-nested' ) &&
143+ field . type === 'group' )
133144 ) {
134145 // if the new field has properties let's dedup and concat them with the already existing found variable in
135146 // the array
@@ -148,10 +159,10 @@ function dedupFields(fields: Fields): Fields {
148159 // supposed to be `nested` for when the template is actually generated
149160 if ( found . type === 'nested' || field . type === 'nested' ) {
150161 found . type = 'group-nested' ;
151- } else {
152- // found was either `group` already or `object` so just set it to `group`
162+ } else if ( found . type === 'object' ) {
153163 found . type = 'group' ;
154164 }
165+ // found.type could be group-nested or group, in those cases just leave it
155166 }
156167 // we need to merge in other properties (like `dynamic`) that might exist
157168 Object . assign ( found , importantFieldProps ) ;
0 commit comments