(prefix string, seen map[*AttributeExpr]int, indent int)
| 662 | // Debug dumps the attribute to STDOUT in a goa developer friendly way. |
| 663 | func (a *AttributeExpr) Debug(prefix string) { a.debug(prefix, make(map[*AttributeExpr]int), 0) } |
| 664 | func (a *AttributeExpr) debug(prefix string, seen map[*AttributeExpr]int, indent int) { |
| 665 | tab := " " |
| 666 | tabs := strings.Repeat(tab, indent) |
| 667 | prefix = tabs + prefix |
| 668 | if IsObject(a.Type) { |
| 669 | // avoid infinite recursion |
| 670 | if c, ok := seen[a]; ok && c > 1 { |
| 671 | fmt.Printf("%s: ...\n", prefix) |
| 672 | return |
| 673 | } |
| 674 | seen[a]++ |
| 675 | } |
| 676 | n := a.Type.Name() |
| 677 | if desc := a.Description; desc != "" { |
| 678 | fmt.Printf("%s: %s (%s) <%T>\n", prefix, n, desc, a.Type) |
| 679 | } else { |
| 680 | fmt.Printf("%s: %s <%T>\n", prefix, n, a.Type) |
| 681 | } |
| 682 | ut, isUT := a.Type.(UserType) |
| 683 | switch { |
| 684 | case isUT: |
| 685 | ut.Attribute().debug("att", seen, indent+1) |
| 686 | tabs = strings.Repeat(tab, indent+1) |
| 687 | case IsObject(a.Type): |
| 688 | for _, nat := range *AsObject(a.Type) { |
| 689 | nat.Attribute.debug("- "+nat.Name, seen, indent+1) |
| 690 | } |
| 691 | case IsArray(a.Type): |
| 692 | AsArray(a.Type).ElemType.debug("elem", seen, indent+1) |
| 693 | case IsMap(a.Type): |
| 694 | m := AsMap(a.Type) |
| 695 | m.KeyType.debug("key", seen, indent+1) |
| 696 | m.ElemType.debug("elem", seen, indent+1) |
| 697 | case IsUnion(a.Type): |
| 698 | for _, nat := range AsUnion(a.Type).Values { |
| 699 | nat.Attribute.debug("* "+nat.Name, seen, indent+1) |
| 700 | } |
| 701 | } |
| 702 | if rt, ok := a.Type.(*ResultTypeExpr); ok { |
| 703 | fmt.Printf("%s%sviews\n", tabs, tab) |
| 704 | for _, v := range rt.Views { |
| 705 | nats := *AsObject(v.Type) |
| 706 | keys := make([]string, len(nats)) |
| 707 | for i, n := range nats { |
| 708 | keys[i] = n.Name |
| 709 | } |
| 710 | fmt.Printf("%s%s- %s: %v\n", tabs+tab, tab, v.Name, keys) |
| 711 | } |
| 712 | } |
| 713 | if d := a.DefaultValue; d != nil { |
| 714 | fmt.Printf("%s%sdefault\n", tabs, tab) |
| 715 | fmt.Printf("%s%s%#v\n", tabs+tab, tab, a.DefaultValue) |
| 716 | } |
| 717 | if len(a.UserExamples) > 0 { |
| 718 | fmt.Printf("%s%sexamples\n", tabs, tab) |
| 719 | for _, ex := range a.UserExamples { |
| 720 | fmt.Printf("%s%s- %s: %#v\n", tabs+tab, tab, ex.Summary, ex.Value) |
| 721 | } |
no test coverage detected