validateEnumDefault makes sure that the attribute default value is one of the enum values.
(ctx string, parent eval.Expression)
| 746 | // validateEnumDefault makes sure that the attribute default value is one of the |
| 747 | // enum values. |
| 748 | func (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. |