MCPcopy Create free account
hub / github.com/goadesign/goa / Merge

Method Merge

expr/attribute.go:391–414  ·  view source on GitHub ↗

Merge merges other's attributes into a overriding attributes of a with attributes of other with identical names. This only applies to attributes of type Object and Merge panics if the argument or the target is not of type Object.

(other *AttributeExpr)

Source from the content-addressed store, hash-verified

389// This only applies to attributes of type Object and Merge panics if the
390// argument or the target is not of type Object.
391func (a *AttributeExpr) Merge(other *AttributeExpr) {
392 if other == nil {
393 return
394 }
395 left := AsObject(a.Type)
396 right := AsObject(other.Type)
397 if left == nil || right == nil {
398 panic("cannot merge non object attributes") // bug
399 }
400 if a.Type == Empty && len(*right) > 0 {
401 a.Type = &Object{}
402 left = AsObject(a.Type)
403 }
404 if other.Validation != nil {
405 if a.Validation == nil {
406 a.Validation = other.Validation.Dup()
407 } else {
408 a.Validation.Merge(other.Validation)
409 }
410 }
411 for _, nat := range *right {
412 left.Set(nat.Name, nat.Attribute)
413 }
414}
415
416// Inherit merges the properties of existing target type attributes with the
417// argument's. The algorithm is recursive so that child attributes are also

Callers 3

FinalizeMethod · 0.95
ValidateMethod · 0.45
validatePkgPathMethod · 0.45

Calls 3

AsObjectFunction · 0.85
SetMethod · 0.80
DupMethod · 0.65

Tested by

no test coverage detected