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

Function MaxLength

dsl/validation.go:395–412  ·  view source on GitHub ↗

MaxLength adds a "maxItems" validation to the attribute. See http://json-schema.org/latest/json-schema-validation.html#anchor42. Example: Attribute("array", ArrayOf(String), func() { MaxLength(200) // max array length Elem(func() { MaxLength(5) // max length of each array e

(val int)

Source from the content-addressed store, hash-verified

393// })
394// })
395func MaxLength(val int) {
396 if a, ok := eval.Current().(*expr.AttributeExpr); ok {
397 if a.Type != nil {
398 kind := a.Type.Kind()
399 if kind != expr.BytesKind &&
400 kind != expr.StringKind &&
401 kind != expr.ArrayKind &&
402 kind != expr.MapKind {
403 incompatibleAttributeType("maximum length", a.Type.Name(), "a string or an array")
404 return
405 }
406 }
407 if a.Validation == nil {
408 a.Validation = &expr.ValidationExpr{}
409 }
410 a.Validation.MaxLength = &val
411 }
412}
413
414// Required adds a "required" validation to the attribute.
415// See http://json-schema.org/latest/json-schema-validation.html#anchor61.

Callers 6

openapi_dsls.goFile · 0.85
dsls.goFile · 0.85
type_spec_test.goFile · 0.85

Calls 4

CurrentFunction · 0.92
KindMethod · 0.65
NameMethod · 0.65

Tested by 1