@@ -209,13 +209,13 @@ func (v *reconcileWithSchemaWalker) doList(t *schema.List) (errs ValidationError
209209func (v * reconcileWithSchemaWalker ) visitMapItems (t * schema.Map , element * fieldpath.Set ) (errs ValidationErrors ) {
210210 handleElement := func (pe fieldpath.PathElement , isMember bool ) {
211211 var hasChildren bool
212- tr , lookupErrs := typeRefAtPath (t , pe )
213- errs = append ( errs , lookupErrs ... )
214- v2 := v . prepareDescent (pe , tr )
215- v2 .fieldSet , hasChildren = element . Children . Get ( pe )
216- v2 . isAtomic = isMember && ! hasChildren
217- errs = append ( errs , v2 . reconcile () ... )
218- v . finishDescent ( v2 )
212+ if tr , ok := typeRefAtPath (t , pe ); ok { // ignore fields not in the schema
213+ v2 := v . prepareDescent ( pe , tr )
214+ v2 . fieldSet , hasChildren = element . Children . Get (pe )
215+ v2 .isAtomic = isMember && ! hasChildren
216+ errs = append ( errs , v2 . reconcile () ... )
217+ v . finishDescent ( v2 )
218+ }
219219 }
220220 element .Children .Iterate (func (pe fieldpath.PathElement ) {
221221 if element .Members .Has (pe ) {
@@ -283,15 +283,12 @@ func descendToPath(node *fieldpath.Set, path fieldpath.Path) *fieldpath.Set {
283283 return node
284284}
285285
286- func typeRefAtPath (t * schema.Map , pe fieldpath.PathElement ) (tr schema.TypeRef , errs ValidationErrors ) {
287- tr = t .ElementType
286+ func typeRefAtPath (t * schema.Map , pe fieldpath.PathElement ) (schema.TypeRef , bool ) {
287+ tr : = t .ElementType
288288 if pe .FieldName != nil {
289289 if sf , ok := t .FindField (* pe .FieldName ); ok {
290290 tr = sf .Type
291291 }
292292 }
293- if (tr == schema.TypeRef {}) {
294- errs = append (errs , errorf ("field not declared in schema" ).WithPrefix (pe .String ())... )
295- }
296- return tr , errs
293+ return tr , tr != schema.TypeRef {}
297294}
0 commit comments