fix: inherit issue when parent after inherits (#2586)

* fix: inherit issue when parent after inherits

* chore: add more tests
This commit is contained in:
Kevin Wan
2022-11-10 22:13:05 +08:00
committed by GitHub
parent 4b071f4c33
commit e3e08a7396
2 changed files with 115 additions and 12 deletions

View File

@@ -70,21 +70,33 @@ func (rv recursiveValuer) Value(key string) (interface{}, bool) {
return nil, false
}
if vm, ok := val.(map[string]interface{}); ok {
if parent := rv.Parent(); parent != nil {
pv, pok := parent.Value(key)
if pok {
if pm, ok := pv.(map[string]interface{}); ok {
for k, v := range vm {
pm[k] = v
}
return pm, true
}
}
vm, ok := val.(map[string]interface{})
if !ok {
return val, true
}
parent := rv.Parent()
if parent == nil {
return val, true
}
pv, ok := parent.Value(key)
if !ok {
return val, true
}
pm, ok := pv.(map[string]interface{})
if !ok {
return val, true
}
for k, v := range pm {
if _, ok := vm[k]; !ok {
vm[k] = v
}
}
return val, true
return vm, true
}
// Parent get the parent valuer from rv.