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

Function buildProjectedType

codegen/service/service_data.go:1926–1957  ·  view source on GitHub ↗

buildProjectedType builds projected type for the given user type. viewspkg is the name of the views package

(projected, att *expr.AttributeExpr, viewspkg string, scope, viewScope *codegen.NameScope)

Source from the content-addressed store, hash-verified

1924//
1925// viewspkg is the name of the views package
1926func buildProjectedType(projected, att *expr.AttributeExpr, viewspkg string, scope, viewScope *codegen.NameScope) *ProjectedTypeData {
1927 var (
1928 projections []*InitData
1929 typeInits []*InitData
1930 views []*ViewData
1931
1932 varname = viewScope.GoTypeName(projected)
1933 pt = projected.Type.(expr.UserType)
1934 )
1935 if _, isrt := pt.(*expr.ResultTypeExpr); isrt {
1936 typeInits = buildTypeInits(projected, att, viewspkg, scope, viewScope)
1937 projections = buildProjections(projected, att, viewspkg, scope, viewScope)
1938 views = buildViews(att.Type.(*expr.ResultTypeExpr), viewScope)
1939 }
1940 validations := buildValidations(projected, viewScope)
1941 removeMeta(projected)
1942 return &ProjectedTypeData{
1943 UserTypeData: &UserTypeData{
1944 Name: varname,
1945 Description: fmt.Sprintf("%s is a type that runs validations on a projected type.", varname),
1946 VarName: varname,
1947 Def: viewScope.GoTypeDef(pt.Attribute(), true, true),
1948 Ref: viewScope.GoTypeRef(projected),
1949 Type: pt,
1950 },
1951 Projections: projections,
1952 TypeInits: typeInits,
1953 Validations: validations,
1954 ViewsPkg: viewspkg,
1955 Views: views,
1956 }
1957}
1958
1959// buildViews builds the view data for all the views in the given result type.
1960func buildViews(rt *expr.ResultTypeExpr, viewScope *codegen.NameScope) []*ViewData {

Callers 1

collectProjectedTypesFunction · 0.85

Calls 9

buildTypeInitsFunction · 0.85
buildProjectionsFunction · 0.85
buildViewsFunction · 0.85
buildValidationsFunction · 0.85
GoTypeNameMethod · 0.80
GoTypeDefMethod · 0.80
GoTypeRefMethod · 0.80
removeMetaFunction · 0.70
AttributeMethod · 0.65

Tested by

no test coverage detected