@@ -31,7 +31,26 @@ func (v sizeBetweenValidator) MarkdownDescription(ctx context.Context) string {
3131}
3232
3333func (v sizeBetweenValidator ) ValidateSet (ctx context.Context , req validator.SetRequest , resp * validator.SetResponse ) {
34- if req .ConfigValue .IsNull () || req .ConfigValue .IsUnknown () {
34+ if req .ConfigValue .IsNull () {
35+ return
36+ }
37+
38+ if req .ConfigValue .IsUnknown () {
39+ if refn , ok := req .ConfigValue .LengthLowerBoundRefinement (); ok && refn .LowerBound () > int64 (v .max ) {
40+ resp .Diagnostics .Append (validatordiag .InvalidAttributeValueDiagnostic (
41+ req .Path ,
42+ v .Description (ctx ),
43+ fmt .Sprintf ("unknown value that will have at least %d elements" , refn .LowerBound ()),
44+ ))
45+ }
46+
47+ if refn , ok := req .ConfigValue .LengthUpperBoundRefinement (); ok && refn .UpperBound () < int64 (v .min ) {
48+ resp .Diagnostics .Append (validatordiag .InvalidAttributeValueDiagnostic (
49+ req .Path ,
50+ v .Description (ctx ),
51+ fmt .Sprintf ("unknown value that will have at most %d elements" , refn .UpperBound ()),
52+ ))
53+ }
3554 return
3655 }
3756
@@ -47,7 +66,26 @@ func (v sizeBetweenValidator) ValidateSet(ctx context.Context, req validator.Set
4766}
4867
4968func (v sizeBetweenValidator ) ValidateParameterSet (ctx context.Context , req function.SetParameterValidatorRequest , resp * function.SetParameterValidatorResponse ) {
50- if req .Value .IsNull () || req .Value .IsUnknown () {
69+ if req .Value .IsNull () {
70+ return
71+ }
72+
73+ if req .Value .IsUnknown () {
74+ if refn , ok := req .Value .LengthLowerBoundRefinement (); ok && refn .LowerBound () > int64 (v .max ) {
75+ resp .Error = validatorfuncerr .InvalidParameterValueFuncError (
76+ req .ArgumentPosition ,
77+ v .Description (ctx ),
78+ fmt .Sprintf ("unknown value that will have at least %d elements" , refn .LowerBound ()),
79+ )
80+ }
81+
82+ if refn , ok := req .Value .LengthUpperBoundRefinement (); ok && refn .UpperBound () < int64 (v .min ) {
83+ resp .Error = validatorfuncerr .InvalidParameterValueFuncError (
84+ req .ArgumentPosition ,
85+ v .Description (ctx ),
86+ fmt .Sprintf ("unknown value that will have at most %d elements" , refn .UpperBound ()),
87+ )
88+ }
5189 return
5290 }
5391
0 commit comments