(all bool)
| 1384 | } |
| 1385 | |
| 1386 | func (m *RuleDefinition) validate(all bool) error { |
| 1387 | if m == nil { |
| 1388 | return nil |
| 1389 | } |
| 1390 | |
| 1391 | var errors []error |
| 1392 | |
| 1393 | if len(m.GetName()) > 64 { |
| 1394 | err := RuleDefinitionValidationError{ |
| 1395 | field: "Name", |
| 1396 | reason: "value length must be at most 64 bytes", |
| 1397 | } |
| 1398 | if !all { |
| 1399 | return err |
| 1400 | } |
| 1401 | errors = append(errors, err) |
| 1402 | } |
| 1403 | |
| 1404 | if !_RuleDefinition_Name_Pattern.MatchString(m.GetName()) { |
| 1405 | err := RuleDefinitionValidationError{ |
| 1406 | field: "Name", |
| 1407 | reason: "value does not match regex pattern \"^[a-zA-Z_]{1,64}$\"", |
| 1408 | } |
| 1409 | if !all { |
| 1410 | return err |
| 1411 | } |
| 1412 | errors = append(errors, err) |
| 1413 | } |
| 1414 | |
| 1415 | // no validation rules for Arguments |
| 1416 | |
| 1417 | if all { |
| 1418 | switch v := interface{}(m.GetExpression()).(type) { |
| 1419 | case interface{ ValidateAll() error }: |
| 1420 | if err := v.ValidateAll(); err != nil { |
| 1421 | errors = append(errors, RuleDefinitionValidationError{ |
| 1422 | field: "Expression", |
| 1423 | reason: "embedded message failed validation", |
| 1424 | cause: err, |
| 1425 | }) |
| 1426 | } |
| 1427 | case interface{ Validate() error }: |
| 1428 | if err := v.Validate(); err != nil { |
| 1429 | errors = append(errors, RuleDefinitionValidationError{ |
| 1430 | field: "Expression", |
| 1431 | reason: "embedded message failed validation", |
| 1432 | cause: err, |
| 1433 | }) |
| 1434 | } |
| 1435 | } |
| 1436 | } else if v, ok := interface{}(m.GetExpression()).(interface{ Validate() error }); ok { |
| 1437 | if err := v.Validate(); err != nil { |
| 1438 | return RuleDefinitionValidationError{ |
| 1439 | field: "Expression", |
| 1440 | reason: "embedded message failed validation", |
| 1441 | cause: err, |
| 1442 | } |
| 1443 | } |
no test coverage detected