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

Function projectSingle

expr/result_type.go:250–327  ·  view source on GitHub ↗
(rt *ResultTypeExpr, view string, seen map[string]*AttributeExpr)

Source from the content-addressed store, hash-verified

248}
249
250func projectSingle(rt *ResultTypeExpr, view string, seen map[string]*AttributeExpr) (*ResultTypeExpr, error) {
251 v := rt.View(view)
252 if v == nil {
253 return nil, fmt.Errorf("unknown view %#v", view)
254 }
255 viewObj := v.Type.(*Object)
256
257 // Compute validations - view may not have all fields
258 var val *ValidationExpr
259 if rt.Validation != nil {
260 var required []string
261 for _, n := range rt.Validation.Required {
262 if att := viewObj.Attribute(n); att != nil {
263 required = append(required, n)
264 }
265 }
266 val = rt.Validation.Dup()
267 val.Required = required
268 }
269
270 // Compute description
271 desc := rt.Description
272 if desc == "" {
273 desc = rt.TypeName + " result type"
274 }
275 desc += " (" + view + " view)"
276
277 // Compute type name
278 typeName := rt.TypeName
279 if view != DefaultView {
280 typeName += Title(view)
281 }
282
283 var ut *UserTypeExpr
284 if att, ok := seen[hashAttrAndView(rt.Attribute(), view)]; ok {
285 if rt, ok2 := att.Type.(*ResultTypeExpr); ok2 {
286 ut = &UserTypeExpr{
287 AttributeExpr: DupAtt(rt.Attribute()),
288 TypeName: rt.TypeName,
289 }
290 }
291 }
292 id := rt.projectIdentifier(view)
293 if ut == nil {
294 ut = &UserTypeExpr{
295 AttributeExpr: &AttributeExpr{
296 Description: desc,
297 Validation: val,
298 },
299 }
300 }
301 ut.TypeName = typeName
302 ut.UID = id
303 ut.Type = Dup(v.Type)
304 ut.UserExamples = v.UserExamples
305 projected := &ResultTypeExpr{
306 Identifier: id,
307 UserTypeExpr: ut,

Callers 1

projectFunction · 0.85

Calls 11

hashAttrAndViewFunction · 0.85
DupAttFunction · 0.85
DupFunction · 0.85
AsObjectFunction · 0.85
projectRecursiveFunction · 0.85
ViewMethod · 0.80
projectIdentifierMethod · 0.80
SetMethod · 0.80
TitleFunction · 0.70
AttributeMethod · 0.65
DupMethod · 0.65

Tested by

no test coverage detected