mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +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 {
|
if prop, ok := s.Properties[k]; ok {
|
||||||
prune(v, &prop)
|
prune(v, &prop)
|
||||||
} else {
|
} else if s.AdditionalProperties != nil {
|
||||||
skipPrune(v, nil)
|
prune(v, s.AdditionalProperties.Structural)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
|
@ -84,6 +84,12 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecifiedObject": {"unspecified": "bar"},
|
"unspecifiedObject": {"unspecified": "bar"},
|
||||||
"pruning": {"unspecified": "bar"},
|
"pruning": {"unspecified": "bar"},
|
||||||
"preserving": {"unspecified": "bar"}
|
"preserving": {"unspecified": "bar"}
|
||||||
|
},
|
||||||
|
"preservingAdditionalProperties": {
|
||||||
|
"foo": {
|
||||||
|
"specified": {"unspecified":"bar"},
|
||||||
|
"unspecified": "bar"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, schema: &structuralschema.Structural{
|
`, 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: `
|
}, expected: `
|
||||||
{
|
{
|
||||||
@ -133,6 +153,11 @@ func TestPrune(t *testing.T) {
|
|||||||
"unspecifiedObject": {"unspecified": "bar"},
|
"unspecifiedObject": {"unspecified": "bar"},
|
||||||
"pruning": {},
|
"pruning": {},
|
||||||
"preserving": {"unspecified": "bar"}
|
"preserving": {"unspecified": "bar"}
|
||||||
|
},
|
||||||
|
"preservingAdditionalProperties": {
|
||||||
|
"foo": {
|
||||||
|
"specified": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`},
|
`},
|
||||||
|
Loading…
Reference in New Issue
Block a user