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

Function buildView

dsl/result_type.go:514–540  ·  view source on GitHub ↗

buildView builds a view expression given an attribute and a corresponding result type. The attribute must be an object listing the child attributes that make up the view.

(name string, mt *expr.ResultTypeExpr, at *expr.AttributeExpr)

Source from the content-addressed store, hash-verified

512// result type. The attribute must be an object listing the child attributes
513// that make up the view.
514func buildView(name string, mt *expr.ResultTypeExpr, at *expr.AttributeExpr) (*expr.ViewExpr, error) {
515 if at.Type == nil {
516 return nil, fmt.Errorf("invalid view DSL")
517 }
518 o := expr.AsObject(at.Type)
519 if o == nil {
520 return nil, fmt.Errorf("invalid view DSL")
521 }
522 for _, nat := range *o {
523 n := nat.Name
524 cat := nat.Attribute
525 if existing := mt.Find(n); existing != nil {
526 dup := expr.DupAtt(existing)
527 if v, ok := cat.Meta.Last(expr.ViewMetaKey); ok {
528 dup.AddMeta("view", v)
529 }
530 o.Set(n, dup)
531 } else if n != "links" {
532 return nil, fmt.Errorf("unknown attribute %#v", n)
533 }
534 }
535 return &expr.ViewExpr{
536 AttributeExpr: at,
537 Name: name,
538 Parent: mt,
539 }, nil
540}

Callers 1

ViewFunction · 0.85

Calls 6

AsObjectFunction · 0.92
DupAttFunction · 0.92
FindMethod · 0.80
LastMethod · 0.80
SetMethod · 0.80
AddMetaMethod · 0.65

Tested by

no test coverage detected