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

Function methodDSL

dsl/payload.go:164–222  ·  view source on GitHub ↗
(m *expr.MethodExpr, suffix string, p any, args ...any)

Source from the content-addressed store, hash-verified

162}
163
164func methodDSL(m *expr.MethodExpr, suffix string, p any, args ...any) *expr.AttributeExpr {
165 var (
166 att *expr.AttributeExpr
167 fn func()
168 )
169 switch actual := p.(type) {
170 case func():
171 fn = actual
172 att = &expr.AttributeExpr{Type: &expr.Object{}}
173 case expr.UserType:
174 if len(args) == 0 {
175 // Do not duplicate type if it is not customized
176 return &expr.AttributeExpr{Type: actual}
177 }
178 dupped := expr.Dup(actual)
179 att = &expr.AttributeExpr{Type: dupped}
180 if f, ok := args[len(args)-1].(func()); ok {
181 numreqs := 0
182 if att.Validation != nil {
183 numreqs = len(att.Validation.Required)
184 }
185 eval.Execute(f, att)
186 if att.Validation != nil && len(att.Validation.Required) != numreqs {
187 // If the DSL modifies the type attributes "requiredness"
188 // then rename the type to avoid collisions.
189 if renamer, ok := dupped.(interface {
190 Rename(string)
191 }); ok {
192 renamer.Rename(actual.Name() + "_" + m.Name + "_" + suffix)
193 }
194 }
195 }
196 case expr.DataType:
197 att = &expr.AttributeExpr{Type: actual}
198 default:
199 eval.InvalidArgError("type or function", p)
200 return nil
201 }
202 if len(args) >= 1 {
203 if f, ok := args[len(args)-1].(func()); ok {
204 if fn != nil {
205 eval.InvalidArgError("(type), (func), (type, func), (type, desc) or (type, desc, func)", f)
206 }
207 fn = f
208 }
209 if d, ok := args[0].(string); ok {
210 att.Description = d
211 }
212 }
213 if fn != nil {
214 eval.Execute(fn, att)
215 if obj, ok := att.Type.(*expr.Object); ok {
216 if len(*obj) == 0 {
217 att.Type = expr.Empty
218 }
219 }
220 }
221 return att

Callers 4

PayloadFunction · 0.85
StreamingPayloadFunction · 0.85
ResultFunction · 0.85
StreamingResultFunction · 0.85

Calls 5

DupFunction · 0.92
ExecuteFunction · 0.92
InvalidArgErrorFunction · 0.92
RenameMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected