validate validates the interceptor.
(m *MethodExpr)
| 43 | |
| 44 | // validate validates the interceptor. |
| 45 | func (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 { |