mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
apiextensions: fix pruning inside additionalProperties
This commit is contained in:
parent
3f7c6294f0
commit
f590120d0f
@ -95,8 +95,8 @@ func skipPrune(x interface{}, s *structuralschema.Structural) {
|
||||
}
|
||||
if prop, ok := s.Properties[k]; ok {
|
||||
prune(v, &prop)
|
||||
} else {
|
||||
skipPrune(v, nil)
|
||||
} else if s.AdditionalProperties != nil {
|
||||
prune(v, s.AdditionalProperties.Structural)
|
||||
}
|
||||
}
|
||||
case []interface{}:
|
||||
|
@ -84,6 +84,12 @@ func TestPrune(t *testing.T) {
|
||||
"unspecifiedObject": {"unspecified": "bar"},
|
||||
"pruning": {"unspecified": "bar"},
|
||||
"preserving": {"unspecified": "bar"}
|
||||
},
|
||||
"preservingAdditionalProperties": {
|
||||
"foo": {
|
||||
"specified": {"unspecified":"bar"},
|
||||
"unspecified": "bar"
|
||||
}
|
||||
}
|
||||
}
|
||||
`, schema: &structuralschema.Structural{
|
||||
@ -117,6 +123,20 @@ func TestPrune(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
"preservingAdditionalProperties": {
|
||||
Extensions: structuralschema.Extensions{XPreserveUnknownFields: true},
|
||||
Generic: structuralschema.Generic{
|
||||
Type: "object",
|
||||
AdditionalProperties: &structuralschema.StructuralOrBool{
|
||||
Structural: &structuralschema.Structural{
|
||||
Generic: structuralschema.Generic{Type: "object"},
|
||||
Properties: map[string]structuralschema.Structural{
|
||||
"specified": {Generic: structuralschema.Generic{Type: "object"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, expected: `
|
||||
{
|
||||
@ -133,6 +153,11 @@ func TestPrune(t *testing.T) {
|
||||
"unspecifiedObject": {"unspecified": "bar"},
|
||||
"pruning": {},
|
||||
"preserving": {"unspecified": "bar"}
|
||||
},
|
||||
"preservingAdditionalProperties": {
|
||||
"foo": {
|
||||
"specified": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
`},
|
||||
|
Loading…
Reference in New Issue
Block a user