(att *expr.AttributeExpr, seen map[string]struct{})
| 522 | } |
| 523 | |
| 524 | func flattenValidations(att *expr.AttributeExpr, seen map[string]struct{}) { |
| 525 | switch actual := att.Type.(type) { |
| 526 | case *expr.Array: |
| 527 | flattenValidations(actual.ElemType, seen) |
| 528 | case *expr.Map: |
| 529 | flattenValidations(actual.KeyType, seen) |
| 530 | flattenValidations(actual.ElemType, seen) |
| 531 | case *expr.Object: |
| 532 | for _, nat := range *actual { |
| 533 | flattenValidations(nat.Attribute, seen) |
| 534 | } |
| 535 | case *expr.Union: |
| 536 | for _, nat := range actual.Values { |
| 537 | flattenValidations(nat.Attribute, seen) |
| 538 | } |
| 539 | case expr.UserType: |
| 540 | if _, ok := seen[actual.ID()]; ok { |
| 541 | return |
| 542 | } |
| 543 | seen[actual.ID()] = struct{}{} |
| 544 | v := att.Validation |
| 545 | ut, ok := actual.Attribute().Type.(expr.UserType) |
| 546 | for ok { |
| 547 | if val := ut.Attribute().Validation; val != nil { |
| 548 | if v == nil { |
| 549 | v = val |
| 550 | } else { |
| 551 | v.Merge(val) |
| 552 | } |
| 553 | } |
| 554 | ut, ok = ut.Attribute().Type.(expr.UserType) |
| 555 | } |
| 556 | att.Validation = v |
| 557 | flattenValidations(actual.Attribute(), seen) |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | // toSlice returns Go code that represents the given slice. |
| 562 | func toSlice(val []any) string { |
no test coverage detected