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

Function generatedRequiredValidation

codegen/validation.go:501–522  ·  view source on GitHub ↗

There is a case where there is validation but no actual validation code: if the validation is a required validation that applies to attributes that cannot be nil i.e. primitive types.

(att *expr.AttributeExpr, attCtx *AttributeContext)

Source from the content-addressed store, hash-verified

499// the validation is a required validation that applies to attributes that
500// cannot be nil i.e. primitive types.
501func generatedRequiredValidation(att *expr.AttributeExpr, attCtx *AttributeContext) (res []string) {
502 if att.Validation == nil {
503 return
504 }
505 obj := expr.AsObject(att.Type)
506 for _, req := range att.Validation.Required {
507 reqAtt := obj.Attribute(req)
508 if reqAtt == nil {
509 continue
510 }
511 if !attCtx.Pointer && expr.IsPrimitive(reqAtt.Type) &&
512 reqAtt.Type.Kind() != expr.BytesKind &&
513 reqAtt.Type.Kind() != expr.AnyKind {
514 continue
515 }
516 if attCtx.IgnoreRequired && expr.IsPrimitive(reqAtt.Type) {
517 continue
518 }
519 res = append(res, req)
520 }
521 return
522}
523
524func flattenValidations(att *expr.AttributeExpr, seen map[string]struct{}) {
525 switch actual := att.Type.(type) {

Callers 1

validationCodeFunction · 0.85

Calls 4

AsObjectFunction · 0.92
IsPrimitiveFunction · 0.92
AttributeMethod · 0.65
KindMethod · 0.65

Tested by

no test coverage detected