MCPcopy
hub / github.com/carvel-dev/ytt / AssignTypeTo

Method AssignTypeTo

pkg/schema/assign.go:38–60  ·  view source on GitHub ↗

AssignTypeTo assigns this schema metadata to `node`. If `node` is not a yamlmeta.Map, `chk` contains a violation describing the mismatch If `node`'s yamlmeta.MapItem's cannot be assigned their corresponding MapItemType, `chk` contains a violation describing the mismatch If `node` is missing any yam

(node yamlmeta.Node)

Source from the content-addressed store, hash-verified

36// If `node`'s yamlmeta.MapItem's cannot be assigned their corresponding MapItemType, `chk` contains a violation describing the mismatch
37// If `node` is missing any yamlmeta.MapItem's specified in this MapType, they are added to `node`.
38func (m *MapType) AssignTypeTo(node yamlmeta.Node) TypeCheck {
39 chk := TypeCheck{}
40 mapNode, ok := node.(*yamlmeta.Map)
41 if !ok {
42 chk.Violations = append(chk.Violations, NewMismatchedTypeAssertionError(node, m))
43 return chk
44 }
45 var foundKeys []interface{}
46 SetType(node, m)
47 for _, mapItem := range mapNode.Items {
48 for _, itemType := range m.Items {
49 if mapItem.Key == itemType.Key {
50 foundKeys = append(foundKeys, itemType.Key)
51 childCheck := itemType.AssignTypeTo(mapItem)
52 chk.Violations = append(chk.Violations, childCheck.Violations...)
53 break
54 }
55 }
56 }
57
58 m.applySchemaDefaults(foundKeys, chk, mapNode)
59 return chk
60}
61
62func (m *MapType) applySchemaDefaults(foundKeys []interface{}, chk TypeCheck, mapNode *yamlmeta.Map) {
63 for _, item := range m.Items {

Callers

nothing calls this directly

Calls 4

applySchemaDefaultsMethod · 0.95
SetTypeFunction · 0.85
AssignTypeToMethod · 0.65

Tested by

no test coverage detected