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

Method validate

expr/interceptor.go:45–144  ·  view source on GitHub ↗

validate validates the interceptor.

(m *MethodExpr)

Source from the content-addressed store, hash-verified

43
44// validate validates the interceptor.
45func (i *InterceptorExpr) validate(m *MethodExpr) *eval.ValidationErrors {
46 verr := new(eval.ValidationErrors)
47
48 if i.ReadPayload != nil || i.WritePayload != nil {
49 if !IsObject(m.Payload.Type) {
50 verr.Add(m, "interceptor %q cannot be applied because the method payload is not an object", i.Name)
51 } else {
52 payload := DupAtt(m.Payload)
53 if m.Payload.Bases != nil {
54 for _, base := range m.Payload.Bases {
55 if ut, ok := base.(UserType); ok {
56 payload.Merge(ut.Attribute())
57 }
58 }
59 }
60 if i.ReadPayload != nil {
61 i.validateAttributeAccess(m, "read payload", verr, payload, i.ReadPayload)
62 }
63 if i.WritePayload != nil {
64 i.validateAttributeAccess(m, "write payload", verr, payload, i.WritePayload)
65 }
66 }
67 }
68
69 if i.ReadResult != nil || i.WriteResult != nil {
70 if m.IsResultStreaming() {
71 verr.Add(m, "interceptor %q cannot be applied because the method result is streaming", i.Name)
72 }
73 if !IsObject(m.Result.Type) {
74 verr.Add(m, "interceptor %q cannot be applied because the method result is not an object", i.Name)
75 } else {
76 result := DupAtt(m.Result)
77 if m.Result.Bases != nil {
78 for _, base := range m.Result.Bases {
79 if ut, ok := base.(UserType); ok {
80 result.Merge(ut.Attribute())
81 }
82 }
83 }
84 if i.ReadResult != nil {
85 i.validateAttributeAccess(m, "read result", verr, result, i.ReadResult)
86 }
87 if i.WriteResult != nil {
88 i.validateAttributeAccess(m, "write result", verr, result, i.WriteResult)
89 }
90 }
91 }
92
93 if i.ReadStreamingPayload != nil || i.WriteStreamingPayload != nil {
94 if !m.IsPayloadStreaming() || m.StreamingPayload == nil {
95 verr.Add(m, "interceptor %q cannot be applied because the method payload is not streaming", i.Name)
96 } else {
97 if !IsObject(m.StreamingPayload.Type) {
98 verr.Add(m, "interceptor %q cannot be applied because the method payload is not an object", i.Name)
99 } else {
100 payload := DupAtt(m.StreamingPayload)
101 if m.StreamingPayload.Bases != nil {
102 for _, base := range m.StreamingPayload.Bases {

Callers 2

validateInterceptorsMethod · 0.80

Calls 8

IsObjectFunction · 0.85
DupAttFunction · 0.85
AddMethod · 0.80
IsResultStreamingMethod · 0.80
IsPayloadStreamingMethod · 0.80
AttributeMethod · 0.65
MergeMethod · 0.45

Tested by 1