Fix regression pruning array fields with x-kubernetes-preserve-unknown-fields: true

This commit is contained in:
Jordan Liggitt 2022-01-21 14:06:49 -05:00
parent e7e58de49f
commit acb8d4ed20
2 changed files with 9 additions and 3 deletions

View File

@ -189,7 +189,7 @@ func skipPrune(x interface{}, s *structuralschema.Structural, opts *PruneOptions
case []interface{}:
for i, v := range x {
opts.appendIndex(i)
prune(v, s.Items, opts)
skipPrune(v, s.Items, opts)
opts.parentPath = opts.parentPath[:origPathLen]
}
default:

View File

@ -88,7 +88,8 @@ func TestPrune(t *testing.T) {
"unspecified": "bar",
"unspecifiedObject": {"unspecified": "bar"},
"pruning": {"unspecified": "bar"},
"preserving": {"unspecified": "bar"}
"preserving": {"unspecified": "bar"},
"preservingUnknownType": [{"foo":true},{"bar":true}]
},
"preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": {
"foo": {
@ -129,6 +130,10 @@ func TestPrune(t *testing.T) {
Generic: structuralschema.Generic{Type: "object"},
Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
},
"preservingUnknownType": {
Generic: structuralschema.Generic{Type: ""},
Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
},
"pruning": {
Generic: structuralschema.Generic{Type: "object"},
},
@ -177,7 +182,8 @@ func TestPrune(t *testing.T) {
"unspecified": "bar",
"unspecifiedObject": {"unspecified": "bar"},
"pruning": {},
"preserving": {"unspecified": "bar"}
"preserving": {"unspecified": "bar"},
"preservingUnknownType": [{"foo":true},{"bar":true}]
},
"preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": {
"foo": {