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

Function flattenValidations

codegen/validation.go:524–559  ·  view source on GitHub ↗
(att *expr.AttributeExpr, seen map[string]struct{})

Source from the content-addressed store, hash-verified

522}
523
524func 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.
562func toSlice(val []any) string {

Callers 1

recurseValidationCodeFunction · 0.85

Calls 3

IDMethod · 0.65
AttributeMethod · 0.65
MergeMethod · 0.45

Tested by

no test coverage detected