MinLength adds a "minItems" validation to the attribute. See http://json-schema.org/latest/json-schema-validation.html#anchor45. Example: Attribute("map", MapOf(String, String), func() { MinLength(10) // min key-values in map Key(func() { MinLength(1) // min length of ma
(val int)
| 363 | // }) |
| 364 | // }) |
| 365 | func MinLength(val int) { |
| 366 | if a, ok := eval.Current().(*expr.AttributeExpr); ok { |
| 367 | if a.Type != nil { |
| 368 | kind := a.Type.Kind() |
| 369 | if kind != expr.BytesKind && |
| 370 | kind != expr.StringKind && |
| 371 | kind != expr.ArrayKind && |
| 372 | kind != expr.MapKind { |
| 373 | incompatibleAttributeType("minimum length", a.Type.Name(), "a string or an array") |
| 374 | return |
| 375 | } |
| 376 | } |
| 377 | if a.Validation == nil { |
| 378 | a.Validation = &expr.ValidationExpr{} |
| 379 | } |
| 380 | a.Validation.MinLength = &val |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | // MaxLength adds a "maxItems" validation to the attribute. |
| 385 | // See http://json-schema.org/latest/json-schema-validation.html#anchor42. |