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

Method validateEnumDefault

expr/attribute.go:748–770  ·  view source on GitHub ↗

validateEnumDefault makes sure that the attribute default value is one of the enum values.

(ctx string, parent eval.Expression)

Source from the content-addressed store, hash-verified

746// validateEnumDefault makes sure that the attribute default value is one of the
747// enum values.
748func (a *AttributeExpr) validateEnumDefault(ctx string, parent eval.Expression) *eval.ValidationErrors {
749 //TODO: We only do the default value and enum check just for primitive types.
750 if _, ok := a.Type.(Primitive); !ok {
751 return nil
752 }
753 verr := new(eval.ValidationErrors)
754 if a.DefaultValue != nil && a.Validation != nil && a.Validation.Values != nil {
755 var found bool
756 if slices.Contains(a.Validation.Values, a.DefaultValue) {
757 found = true
758 }
759 if !found {
760 verr.Add(
761 parent,
762 "%sdefault value %#v is not one of the accepted values: %#v",
763 ctx,
764 a.DefaultValue,
765 a.Validation.Values,
766 )
767 }
768 }
769 return verr
770}
771
772// validateExamples makes sure that the attribute example values are compatible
773// with the attribute type.

Callers 1

ValidateMethod · 0.95

Calls 1

AddMethod · 0.80

Tested by

no test coverage detected