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

Function buildHTTPUnionTypeData

http/codegen/service_data.go:2829–2855  ·  view source on GitHub ↗
(u *expr.Union, scope *codegen.NameScope)

Source from the content-addressed store, hash-verified

2827}
2828
2829func buildHTTPUnionTypeData(u *expr.Union, scope *codegen.NameScope) *service.UnionTypeData {
2830 att := &expr.AttributeExpr{Type: u}
2831 name := scope.GoTypeName(att)
2832 kindName := scope.Unique(name + "Kind")
2833
2834 fields := make([]*service.UnionFieldData, len(u.Values))
2835 for i, nat := range u.Values {
2836 fieldName := codegen.Goify(nat.Name, true)
2837 fieldType := scope.GoTypeRef(nat.Attribute)
2838 kindConst := kindName + fieldName
2839 fields[i] = &service.UnionFieldData{
2840 Name: nat.Name,
2841 KindConst: kindConst,
2842 FieldName: fieldName,
2843 FieldType: fieldType,
2844 TypeTag: nat.Name,
2845 }
2846 }
2847
2848 return &service.UnionTypeData{
2849 Name: name,
2850 KindName: kindName,
2851 Fields: fields,
2852 TypeKey: u.GetTypeKey(),
2853 ValueKey: u.GetValueKey(),
2854 }
2855}
2856
2857// sortedNamedAttributes returns object fields sorted by attribute name.
2858// Union naming uses NameScope uniqueness, so callers that discover unions while

Callers 1

collectHTTPUnionTypesFunction · 0.85

Calls 6

GoifyFunction · 0.92
GoTypeNameMethod · 0.80
UniqueMethod · 0.80
GoTypeRefMethod · 0.80
GetTypeKeyMethod · 0.80
GetValueKeyMethod · 0.80

Tested by

no test coverage detected