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

View File

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