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

Function Elem

dsl/user_type.go:290–304  ·  view source on GitHub ↗

Elem makes it possible to specify validations for array and map values. Example: Attribute("array", ArrayOf(Int), func() { Elem(func() { Enum(1, 2, 3, 4, 5) // list possible values for array elements }) }) Attribute("map", MapOf(String, Int), func() { Elem(func() {

(fn func())

Source from the content-addressed store, hash-verified

288// })
289// })
290func Elem(fn func()) {
291 at, ok := eval.Current().(*expr.AttributeExpr)
292 if !ok {
293 eval.IncompatibleDSL()
294 return
295 }
296 switch e := at.Type.(type) {
297 case *expr.Array:
298 eval.Execute(fn, e.ElemType)
299 case *expr.Map:
300 eval.Execute(fn, e.ElemType)
301 default:
302 eval.IncompatibleDSL()
303 }
304}

Callers 7

TestGetMetaTypeImportsFunction · 0.92
result_dsls.goFile · 0.85
openapi_dsls.goFile · 0.85
payload_dsls.goFile · 0.85
dsls.goFile · 0.85
type_spec_test.goFile · 0.85

Calls 3

CurrentFunction · 0.92
IncompatibleDSLFunction · 0.92
ExecuteFunction · 0.92

Tested by 1

TestGetMetaTypeImportsFunction · 0.74