Skip to content

Commit 002a6cf

Browse files
committed
fix(validators): min length validator should be ignored if required is false
1 parent cc2b0a6 commit 002a6cf

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

internal/parameter/secret/secret.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ func (p Param) Render() huh.Field {
2020
if p.Required {
2121
group = append(group, validators.Required(p.Name, p.Trim))
2222
}
23-
if p.MinLength != nil {
23+
// if the value is not required and no value has been given, min length validator should be ignored.
24+
if p.Required && p.MinLength != nil {
2425
group = append(group, validators.MinLength(*p.MinLength))
2526
}
2627
if p.MaxLength != nil {

internal/parameter/str/str.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func (p Param) RenderInput() *huh.Input {
3939
if p.Required {
4040
group = append(group, validators.Required(p.Name, p.Trim))
4141
}
42-
if p.MinLength != nil {
42+
// if the value is not required and no value has been given, min length validator should be ignored.
43+
if p.Required && p.MinLength != nil {
4344
group = append(group, validators.MinLength(*p.MinLength))
4445
}
4546
if p.MaxLength != nil {

internal/parameter/text/text.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func (p Param) Render() huh.Field {
3737
if p.Required {
3838
group = append(group, validators.Required(p.Name, false))
3939
}
40-
if p.MinLength != nil {
40+
// if the value is not required and no value has been given, min length validator should be ignored.
41+
if p.Required && p.MinLength != nil {
4142
group = append(group, validators.MinLength(*p.MinLength))
4243
}
4344
if p.MaxLength != nil {

0 commit comments

Comments
 (0)