apiextensions: fix pruning inside additionalProperties

This commit is contained in:
Dr. Stefan Schimanski 2019-06-07 17:02:05 +02:00
parent 3f7c6294f0
commit f590120d0f
2 changed files with 27 additions and 2 deletions

View File

@ -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{}:

View File

@ -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": {}
}
}
}
`},