Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ package plugin
import (
"fmt"
"os"
"reflect"
"strconv"
"strings"

Expand Down Expand Up @@ -664,22 +663,8 @@ func (p *plugin) validatorWithNonRepeatedConstraint(fv *validator.FieldValidator
return false
}

// Need to use reflection in order to be future-proof for new types of constraints.
v := reflect.ValueOf(*fv)
for i := 0; i < v.NumField(); i++ {
fieldName := v.Type().Field(i).Name

// All known validators will have a pointer type and we should skip any fields
// that are not pointers (i.e unknown fields, etc) as well as 'nil' pointers that
// don't lead to anything.
if v.Type().Field(i).Type.Kind() != reflect.Ptr || v.Field(i).IsNil() {
continue
}

// Identify non-repeated constraints based on their name.
if fieldName != "RepeatedCountMin" && fieldName != "RepeatedCountMax" {
return true
}
if fv.RepeatedCountMin == nil && fv.RepeatedCountMax == nil {
return true
}
return false
}
Expand Down