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

Method Finalize

expr/method.go:358–415  ·  view source on GitHub ↗

Finalize makes sure the method payload and result types are set. It also projects the result if it is a result type and a view is explicitly set in the design or a result type having at most one view.

()

Source from the content-addressed store, hash-verified

356// projects the result if it is a result type and a view is explicitly set in
357// the design or a result type having at most one view.
358func (m *MethodExpr) Finalize() {
359 if m.Payload == nil {
360 m.Payload = &AttributeExpr{Type: Empty}
361 } else {
362 m.Payload.Finalize()
363 }
364 if m.StreamingPayload == nil {
365 m.StreamingPayload = &AttributeExpr{Type: Empty}
366 } else {
367 m.StreamingPayload.Finalize()
368 }
369
370 // Handle StreamingResult finalization
371 if m.StreamingResult != nil {
372 m.StreamingResult.Finalize()
373 if rt, ok := m.StreamingResult.Type.(*ResultTypeExpr); ok {
374 rt.Finalize()
375 }
376 }
377
378 // Handle Result finalization (may be same as StreamingResult for backward compat)
379 if m.Result == nil {
380 m.Result = &AttributeExpr{Type: Empty}
381 } else {
382 m.Result.Finalize()
383 if rt, ok := m.Result.Type.(*ResultTypeExpr); ok {
384 rt.Finalize()
385 }
386 }
387 for _, e := range m.Service.Errors {
388 found := false
389 for _, f := range m.Errors {
390 if e.Name == f.Name {
391 found = true
392 break
393 }
394 }
395 if !found {
396 m.Errors = append(m.Errors, e)
397 }
398 }
399 for _, e := range m.Errors {
400 e.Finalize()
401 }
402
403 // Inherit security requirements
404 if HasNoSecurity(m.Requirements) {
405 m.Requirements = []*SecurityExpr{{Schemes: []*SchemeExpr{{Kind: NoKind}}}}
406 return
407 }
408 if len(m.Requirements) == 0 {
409 if len(m.Service.Requirements) > 0 {
410 m.Requirements = copyReqs(m.Service.Requirements)
411 } else if len(Root.API.Requirements) > 0 {
412 m.Requirements = copyReqs(Root.API.Requirements)
413 }
414 }
415}

Calls 3

HasNoSecurityFunction · 0.85
copyReqsFunction · 0.85
FinalizeMethod · 0.65