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

Method Finalize

expr/http_response.go:268–322  ·  view source on GitHub ↗

Finalize sets the response result type from its type if the type is a result type and no result type is already specified.

(a *HTTPEndpointExpr, svcAtt *AttributeExpr)

Source from the content-addressed store, hash-verified

266// Finalize sets the response result type from its type if the type is a result
267// type and no result type is already specified.
268func (r *HTTPResponseExpr) Finalize(a *HTTPEndpointExpr, svcAtt *AttributeExpr) {
269 r.Parent = a
270
271 if r.Body != nil && r.Body.Type != Empty {
272 bodyAtt := svcAtt
273 if o, ok := r.Body.Meta["origin:attribute"]; ok {
274 bodyAtt = svcAtt.Find(o[0])
275 }
276 bodyObj := AsObject(bodyAtt.Type)
277 if body := AsObject(r.Body.Type); body != nil {
278 for _, nat := range *body {
279 n := nat.Name
280 n = strings.Split(n, ":")[0]
281 var att, patt *AttributeExpr
282 var required bool
283 if bodyObj != nil {
284 att = bodyObj.Attribute(n)
285 required = bodyAtt.IsRequired(n)
286 } else {
287 att = bodyAtt
288 required = bodyAtt.Type != Empty
289 }
290 initAttrFromDesign(att, patt)
291 if required {
292 if r.Body.Validation == nil {
293 r.Body.Validation = &ValidationExpr{}
294 }
295 r.Body.Validation.AddRequired(n)
296 }
297 }
298 // Remember original name for example to generate friendlier OpenAPI specs.
299 if t, ok := r.Body.Type.(UserType); ok {
300 t.Attribute().AddMeta("name:original", t.Name())
301 }
302 // Wrap object with user type to simplify response rendering code.
303 r.Body.Type = &UserTypeExpr{
304 AttributeExpr: DupAtt(r.Body),
305 TypeName: fmt.Sprintf("%s%sResponseBody", a.Service.Name(), a.Name()),
306 }
307 }
308 if r.Body.Meta == nil {
309 r.Body.Meta = bodyAtt.Meta
310 }
311 }
312
313 // Set response content type if empty and if set in the result type
314 if r.ContentType == "" {
315 if rt, ok := svcAtt.Type.(*ResultTypeExpr); ok && rt.ContentType != "" {
316 r.ContentType = rt.ContentType
317 }
318 }
319
320 initAttr(r.Headers, svcAtt)
321 initAttr(r.Cookies, svcAtt)
322}
323
324// Dup creates a copy of the response expression.
325func (r *HTTPResponseExpr) Dup() *HTTPResponseExpr {

Callers

nothing calls this directly

Calls 10

AsObjectFunction · 0.85
initAttrFromDesignFunction · 0.85
DupAttFunction · 0.85
initAttrFunction · 0.85
FindMethod · 0.80
IsRequiredMethod · 0.80
AddRequiredMethod · 0.80
AttributeMethod · 0.65
AddMetaMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected