From 2808887a84f5449e7070038d86833efb2575e7aa Mon Sep 17 00:00:00 2001 From: Leo Cavalcante Date: Tue, 29 Sep 2026 18:44:33 -0300 Subject: [PATCH 1/3] Add oneof and iscolor for the common validator example. The usual User and Address structs need space-separated oneof, the iscolor alias, and the validate tag key, including dive into address elements. --- README.md | 12 ++ docs/internals.md | 6 +- internal/analyzer/analyzer.go | 24 +-- internal/analyzer/common_example_test.go | 149 ++++++++++++++ .../analyzer/operations/operations_list.go | 20 ++ .../analyzer/operations/operations_test.go | 93 +++++++++ internal/analyzer/parser_validation_test.go | 36 ++++ internal/codegenerator/common_example_test.go | 189 ++++++++++++++++++ internal/codegenerator/condition_table.go | 49 +++++ .../get_test_elements_pointer_test.go | 19 ++ .../get_test_elements_string_test.go | 23 +++ internal/parser/common_example_test.go | 62 ++++++ tests/endtoend/common_validator_example.go | 133 ++++++++++++ tests/endtoend/commonexample/user.go | 27 +++ tests/endtoend/commonexample/validator__.go | 78 ++++++++ tests/endtoend/main.go | 1 + types/color.go | 46 +++++ types/color_test.go | 87 ++++++++ 18 files changed, 1039 insertions(+), 15 deletions(-) create mode 100644 internal/analyzer/common_example_test.go create mode 100644 internal/codegenerator/common_example_test.go create mode 100644 internal/parser/common_example_test.go create mode 100644 tests/endtoend/common_validator_example.go create mode 100644 tests/endtoend/commonexample/user.go create mode 100755 tests/endtoend/commonexample/validator__.go create mode 100644 types/color.go create mode 100644 types/color_test.go diff --git a/README.md b/README.md index 815f15c..f4d4264 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ Malformed JSON still returns the usual `encoding/json` decode error. Validation ## Validations +Struct tags may use `valid` or `validate`. When both keys are present, `valid` is the one that is read. The common go-playground example uses `validate`. + The following validations will be implemented: - eq (equal): must be equal to the specified value @@ -91,6 +93,9 @@ The following validations will be implemented: - nin (not in): must not be one of the following values - required (required): is required - email (email): must be a valid email format (empty is valid for optional fields) +- oneof (one of): string must be one of the space-separated values +- hexcolor, rgb, rgba, hsl, hsla: string must match that color format +- iscolor: alias for hexcolor, rgb, rgba, hsl, or hsla - eqfield (equal field): field must be equal to another field - neqfield (not equal field): field must not be equal to another field - gtefield (greater than or equal field): field must be greater than or equal to another field @@ -136,6 +141,13 @@ The following table shows the validations and possible types, where: | nin | I | I | W | - | I | I | W | - | W | | required | I | I | W | - | I | - | W | W | W | | email | I | - | - | - | - | - | - | - | - | +| oneof | I | - | - | - | - | - | - | - | - | +| hexcolor | I | - | - | - | - | - | - | - | - | +| rgb | I | - | - | - | - | - | - | - | - | +| rgba | I | - | - | - | - | - | - | - | - | +| hsl | I | - | - | - | - | - | - | - | - | +| hsla | I | - | - | - | - | - | - | - | - | +| iscolor | I | - | - | - | - | - | - | - | - | | eqfield | I | I | I | I | - | - | - | W | W | | neqfield | I | I | I | I | - | - | - | W | W | | gtefield | - | I | - | - | - | - | - | W | W | diff --git a/docs/internals.md b/docs/internals.md index bee4a3f..2d75a17 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -72,11 +72,11 @@ Slices, arrays, maps, and pointers keep a marker on that name, such as `[]` ### Tag parsing -`analyzeFieldValidations` copies each `parser.Struct` into an `analyzer.Struct`. A field counts as validated only when its tag text starts with `valid:`. The analyzer sets `HasValidTag` if any field matches. It unquotes the text after `valid:` and splits on commas. +`analyzeFieldValidations` copies each `parser.Struct` into an `analyzer.Struct`. A field counts as validated when its struct tag has a `valid` key, or a `validate` key if `valid` is absent. The analyzer sets `HasValidTag` if any field matches. It splits that key's value on commas. `reflect.StructTag` reads the key, so `json:"email" validate:"required,email"` is accepted. `ParserValidation` splits one validation on `=`. More than two pieces is an error. The operation's `CountValues` selects the shape. -`ZeroValue` operations `required` and `email` reject a target. `OneValue` operations require one target. `ManyValues` operations `in` and `nin` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. +`ZeroValue` operations `required`, `email`, `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` reject a target. `OneValue` operations require one target. `ManyValues` operations `in`, `nin`, and `oneof` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. `iscolor` is the alias for `hexcolor|rgb|rgba|hsl|hsla` and calls `types.IsColor`. The result is an `analyzer.Validation` with `Operation`, `ExpectedValues`, and `Values`. @@ -142,7 +142,7 @@ errs = append(errs, types.NewValidationError("message")) Scalar `in` rows set `concatOperator` to `||`, and the per-value copies are joined. That includes `*`, `*`, `*`, and `*`. Scalar `nin` rows set `concatOperator` to `&&`. Slice, array, and map rows leave `concatOperator` empty, so `DefineTestElements` keeps one copy. That copy lists every target through `{{.TargetsAsStringSlice}}` or `{{.TargetsAsNumericSlice}}`. -Those slice and map copies call `types.SliceOnlyContains`, `types.SliceNotContains`, `types.MapOnlyContains`, or `types.MapNotContains`. Non-pointer array rows pass `obj.Field[:]` into the slice helpers. Literal string comparisons quote the target. `email` calls `types.IsValidEmail`. `eq_ignore_case` and `neq_ignore_case` call `strings.EqualFold`. Field comparisons compile to `obj.Field` compared with `obj.Other` or `obj.Nested.Field`. +Those slice and map copies call `types.SliceOnlyContains`, `types.SliceNotContains`, `types.MapOnlyContains`, or `types.MapNotContains`. Non-pointer array rows pass `obj.Field[:]` into the slice helpers. Literal string comparisons quote the target. `email` calls `types.IsValidEmail`. `oneof` uses the same string equality as scalar `in`. `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` call the matching `types` helpers. `eq_ignore_case` and `neq_ignore_case` call `strings.EqualFold`. Field comparisons compile to `obj.Field` compared with `obj.Other` or `obj.Nested.Field`. When the field is a struct or a pointer to a struct, each validation on that field appends a nested call instead of a condition-table test. The call is `TypeValidate(&obj.Field)`, where `Type` is `BaseType`. If `BaseType` starts with the struct's own package name and a dot, that prefix is removed. A same-package field whose `BaseType` is `main.InnerStructType` calls `InnerStructTypeValidate`. A field whose `BaseType` is `mypkg.InnerStructType` calls `mypkg.InnerStructTypeValidate`. The call is emitted when `BaseType` is in the parsed-struct index. A missing type returns `no validator found for struct type`. diff --git a/internal/analyzer/analyzer.go b/internal/analyzer/analyzer.go index a3ddd0e..610e45d 100644 --- a/internal/analyzer/analyzer.go +++ b/internal/analyzer/analyzer.go @@ -2,7 +2,7 @@ package analyzer import ( "fmt" - "strconv" + "reflect" "strings" "github.com/opencodeco/validgen/internal/analyzer/operations" @@ -11,8 +11,6 @@ import ( "github.com/opencodeco/validgen/types" ) -const validTag = "valid" - func AnalyzeStructs(structs []*parser.Struct) ([]*Struct, error) { result, err := analyzeFieldValidations(structs) if err != nil { @@ -63,18 +61,20 @@ func analyzeFieldValidations(structs []*parser.Struct) ([]*Struct, error) { } func parseFieldValidations(fieldTag string) ([]string, bool) { - fieldValidations := []string{} - hasValidTag := false - prefixToSearch := validTag + ":" + if fieldTag == "" { + return nil, false + } - if strings.HasPrefix(fieldTag, prefixToSearch) { - hasValidTag = true - tagWithoutPrefix, _ := strings.CutPrefix(fieldTag, prefixToSearch) - tagWithoutQuotes, _ := strconv.Unquote(tagWithoutPrefix) - fieldValidations = strings.Split(tagWithoutQuotes, ",") + tag := reflect.StructTag(fieldTag) + value, ok := tag.Lookup("valid") + if !ok { + value, ok = tag.Lookup("validate") + } + if !ok { + return nil, false } - return fieldValidations, hasValidTag + return strings.Split(value, ","), true } func checkForInvalidOperations(structs []*Struct) error { diff --git a/internal/analyzer/common_example_test.go b/internal/analyzer/common_example_test.go new file mode 100644 index 0000000..4a2bb2c --- /dev/null +++ b/internal/analyzer/common_example_test.go @@ -0,0 +1,149 @@ +package analyzer + +import ( + "reflect" + "testing" + + "github.com/opencodeco/validgen/internal/common" + "github.com/opencodeco/validgen/internal/parser" +) + +func TestAnalyzeCommonValidatorExample(t *testing.T) { + structs := commonExampleStructs() + got, err := AnalyzeStructs(structs) + if err != nil { + t.Fatal(err) + } + if len(got) != 2 { + t.Fatalf("struct count = %d, want 2", len(got)) + } + if !got[0].HasValidTag || !got[1].HasValidTag { + t.Fatal("example structs should be validated") + } + + wantUser := [][]string{ + {"required"}, + {"required"}, + {"gte", "lte"}, + {"required", "email"}, + {"oneof"}, + {"iscolor"}, + {"required", "dive", "required"}, + } + if ops := operationNames(got[0]); !reflect.DeepEqual(ops, wantUser) { + t.Fatalf("User operations = %#v, want %#v", ops, wantUser) + } + + gender := got[0].FieldsValidations[4].Validations[0] + wantValues := []string{"male", "female", "prefer_not_to"} + if !reflect.DeepEqual(gender.Values, wantValues) { + t.Fatalf("oneof values = %#v, want %#v", gender.Values, wantValues) + } + + wantAddress := [][]string{ + {"required"}, + {"required"}, + {"required"}, + {"required"}, + } + if ops := operationNames(got[1]); !reflect.DeepEqual(ops, wantAddress) { + t.Fatalf("Address operations = %#v, want %#v", ops, wantAddress) + } +} + +func TestValidationTagKey(t *testing.T) { + stringField := common.FieldType{BaseType: "string"} + tests := []struct { + name string + tag string + want []string + }{ + { + name: "valid tag", + tag: `valid:"required,email"`, + want: []string{"required", "email"}, + }, + { + name: "validate tag after json", + tag: `json:"email" validate:"required,email"`, + want: []string{"required", "email"}, + }, + { + name: "valid wins when both keys are present", + tag: `valid:"required" validate:"email"`, + want: []string{"required"}, + }, + { + name: "unrelated tag", + tag: `json:"email"`, + want: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := AnalyzeStructs([]*parser.Struct{{ + PackageName: "main", + StructName: "User", + Fields: []parser.Field{{ + FieldName: "Email", + Type: stringField, + Tag: tt.tag, + }}, + }}) + if err != nil { + t.Fatal(err) + } + ops := operationNames(got[0]) + var flat []string + if len(ops) == 1 { + flat = ops[0] + } + if !reflect.DeepEqual(flat, tt.want) { + t.Fatalf("operations = %#v, want %#v", flat, tt.want) + } + }) + } +} + +func commonExampleStructs() []*parser.Struct { + return []*parser.Struct{ + { + PackageName: "main", + StructName: "User", + Fields: []parser.Field{ + {FieldName: "FirstName", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "LastName", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Age", Type: common.FieldType{BaseType: "uint8"}, Tag: `validate:"gte=0,lte=130"`}, + {FieldName: "Email", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required,email"`}, + {FieldName: "Gender", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"oneof=male female prefer_not_to"`}, + {FieldName: "FavouriteColor", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"iscolor"`}, + { + FieldName: "Addresses", + Type: common.FieldType{BaseType: "main.Address", ComposedType: "*[]", ElemPointer: true}, + Tag: `validate:"required,dive,required"`, + }, + }, + }, + { + PackageName: "main", + StructName: "Address", + Fields: []parser.Field{ + {FieldName: "Street", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "City", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Planet", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Phone", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + }, + }, + } +} + +func operationNames(st *Struct) [][]string { + names := make([][]string, len(st.FieldsValidations)) + for i, field := range st.FieldsValidations { + for _, validation := range field.Validations { + names[i] = append(names[i], validation.Operation) + } + } + return names +} diff --git a/internal/analyzer/operations/operations_list.go b/internal/analyzer/operations/operations_list.go index 55f08a3..47bddb1 100644 --- a/internal/analyzer/operations/operations_list.go +++ b/internal/analyzer/operations/operations_list.go @@ -100,6 +100,18 @@ var operationsList = map[string]Operation{ IsFieldOperation: false, ValidTypes: []string{""}, }, + "oneof": { + CountValues: common.ManyValues, + IsFieldOperation: false, + ValidTypes: []string{""}, + }, + // iscolor is go-playground/validator's alias for hexcolor|rgb|rgba|hsl|hsla. + "hexcolor": zeroStringOp(), + "rgb": zeroStringOp(), + "rgba": zeroStringOp(), + "hsl": zeroStringOp(), + "hsla": zeroStringOp(), + "iscolor": zeroStringOp(), "eqfield": { CountValues: common.OneValue, IsFieldOperation: true, @@ -137,3 +149,11 @@ var operationsList = map[string]Operation{ ValidTypes: nil, }, } + +func zeroStringOp() Operation { + return Operation{ + CountValues: common.ZeroValue, + IsFieldOperation: false, + ValidTypes: []string{""}, + } +} diff --git a/internal/analyzer/operations/operations_test.go b/internal/analyzer/operations/operations_test.go index a10e742..a8e2ce3 100644 --- a/internal/analyzer/operations/operations_test.go +++ b/internal/analyzer/operations/operations_test.go @@ -28,6 +28,13 @@ func TestOperationsIsValid(t *testing.T) { {op: "in", want: true}, {op: "nin", want: true}, {op: "email", want: true}, + {op: "oneof", want: true}, + {op: "hexcolor", want: true}, + {op: "rgb", want: true}, + {op: "rgba", want: true}, + {op: "hsl", want: true}, + {op: "hsla", want: true}, + {op: "iscolor", want: true}, {op: "eqfield", want: true}, {op: "neqfield", want: true}, {op: "gtefield", want: true}, @@ -230,6 +237,63 @@ func TestOperationsIsValidByType(t *testing.T) { valid: true, }, + { + op: "oneof", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + { + op: "hexcolor", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + { + op: "rgb", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + { + op: "rgba", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + { + op: "hsl", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + { + op: "hsla", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + { + op: "iscolor", + fieldTypes: []string{ + "", + "*", + }, + valid: true, + }, + // eqfield operations { op: "eqfield", @@ -303,6 +367,21 @@ func TestOperationsIsValidByType(t *testing.T) { }, valid: false, }, + { + op: "oneof", + fieldTypes: []string{ + "", "", "", + "[]", "map[]", + }, + valid: false, + }, + { + op: "iscolor", + fieldTypes: []string{ + "", "[]", "map[]", + }, + valid: false, + }, { op: "gt", fieldTypes: []string{ @@ -420,6 +499,13 @@ func TestOperationsIsFieldOperation(t *testing.T) { {op: "in", want: false}, {op: "nin", want: false}, {op: "email", want: false}, + {op: "oneof", want: false}, + {op: "hexcolor", want: false}, + {op: "rgb", want: false}, + {op: "rgba", want: false}, + {op: "hsl", want: false}, + {op: "hsla", want: false}, + {op: "iscolor", want: false}, {op: "eqfield", want: true}, {op: "neqfield", want: true}, {op: "gtefield", want: true}, @@ -461,6 +547,13 @@ func TestOperationsArgsCount(t *testing.T) { {op: "in", want: common.ManyValues}, {op: "nin", want: common.ManyValues}, {op: "email", want: common.ZeroValue}, + {op: "oneof", want: common.ManyValues}, + {op: "hexcolor", want: common.ZeroValue}, + {op: "rgb", want: common.ZeroValue}, + {op: "rgba", want: common.ZeroValue}, + {op: "hsl", want: common.ZeroValue}, + {op: "hsla", want: common.ZeroValue}, + {op: "iscolor", want: common.ZeroValue}, {op: "eqfield", want: common.OneValue}, {op: "neqfield", want: common.OneValue}, {op: "gtefield", want: common.OneValue}, diff --git a/internal/analyzer/parser_validation_test.go b/internal/analyzer/parser_validation_test.go index 59cdaaf..cc66374 100644 --- a/internal/analyzer/parser_validation_test.go +++ b/internal/analyzer/parser_validation_test.go @@ -141,6 +141,42 @@ func TestValidParserValidation(t *testing.T) { Values: []string{}, }, }, + { + name: "oneof from the common validator example", + validation: "oneof=male female prefer_not_to", + want: &Validation{ + Operation: "oneof", + ExpectedValues: common.ManyValues, + Values: []string{"male", "female", "prefer_not_to"}, + }, + }, + { + name: "oneof quoted value", + validation: "oneof='prefer not to'", + want: &Validation{ + Operation: "oneof", + ExpectedValues: common.ManyValues, + Values: []string{"prefer not to"}, + }, + }, + { + name: "iscolor alias", + validation: "iscolor", + want: &Validation{ + Operation: "iscolor", + ExpectedValues: common.ZeroValue, + Values: []string{}, + }, + }, + { + name: "hexcolor", + validation: "hexcolor", + want: &Validation{ + Operation: "hexcolor", + ExpectedValues: common.ZeroValue, + Values: []string{}, + }, + }, } for _, tt := range tests { diff --git a/internal/codegenerator/common_example_test.go b/internal/codegenerator/common_example_test.go new file mode 100644 index 0000000..b7ef441 --- /dev/null +++ b/internal/codegenerator/common_example_test.go @@ -0,0 +1,189 @@ +package codegenerator + +import ( + "testing" + + "github.com/opencodeco/validgen/internal/analyzer" + "github.com/opencodeco/validgen/internal/common" + "github.com/opencodeco/validgen/internal/parser" + "github.com/sergi/go-diff/diffmatchpatch" +) + +func TestCommonValidatorExampleCode(t *testing.T) { + analyzed, err := analyzer.AnalyzeStructs(commonExampleStructs()) + if err != nil { + t.Fatal(err) + } + + gv := GenValidations{ + StructsWithValidation: map[string]struct{}{ + "main.User": {}, + "main.Address": {}, + }, + Struct: analyzed[0], + } + got, err := gv.BuildFuncValidatorCode() + if err != nil { + t.Fatal(err) + } + + want := `func UserValidate(obj *User) []error { +var errs []error +if !(obj.FirstName != "") { +errs = append(errs, types.NewValidationError("FirstName is required")) +} +if !(obj.LastName != "") { +errs = append(errs, types.NewValidationError("LastName is required")) +} +if !(obj.Age >= 0) { +errs = append(errs, types.NewValidationError("Age must be >= 0")) +} +if !(obj.Age <= 130) { +errs = append(errs, types.NewValidationError("Age must be <= 130")) +} +if !(obj.Email != "") { +errs = append(errs, types.NewValidationError("Email is required")) +} +if !(types.IsValidEmail(obj.Email)) { +errs = append(errs, types.NewValidationError("Email must be a valid email")) +} +if !(obj.Gender == "male" || obj.Gender == "female" || obj.Gender == "prefer_not_to") { +errs = append(errs, types.NewValidationError("Gender must be one of 'male' 'female' 'prefer_not_to'")) +} +if !(types.IsColor(obj.FavouriteColor)) { +errs = append(errs, types.NewValidationError("FavouriteColor must be a valid color")) +} +if !(len(obj.Addresses) != 0) { +errs = append(errs, types.NewValidationError("Addresses must not be empty")) +} +for _, elem1 := range obj.Addresses { +if !(elem1 != nil) { +errs = append(errs, types.NewValidationError("Addresses is required")) +} +if elem1 != nil { +errs = append(errs, AddressValidate(elem1)...) +} +} +return errs +} +` + if got != want { + dmp := diffmatchpatch.New() + t.Fatalf("UserValidate mismatch\n%s", dmp.DiffPrettyText(dmp.DiffMain(want, got, false))) + } + + gv.Struct = analyzed[1] + got, err = gv.BuildFuncValidatorCode() + if err != nil { + t.Fatal(err) + } + wantAddress := `func AddressValidate(obj *Address) []error { +var errs []error +if !(obj.Street != "") { +errs = append(errs, types.NewValidationError("Street is required")) +} +if !(obj.City != "") { +errs = append(errs, types.NewValidationError("City is required")) +} +if !(obj.Planet != "") { +errs = append(errs, types.NewValidationError("Planet is required")) +} +if !(obj.Phone != "") { +errs = append(errs, types.NewValidationError("Phone is required")) +} +return errs +} +` + if got != wantAddress { + dmp := diffmatchpatch.New() + t.Fatalf("AddressValidate mismatch\n%s", dmp.DiffPrettyText(dmp.DiffMain(wantAddress, got, false))) + } +} + +func TestDiveOneofAndColor(t *testing.T) { + tests := []struct { + name string + fieldName string + fieldType common.FieldType + fieldValidation string + want string + }{ + { + name: "dive iscolor", + fieldName: "Colors", + fieldType: common.FieldType{BaseType: "string", ComposedType: "[]"}, + fieldValidation: "dive,iscolor", + want: `for _, elem1 := range obj.Colors { +if !(types.IsColor(elem1)) { +errs = append(errs, types.NewValidationError("Colors must be a valid color")) +} +} +`, + }, + { + name: "dive oneof on map values", + fieldName: "Labels", + fieldType: common.FieldType{ + BaseType: "string", + ComposedType: "map", + MapValue: &common.FieldType{BaseType: "string"}, + }, + fieldValidation: "dive,oneof=red green blue", + want: `for _, elem1 := range obj.Labels { +if !(elem1 == "red" || elem1 == "green" || elem1 == "blue") { +errs = append(errs, types.NewValidationError("Labels must be one of 'red' 'green' 'blue'")) +} +} +`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gv := GenValidations{} + var validations []*analyzer.Validation + for _, part := range splitValidations(tt.fieldValidation) { + validations = append(validations, AssertParserValidation(t, part)) + } + got, err := gv.BuildValidationCode(tt.fieldName, tt.fieldType, validations) + if err != nil { + t.Fatal(err) + } + if got != tt.want { + t.Fatalf("BuildValidationCode() = %q, want %q", got, tt.want) + } + }) + } +} + +func commonExampleStructs() []*parser.Struct { + return []*parser.Struct{ + { + PackageName: "main", + StructName: "User", + Fields: []parser.Field{ + {FieldName: "FirstName", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "LastName", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Age", Type: common.FieldType{BaseType: "uint8"}, Tag: `validate:"gte=0,lte=130"`}, + {FieldName: "Email", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required,email"`}, + {FieldName: "Gender", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"oneof=male female prefer_not_to"`}, + {FieldName: "FavouriteColor", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"iscolor"`}, + { + FieldName: "Addresses", + Type: common.FieldType{BaseType: "main.Address", ComposedType: "*[]", ElemPointer: true}, + Tag: `validate:"required,dive,required"`, + }, + }, + }, + { + PackageName: "main", + StructName: "Address", + Fields: []parser.Field{ + {FieldName: "Street", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "City", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Planet", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Phone", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + }, + }, + } +} diff --git a/internal/codegenerator/condition_table.go b/internal/codegenerator/condition_table.go index 0c5fed5..b8941c0 100644 --- a/internal/codegenerator/condition_table.go +++ b/internal/codegenerator/condition_table.go @@ -687,6 +687,32 @@ var conditionTable = map[string]Operation{ }, }, }, + "oneof": { + ConditionByTypes: []ConditionByType{ + { + AcceptedTypes: []string{""}, + ConditionTable: ConditionTable{ + operation: `obj.{{.Name}} == "{{.Target}}"`, + concatOperator: "||", + errorMessage: "{{.Name}} must be one of {{.Targets}}", + }, + }, + { + AcceptedTypes: []string{"*"}, + ConditionTable: ConditionTable{ + operation: `(obj.{{.Name}} != nil && *obj.{{.Name}} == "{{.Target}}")`, + concatOperator: "||", + errorMessage: "{{.Name}} must be one of {{.Targets}}", + }, + }, + }, + }, + "hexcolor": stringPredicate("types.IsHexColor", "{{.Name}} must be a valid hex color"), + "rgb": stringPredicate("types.IsRGB", "{{.Name}} must be a valid rgb color"), + "rgba": stringPredicate("types.IsRGBA", "{{.Name}} must be a valid rgba color"), + "hsl": stringPredicate("types.IsHSL", "{{.Name}} must be a valid hsl color"), + "hsla": stringPredicate("types.IsHSLA", "{{.Name}} must be a valid hsla color"), + "iscolor": stringPredicate("types.IsColor", "{{.Name}} must be a valid color"), "eqfield": { ConditionByTypes: []ConditionByType{ { @@ -761,6 +787,29 @@ var conditionTable = map[string]Operation{ }, } +func stringPredicate(call, message string) Operation { + return Operation{ + ConditionByTypes: []ConditionByType{ + { + AcceptedTypes: []string{""}, + ConditionTable: ConditionTable{ + operation: call + `(obj.{{.Name}})`, + concatOperator: "", + errorMessage: message, + }, + }, + { + AcceptedTypes: []string{"*"}, + ConditionTable: ConditionTable{ + operation: `obj.{{.Name}} != nil && ` + call + `(*obj.{{.Name}})`, + concatOperator: "", + errorMessage: message, + }, + }, + }, + } +} + func GetConditionTable(operation string, fieldType common.FieldType) (ConditionTable, error) { op, ok := conditionTable[operation] if !ok { diff --git a/internal/codegenerator/get_test_elements_pointer_test.go b/internal/codegenerator/get_test_elements_pointer_test.go index 93b45b8..8312036 100644 --- a/internal/codegenerator/get_test_elements_pointer_test.go +++ b/internal/codegenerator/get_test_elements_pointer_test.go @@ -92,6 +92,25 @@ func TestDefineTestElementsWithStringPointerFields(t *testing.T) { errorMessage: "Field must be a valid email", }, }, + { + validation: "oneof=male female prefer_not_to", + want: TestElements{ + conditions: []string{ + `(obj.Field != nil && *obj.Field == "male")`, + `(obj.Field != nil && *obj.Field == "female")`, + `(obj.Field != nil && *obj.Field == "prefer_not_to")`, + }, + concatOperator: "||", + errorMessage: "Field must be one of 'male' 'female' 'prefer_not_to'", + }, + }, + { + validation: "iscolor", + want: TestElements{ + conditions: []string{`obj.Field != nil && types.IsColor(*obj.Field)`}, + errorMessage: "Field must be a valid color", + }, + }, } for _, tt := range tests { diff --git a/internal/codegenerator/get_test_elements_string_test.go b/internal/codegenerator/get_test_elements_string_test.go index ff5bac9..6e8f2b6 100644 --- a/internal/codegenerator/get_test_elements_string_test.go +++ b/internal/codegenerator/get_test_elements_string_test.go @@ -152,6 +152,29 @@ func TestDefineTestElementsWithStringFields(t *testing.T) { errorMessage: "EmailField must be a valid email", }, }, + { + name: "oneof from the common validator example", + args: args{ + fieldName: "Gender", + fieldValidation: "oneof=male female prefer_not_to", + }, + want: TestElements{ + conditions: []string{`obj.Gender == "male"`, `obj.Gender == "female"`, `obj.Gender == "prefer_not_to"`}, + concatOperator: "||", + errorMessage: "Gender must be one of 'male' 'female' 'prefer_not_to'", + }, + }, + { + name: "iscolor alias", + args: args{ + fieldName: "FavouriteColor", + fieldValidation: "iscolor", + }, + want: TestElements{ + conditions: []string{`types.IsColor(obj.FavouriteColor)`}, + errorMessage: "FavouriteColor must be a valid color", + }, + }, } for _, tt := range tests { diff --git a/internal/parser/common_example_test.go b/internal/parser/common_example_test.go new file mode 100644 index 0000000..04dd1f1 --- /dev/null +++ b/internal/parser/common_example_test.go @@ -0,0 +1,62 @@ +package parser + +import ( + "reflect" + "testing" + + "github.com/opencodeco/validgen/internal/common" +) + +func TestParseCommonValidatorExample(t *testing.T) { + src := "package main\n" + + "type User struct {\n" + + " FirstName string `validate:\"required\"`\n" + + " LastName string `validate:\"required\"`\n" + + " Age uint8 `validate:\"gte=0,lte=130\"`\n" + + " Email string `validate:\"required,email\"`\n" + + " Gender string `validate:\"oneof=male female prefer_not_to\"`\n" + + " FavouriteColor string `validate:\"iscolor\"`\n" + + " Addresses []*Address `validate:\"required,dive,required\"`\n" + + "}\n" + + "type Address struct {\n" + + " Street string `validate:\"required\"`\n" + + " City string `validate:\"required\"`\n" + + " Planet string `validate:\"required\"`\n" + + " Phone string `validate:\"required\"`\n" + + "}\n" + + got, err := parseStructs("example/main.go", src) + if err != nil { + t.Fatal(err) + } + if len(got) != 2 { + t.Fatalf("struct count = %d, want 2", len(got)) + } + + wantUser := []Field{ + {FieldName: "FirstName", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "LastName", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Age", Type: common.FieldType{BaseType: "uint8"}, Tag: `validate:"gte=0,lte=130"`}, + {FieldName: "Email", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required,email"`}, + {FieldName: "Gender", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"oneof=male female prefer_not_to"`}, + {FieldName: "FavouriteColor", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"iscolor"`}, + { + FieldName: "Addresses", + Type: common.FieldType{BaseType: "main.Address", ComposedType: "*[]", ElemPointer: true}, + Tag: `validate:"required,dive,required"`, + }, + } + if !reflect.DeepEqual(got[0].Fields, wantUser) { + t.Fatalf("User fields mismatch\ngot:\n%swant:\n%s", formatFields(got[0].Fields), formatFields(wantUser)) + } + + wantAddress := []Field{ + {FieldName: "Street", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "City", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Planet", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + {FieldName: "Phone", Type: common.FieldType{BaseType: "string"}, Tag: `validate:"required"`}, + } + if !reflect.DeepEqual(got[1].Fields, wantAddress) { + t.Fatalf("Address fields mismatch\ngot:\n%swant:\n%s", formatFields(got[1].Fields), formatFields(wantAddress)) + } +} diff --git a/tests/endtoend/common_validator_example.go b/tests/endtoend/common_validator_example.go new file mode 100644 index 0000000..358955c --- /dev/null +++ b/tests/endtoend/common_validator_example.go @@ -0,0 +1,133 @@ +package main + +import ( + "log" + + "github.com/opencodeco/validgen/tests/endtoend/commonexample" +) + +func commonValidatorExampleTests() { + log.Println("starting common validator example tests") + + invalid := &commonexample.User{ + FirstName: "Badger", + LastName: "Smith", + Age: 135, + Gender: "male", + Email: "Badger.Smith@gmail.com", + FavouriteColor: "#000-", + Addresses: []*commonexample.Address{{ + Street: "Eavesdown Docks", + Planet: "Persphone", + Phone: "none", + }}, + } + assertExpectedErrorMsgs("playground example", commonexample.UserValidate(invalid), []string{ + "Age must be <= 130", + "FavouriteColor must be a valid color", + "City is required", + }) + + ok := validCommonUser() + assertExpectedErrorMsgs("playground example valid", commonexample.UserValidate(ok), nil) + + for _, color := range []string{ + "#000", + "#aabbcc", + "#aabbccdd", + "rgb(255,255,255)", + "rgba(0,0,0,1)", + "hsl(360,100%,50%)", + "hsla(120,100%,50%,0.5)", + } { + user := validCommonUser() + user.FavouriteColor = color + assertExpectedErrorMsgs("color "+color, commonexample.UserValidate(user), nil) + } + + for _, gender := range []string{"male", "female", "prefer_not_to"} { + user := validCommonUser() + user.Gender = gender + assertExpectedErrorMsgs("gender "+gender, commonexample.UserValidate(user), nil) + } + + badGender := validCommonUser() + badGender.Gender = "other" + assertExpectedErrorMsgs("gender other", commonexample.UserValidate(badGender), []string{ + "Gender must be one of 'male' 'female' 'prefer_not_to'", + }) + + badEmail := validCommonUser() + badEmail.Email = "joeybloggs.gmail.com" + assertExpectedErrorMsgs("email without at", commonexample.UserValidate(badEmail), []string{ + "Email must be a valid email", + }) + + empty := &commonexample.User{} + assertExpectedErrorMsgs("empty user", commonexample.UserValidate(empty), []string{ + "FirstName is required", + "LastName is required", + "Email is required", + "Email must be a valid email", + "Gender must be one of 'male' 'female' 'prefer_not_to'", + "FavouriteColor must be a valid color", + "Addresses must not be empty", + }) + + nilElem := validCommonUser() + nilElem.Addresses = []*commonexample.Address{nil} + assertExpectedErrorMsgs("nil address element", commonexample.UserValidate(nilElem), []string{ + "Addresses is required", + }) + + missingPhone := validCommonUser() + missingPhone.Addresses = append(missingPhone.Addresses, &commonexample.Address{ + Street: "second", + City: "city", + Planet: "Persphone", + }) + assertExpectedErrorMsgs("second address phone", commonexample.UserValidate(missingPhone), []string{ + "Phone is required", + }) + + colors := &commonexample.Palette{ + Colors: []string{"#fff", "nope"}, + Labels: map[string]string{"home": "red"}, + } + assertExpectedErrorMsgs("dive iscolor", commonexample.PaletteValidate(colors), []string{ + "Colors must be a valid color", + }) + + paletteOK := &commonexample.Palette{ + Colors: []string{"#fff", "rgb(0,0,0)"}, + Labels: map[string]string{"not-a-color": "green"}, + } + assertExpectedErrorMsgs("dive color and map value", commonexample.PaletteValidate(paletteOK), nil) + + badLabel := &commonexample.Palette{ + Colors: []string{"#000"}, + Labels: map[string]string{"home": "purple"}, + } + assertExpectedErrorMsgs("dive oneof map value", commonexample.PaletteValidate(badLabel), []string{ + "Labels must be one of 'red' 'green' 'blue'", + }) + + log.Println("common validator example tests ok") +} + +func validCommonUser() *commonexample.User { + return &commonexample.User{ + FirstName: "Badger", + LastName: "Smith", + Age: 30, + Email: "Badger.Smith@gmail.com", + Gender: "male", + FavouriteColor: "#000", + Addresses: []*commonexample.Address{{ + Street: "Eavesdown Docks", + City: "London", + Planet: "Persphone", + Phone: "none", + }}, + } +} diff --git a/tests/endtoend/commonexample/user.go b/tests/endtoend/commonexample/user.go new file mode 100644 index 0000000..f93cd55 --- /dev/null +++ b/tests/endtoend/commonexample/user.go @@ -0,0 +1,27 @@ +package commonexample + +// User is the common go-playground/validator example. +type User struct { + FirstName string `validate:"required"` + LastName string `validate:"required"` + Age uint8 `validate:"gte=0,lte=130"` + Email string `validate:"required,email"` + Gender string `validate:"oneof=male female prefer_not_to"` + FavouriteColor string `validate:"iscolor"` // alias for hexcolor|rgb|rgba|hsl|hsla + Addresses []*Address `validate:"required,dive,required"` +} + +// Address houses a user's address information. +type Address struct { + Street string `validate:"required"` + City string `validate:"required"` + Planet string `validate:"required"` + Phone string `validate:"required"` +} + +// Palette checks oneof and iscolor on elements after dive. +// Map keys are not validated. +type Palette struct { + Colors []string `validate:"dive,iscolor"` + Labels map[string]string `validate:"dive,oneof=red green blue"` +} diff --git a/tests/endtoend/commonexample/validator__.go b/tests/endtoend/commonexample/validator__.go new file mode 100755 index 0000000..246b38c --- /dev/null +++ b/tests/endtoend/commonexample/validator__.go @@ -0,0 +1,78 @@ +// Code generated by ValidGen. DO NOT EDIT. + +//nolint:all +package commonexample + +import ( + "github.com/opencodeco/validgen/types" +) + +func AddressValidate(obj *Address) []error { + var errs []error + if !(obj.Street != "") { + errs = append(errs, types.NewValidationError("Street is required")) + } + if !(obj.City != "") { + errs = append(errs, types.NewValidationError("City is required")) + } + if !(obj.Planet != "") { + errs = append(errs, types.NewValidationError("Planet is required")) + } + if !(obj.Phone != "") { + errs = append(errs, types.NewValidationError("Phone is required")) + } + return errs +} +func PaletteValidate(obj *Palette) []error { + var errs []error + for _, elem1 := range obj.Colors { + if !(types.IsColor(elem1)) { + errs = append(errs, types.NewValidationError("Colors must be a valid color")) + } + } + for _, elem1 := range obj.Labels { + if !(elem1 == "red" || elem1 == "green" || elem1 == "blue") { + errs = append(errs, types.NewValidationError("Labels must be one of 'red' 'green' 'blue'")) + } + } + return errs +} +func UserValidate(obj *User) []error { + var errs []error + if !(obj.FirstName != "") { + errs = append(errs, types.NewValidationError("FirstName is required")) + } + if !(obj.LastName != "") { + errs = append(errs, types.NewValidationError("LastName is required")) + } + if !(obj.Age >= 0) { + errs = append(errs, types.NewValidationError("Age must be >= 0")) + } + if !(obj.Age <= 130) { + errs = append(errs, types.NewValidationError("Age must be <= 130")) + } + if !(obj.Email != "") { + errs = append(errs, types.NewValidationError("Email is required")) + } + if !(types.IsValidEmail(obj.Email)) { + errs = append(errs, types.NewValidationError("Email must be a valid email")) + } + if !(obj.Gender == "male" || obj.Gender == "female" || obj.Gender == "prefer_not_to") { + errs = append(errs, types.NewValidationError("Gender must be one of 'male' 'female' 'prefer_not_to'")) + } + if !(types.IsColor(obj.FavouriteColor)) { + errs = append(errs, types.NewValidationError("FavouriteColor must be a valid color")) + } + if !(len(obj.Addresses) != 0) { + errs = append(errs, types.NewValidationError("Addresses must not be empty")) + } + for _, elem1 := range obj.Addresses { + if !(elem1 != nil) { + errs = append(errs, types.NewValidationError("Addresses is required")) + } + if elem1 != nil { + errs = append(errs, AddressValidate(elem1)...) + } + } + return errs +} diff --git a/tests/endtoend/main.go b/tests/endtoend/main.go index 1316043..93396ea 100644 --- a/tests/endtoend/main.go +++ b/tests/endtoend/main.go @@ -36,6 +36,7 @@ func main() { structInPkgTests() nestedStructTests() diveTests() + commonValidatorExampleTests() cmpBetweenInnerFieldsTests() cmpBetweenNestedFieldsTests() boolTests() diff --git a/types/color.go b/types/color.go new file mode 100644 index 0000000..25c1fe3 --- /dev/null +++ b/types/color.go @@ -0,0 +1,46 @@ +package types + +import "regexp" + +// Color patterns match go-playground/validator v10.28.0. +// iscolor there is the alias hexcolor|rgb|rgba|hsl|hsla. +const ( + hexColorRegexString = "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$" + rgbRegexString = "^rgb\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*\\)$" + rgbaRegexString = "^rgba\\(\\s*(?:(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])|(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%\\s*,\\s*(?:0|[1-9]\\d?|1\\d\\d?|2[0-4]\\d|25[0-5])%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$" + hslRegexString = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$" + hslaRegexString = "^hsla\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0.[1-9]*)|[01])\\s*\\)$" +) + +var ( + hexColorRegex = regexp.MustCompile(hexColorRegexString) + rgbRegex = regexp.MustCompile(rgbRegexString) + rgbaRegex = regexp.MustCompile(rgbaRegexString) + hslRegex = regexp.MustCompile(hslRegexString) + hslaRegex = regexp.MustCompile(hslaRegexString) +) + +func IsHexColor(s string) bool { + return hexColorRegex.MatchString(s) +} + +func IsRGB(s string) bool { + return rgbRegex.MatchString(s) +} + +func IsRGBA(s string) bool { + return rgbaRegex.MatchString(s) +} + +func IsHSL(s string) bool { + return hslRegex.MatchString(s) +} + +func IsHSLA(s string) bool { + return hslaRegex.MatchString(s) +} + +// IsColor reports whether s matches hexcolor, rgb, rgba, hsl, or hsla. +func IsColor(s string) bool { + return IsHexColor(s) || IsRGB(s) || IsRGBA(s) || IsHSL(s) || IsHSLA(s) +} diff --git a/types/color_test.go b/types/color_test.go new file mode 100644 index 0000000..84c345f --- /dev/null +++ b/types/color_test.go @@ -0,0 +1,87 @@ +package types + +import ( + "testing" + + "github.com/go-playground/validator/v10" +) + +func TestColorMatchesValidator(t *testing.T) { + validate := validator.New() + samples := []string{ + "", + "#000", + "#000-", + "#fff", + "#FFFF", + "#aabbcc", + "#aabbccdd", + "#ab", + "#abcde", + "000000", + "rgb(0,0,0)", + "rgb(255,255,255)", + "rgb(255, 255, 255)", + "rgb(0%,0%,0%)", + "rgb(100%, 0%, 50%)", + "rgb(255%,255%,255%)", + "rgb(256,0,0)", + "rgb(0, 0, 0, 1)", + "RGB(0,0,0)", + "rgba(0,0,0,0)", + "rgba(0,0,0,1)", + "rgba(255,255,255,0.5)", + "rgba(0,0,0,0.0)", + "rgba(0%,0%,0%,1)", + "rgba(0,0,0,2)", + "hsl(0,0%,0%)", + "hsl(360,100%,50%)", + "hsl(0, 0%, 0%)", + "hsl(361,0%,0%)", + "hsl(120,50,50)", + "hsla(120,100%,50%,1)", + "hsla(120,100%,50%,0.5)", + "hsla(120,100%,50%,0.0)", + "red", + "blue", + "cmyk(0%,0%,0%,0%)", + "rgb(0,0,0%)", + } + checks := []struct { + tag string + fn func(string) bool + }{ + {tag: "hexcolor", fn: IsHexColor}, + {tag: "rgb", fn: IsRGB}, + {tag: "rgba", fn: IsRGBA}, + {tag: "hsl", fn: IsHSL}, + {tag: "hsla", fn: IsHSLA}, + {tag: "iscolor", fn: IsColor}, + } + + for _, sample := range samples { + for _, check := range checks { + err := validate.Var(sample, check.tag) + got := check.fn(sample) + want := err == nil + if got != want { + t.Errorf("%s %q = %v, validator accepted %v", check.tag, sample, got, want) + } + } + } +} + +func TestCommonExampleColors(t *testing.T) { + if IsColor("#000-") { + t.Fatal(`#000- is the invalid color in the common validator example`) + } + if !IsColor("#000") { + t.Fatal(`#000 should be a color`) + } + if !IsColor("rgb(255,255,255)") { + t.Fatal(`rgb(255,255,255) should be a color`) + } + if IsColor("red") { + t.Fatal(`named colors are outside hexcolor|rgb|rgba|hsl|hsla`) + } +} From c3d7b8d4dcbf60c32ebd5707ccef7fc0c29ba92e Mon Sep 17 00:00:00 2001 From: Leo Cavalcante Date: Tue, 29 Sep 2026 18:58:38 -0300 Subject: [PATCH 2/3] Fix oneof for integers, quotes, and validator ne tags. Reading validate tags also sees the comparison fixtures, so oneof has to accept integers, quoted tokens, and Go string escaping, and ne stays an alias of neq. --- README.md | 4 +- docs/internals.md | 4 +- .../analyzer/operations/operations_list.go | 2 +- .../analyzer/operations/operations_test.go | 6 +- internal/analyzer/parser_validation.go | 79 +- internal/analyzer/parser_validation_test.go | 22 +- internal/codegenerator/build_validator.go | 5 +- internal/codegenerator/common_example_test.go | 39 + internal/codegenerator/condition_table.go | 16 + internal/codegenerator/test_elements.go | 4 + tests/cmpbenchtests/validator__.go | 3164 +++++++++++++++++ 11 files changed, 3301 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index da4d22b..25693e2 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ The following validations will be implemented: - nin (not in): must not be one of the following values - required (required): is required - email (email): must be a valid email format (empty is valid for optional fields) -- oneof (one of): string must be one of the space-separated values +- oneof (one of): string or integer must be one of the space-separated values - hexcolor, rgb, rgba, hsl, hsla: string must match that color format - iscolor: alias for hexcolor, rgb, rgba, hsl, or hsla - eqfield (equal field): field must be equal to another field @@ -141,7 +141,7 @@ The following table shows the validations and possible types, where: | nin | I | I | I | - | I | I | W | - | W | | required | I | I | I | - | I | - | W | W | W | | email | I | - | - | - | - | - | - | - | - | -| oneof | I | - | - | - | - | - | - | - | - | +| oneof | I | I | - | - | - | - | - | - | - | | hexcolor | I | - | - | - | - | - | - | - | - | | rgb | I | - | - | - | - | - | - | - | - | | rgba | I | - | - | - | - | - | - | - | - | diff --git a/docs/internals.md b/docs/internals.md index b9a1a5f..0fdaedf 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -76,7 +76,7 @@ Slices, arrays, maps, and pointers keep a marker on that name, such as `[]` `ParserValidation` splits one validation on `=`. More than two pieces is an error. The operation's `CountValues` selects the shape. -`ZeroValue` operations `required`, `email`, `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` reject a target. `OneValue` operations require one target. `ManyValues` operations `in`, `nin`, and `oneof` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. `iscolor` is the alias for `hexcolor|rgb|rgba|hsl|hsla` and calls `types.IsColor`. +`ZeroValue` operations `required`, `email`, `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` reject a target. `OneValue` operations require one target. `ManyValues` operations `in`, `nin`, and `oneof` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. `iscolor` is the alias for `hexcolor|rgb|rgba|hsl|hsla` and calls `types.IsColor`. `ne` and `ne_ignore_case` are read as `neq` and `neq_ignore_case`. The result is an `analyzer.Validation` with `Operation`, `ExpectedValues`, and `Values`. @@ -144,7 +144,7 @@ errs = append(errs, types.NewValidationError("message")) Scalar `in` rows set `concatOperator` to `||`, and the per-value copies are joined. That includes ``, `*`, `*`, `*`, and `*`. Scalar `nin` rows set `concatOperator` to `&&`. Complex scalar rows use the same `==` / `!=` form as numeric scalars, with the tag literal left unquoted. Slice, array, and map rows leave `concatOperator` empty, so `DefineTestElements` keeps one copy. That copy lists every target through `{{.TargetsAsStringSlice}}` or `{{.TargetsAsNumericSlice}}`. -Those slice and map copies call `types.SliceOnlyContains`, `types.SliceNotContains`, `types.MapOnlyContains`, or `types.MapNotContains`. Non-pointer array rows pass `obj.Field[:]` into the slice helpers. Literal string comparisons quote the target. `email` calls `types.IsValidEmail`. `oneof` uses the same string equality as scalar `in`. `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` call the matching `types` helpers. `eq_ignore_case` and `neq_ignore_case` call `strings.EqualFold`. Field comparisons compile to `obj.Field` compared with `obj.Other` or `obj.Nested.Field`. +Those slice and map copies call `types.SliceOnlyContains`, `types.SliceNotContains`, `types.MapOnlyContains`, or `types.MapNotContains`. Non-pointer array rows pass `obj.Field[:]` into the slice helpers. Literal string comparisons quote the target. `email` calls `types.IsValidEmail`. `oneof` uses the same equality as scalar `in` for strings and integers. String targets are emitted as Go string literals. `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` call the matching `types` helpers. `eq_ignore_case` and `neq_ignore_case` call `strings.EqualFold`. Field comparisons compile to `obj.Field` compared with `obj.Other` or `obj.Nested.Field`. When the field is a struct or a pointer to a struct, each validation on that field appends a nested call instead of a condition-table test. The call is `TypeValidate(&obj.Field)`, where `Type` is `BaseType`. If `BaseType` starts with the struct's own package name and a dot, that prefix is removed. A same-package field whose `BaseType` is `main.InnerStructType` calls `InnerStructTypeValidate`. A field whose `BaseType` is `mypkg.InnerStructType` calls `mypkg.InnerStructTypeValidate`. The call is emitted when `BaseType` is in the parsed-struct index. A missing type returns `no validator found for struct type`. diff --git a/internal/analyzer/operations/operations_list.go b/internal/analyzer/operations/operations_list.go index 77f3985..2bb87a6 100644 --- a/internal/analyzer/operations/operations_list.go +++ b/internal/analyzer/operations/operations_list.go @@ -103,7 +103,7 @@ var operationsList = map[string]Operation{ "oneof": { CountValues: common.ManyValues, IsFieldOperation: false, - ValidTypes: []string{""}, + ValidTypes: []string{"", ""}, }, // iscolor is go-playground/validator's alias for hexcolor|rgb|rgba|hsl|hsla. "hexcolor": zeroStringOp(), diff --git a/internal/analyzer/operations/operations_test.go b/internal/analyzer/operations/operations_test.go index eb8db90..172faec 100644 --- a/internal/analyzer/operations/operations_test.go +++ b/internal/analyzer/operations/operations_test.go @@ -240,8 +240,8 @@ func TestOperationsIsValidByType(t *testing.T) { { op: "oneof", fieldTypes: []string{ - "", - "*", + "", "", + "*", "*", }, valid: true, }, @@ -370,7 +370,7 @@ func TestOperationsIsValidByType(t *testing.T) { { op: "oneof", fieldTypes: []string{ - "", "", "", + "", "", "[]", "map[]", }, valid: false, diff --git a/internal/analyzer/parser_validation.go b/internal/analyzer/parser_validation.go index 57d9eca..f87c069 100644 --- a/internal/analyzer/parser_validation.go +++ b/internal/analyzer/parser_validation.go @@ -45,7 +45,7 @@ func parserValidationString(tag string) (string, string, error) { return "", "", types.NewValidationError("malformed validation %s", tag) } - validation := strings.TrimSpace(tokens[0]) + validation := canonicalOperation(strings.TrimSpace(tokens[0])) values := "" if len(tokens) == 2 { values = tokens[1] @@ -54,6 +54,17 @@ func parserValidationString(tag string) (string, string, error) { return validation, values, nil } +func canonicalOperation(validation string) string { + switch validation { + case "ne": + return "neq" + case "ne_ignore_case": + return "neq_ignore_case" + default: + return validation + } +} + func parserZeroValue(validation string, valuesCount common.CountValues, targets string) (*Validation, error) { if targets != "" { return nil, types.NewValidationError("expected zero target, but has %s", targets) @@ -83,46 +94,50 @@ func parserManyValues(validation string, valuesCount common.CountValues, targets return nil, types.NewValidationError("expected at least one target, but has 0 element(s)") } - targetValues := targets + values, err := splitManyValues(targets) + if err != nil { + return nil, err + } + if len(values) == 0 { + return nil, types.NewValidationError("expected at least one target, but has 0 element(s)") + } - if targetValues[0] == '\'' { - values := []string{} - for { - first := strings.IndexByte(targetValues, '\'') - if first == -1 { - break - } + return &Validation{ + Operation: validation, + ExpectedValues: valuesCount, + Values: values, + }, nil +} - if first != 0 { - // ' must be the first chr - return nil, types.NewValidationError("invalid quote value in %s", targets) - } +// splitManyValues reads a oneof/in list. Spaces and commas separate tokens. +// A single-quoted token may contain spaces, and quoted tokens may be mixed +// with bare tokens, matching go-playground/validator oneof. +func splitManyValues(targets string) ([]string, error) { + values := []string{} + for i := 0; i < len(targets); { + if targets[i] == ' ' || targets[i] == ',' { + i++ + continue + } - second := strings.IndexByte(targetValues[first+1:], '\'') - if second == -1 { + if targets[i] == '\'' { + end := strings.IndexByte(targets[i+1:], '\'') + if end == -1 { return nil, types.NewValidationError("invalid quote value in %s", targets) } - values = append(values, targetValues[first+1:second+1]) - targetValues = strings.TrimSpace(targetValues[second+2:]) + values = append(values, targets[i+1:i+1+end]) + i += end + 2 + continue } - return &Validation{ - Operation: validation, - ExpectedValues: valuesCount, - Values: values, - }, nil + start := i + for i < len(targets) && targets[i] != ' ' && targets[i] != ',' { + i++ + } + values = append(values, targets[start:i]) } - // Break by commas or spaces. - targetValues = strings.ReplaceAll(targetValues, " ", ",") - values := strings.Split(targetValues, ",") - values = removeEmptyValues(values) - - return &Validation{ - Operation: validation, - ExpectedValues: valuesCount, - Values: values, - }, nil + return values, nil } func removeEmptyValues(input []string) []string { diff --git a/internal/analyzer/parser_validation_test.go b/internal/analyzer/parser_validation_test.go index cc66374..be669c0 100644 --- a/internal/analyzer/parser_validation_test.go +++ b/internal/analyzer/parser_validation_test.go @@ -152,11 +152,11 @@ func TestValidParserValidation(t *testing.T) { }, { name: "oneof quoted value", - validation: "oneof='prefer not to'", + validation: "oneof='prefer not to' other", want: &Validation{ Operation: "oneof", ExpectedValues: common.ManyValues, - Values: []string{"prefer not to"}, + Values: []string{"prefer not to", "other"}, }, }, { @@ -168,6 +168,24 @@ func TestValidParserValidation(t *testing.T) { Values: []string{}, }, }, + { + name: "validator ne alias", + validation: "ne=abcde", + want: &Validation{ + Operation: "neq", + ExpectedValues: common.OneValue, + Values: []string{"abcde"}, + }, + }, + { + name: "validator ne_ignore_case alias", + validation: "ne_ignore_case=abcde", + want: &Validation{ + Operation: "neq_ignore_case", + ExpectedValues: common.OneValue, + Values: []string{"abcde"}, + }, + }, { name: "hexcolor", validation: "hexcolor", diff --git a/internal/codegenerator/build_validator.go b/internal/codegenerator/build_validator.go index 8a2d492..cab5df8 100644 --- a/internal/codegenerator/build_validator.go +++ b/internal/codegenerator/build_validator.go @@ -3,6 +3,7 @@ package codegenerator import ( "bytes" "fmt" + "strconv" "strings" "text/template" @@ -195,9 +196,9 @@ func (gv *GenValidations) buildIfCode(expr, fieldName string, fieldType common.F return fmt.Sprintf( `if !(%s) { -errs = append(errs, types.NewValidationError("%s")) +errs = append(errs, types.NewValidationError(%s)) } -`, booleanCondition, testElements.errorMessage), nil +`, booleanCondition, strconv.Quote(testElements.errorMessage)), nil } func (gv *GenValidations) buildIfNestedCode(fieldName string, fieldType common.FieldType) (string, error) { diff --git a/internal/codegenerator/common_example_test.go b/internal/codegenerator/common_example_test.go index b7ef441..34b6a36 100644 --- a/internal/codegenerator/common_example_test.go +++ b/internal/codegenerator/common_example_test.go @@ -1,6 +1,9 @@ package codegenerator import ( + goparser "go/parser" + "go/token" + "reflect" "testing" "github.com/opencodeco/validgen/internal/analyzer" @@ -100,6 +103,42 @@ return errs } } +func TestOneofIntegerAndQuotedTarget(t *testing.T) { + intType := common.FieldType{BaseType: "int"} + parsed := AssertParserValidation(t, "oneof=12 34 56") + got, err := DefineTestElements("Field", intType, parsed) + if err != nil { + t.Fatal(err) + } + want := TestElements{ + conditions: []string{"obj.Field == 12", "obj.Field == 34", "obj.Field == 56"}, + concatOperator: "||", + errorMessage: "Field must be one of '12' '34' '56'", + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("int oneof = %+v, want %+v", got, want) + } + + quoted := AssertParserValidation(t, `oneof='say "hi"'`) + got, err = DefineTestElements("Field", common.FieldType{BaseType: "string"}, quoted) + if err != nil { + t.Fatal(err) + } + if len(got.conditions) != 1 || got.conditions[0] != `obj.Field == "say \"hi\""` { + t.Fatalf("quoted oneof condition = %#v", got.conditions) + } + + gv := GenValidations{} + code, err := gv.BuildValidationCode("Field", common.FieldType{BaseType: "string"}, []*analyzer.Validation{quoted}) + if err != nil { + t.Fatal(err) + } + src := "package p\nfunc f() {\n" + code + "}\n" + if _, err := goparser.ParseFile(token.NewFileSet(), "oneof.go", src, 0); err != nil { + t.Fatalf("generated oneof does not compile: %v\n%s", err, code) + } +} + func TestDiveOneofAndColor(t *testing.T) { tests := []struct { name string diff --git a/internal/codegenerator/condition_table.go b/internal/codegenerator/condition_table.go index 4cb0268..b8185b6 100644 --- a/internal/codegenerator/condition_table.go +++ b/internal/codegenerator/condition_table.go @@ -705,6 +705,22 @@ var conditionTable = map[string]Operation{ errorMessage: "{{.Name}} must be one of {{.Targets}}", }, }, + { + AcceptedTypes: []string{""}, + ConditionTable: ConditionTable{ + operation: `obj.{{.Name}} == {{.Target}}`, + concatOperator: "||", + errorMessage: "{{.Name}} must be one of {{.Targets}}", + }, + }, + { + AcceptedTypes: []string{"*"}, + ConditionTable: ConditionTable{ + operation: `(obj.{{.Name}} != nil && *obj.{{.Name}} == {{.Target}})`, + concatOperator: "||", + errorMessage: "{{.Name}} must be one of {{.Targets}}", + }, + }, }, }, "hexcolor": stringPredicate("types.IsHexColor", "{{.Name}} must be a valid hex color"), diff --git a/internal/codegenerator/test_elements.go b/internal/codegenerator/test_elements.go index 9a37b60..07ecd3a 100644 --- a/internal/codegenerator/test_elements.go +++ b/internal/codegenerator/test_elements.go @@ -1,6 +1,7 @@ package codegenerator import ( + "strconv" "strings" "github.com/opencodeco/validgen/internal/analyzer" @@ -66,6 +67,9 @@ func defineTestElements(expr, fieldName string, fieldType common.FieldType, fiel func replaceExprNameAndTarget(text, expr, name, target string) string { text = strings.ReplaceAll(text, "obj.{{.Name}}", expr) text = strings.ReplaceAll(text, "{{.Name}}", name) + if strings.Contains(text, `"{{.Target}}"`) { + text = strings.ReplaceAll(text, `"{{.Target}}"`, strconv.Quote(target)) + } text = strings.ReplaceAll(text, "{{.Target}}", target) return text diff --git a/tests/cmpbenchtests/validator__.go b/tests/cmpbenchtests/validator__.go index 53f2c25..cabe7dd 100755 --- a/tests/cmpbenchtests/validator__.go +++ b/tests/cmpbenchtests/validator__.go @@ -3173,3 +3173,3167 @@ func ValidGenRequiredUintStructValidate(obj *ValidGenRequiredUintStruct) []error } return errs } +func ValidatorEmailStringPointerStructValidate(obj *ValidatorEmailStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && types.IsValidEmail(*obj.Field)) { + errs = append(errs, types.NewValidationError("Field must be a valid email")) + } + return errs +} +func ValidatorEmailStringStructValidate(obj *ValidatorEmailStringStruct) []error { + var errs []error + if !(types.IsValidEmail(obj.Field)) { + errs = append(errs, types.NewValidationError("Field must be a valid email")) + } + return errs +} +func ValidatorEqBoolPointerStructValidate(obj *ValidatorEqBoolPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == true) { + errs = append(errs, types.NewValidationError("Field must be equal to true")) + } + return errs +} +func ValidatorEqBoolStructValidate(obj *ValidatorEqBoolStruct) []error { + var errs []error + if !(obj.Field == true) { + errs = append(errs, types.NewValidationError("Field must be equal to true")) + } + return errs +} +func ValidatorEqFloat32PointerStructValidate(obj *ValidatorEqFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 12.34) { + errs = append(errs, types.NewValidationError("Field must be equal to 12.34")) + } + return errs +} +func ValidatorEqFloat32StructValidate(obj *ValidatorEqFloat32Struct) []error { + var errs []error + if !(obj.Field == 12.34) { + errs = append(errs, types.NewValidationError("Field must be equal to 12.34")) + } + return errs +} +func ValidatorEqFloat64PointerStructValidate(obj *ValidatorEqFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 12.34) { + errs = append(errs, types.NewValidationError("Field must be equal to 12.34")) + } + return errs +} +func ValidatorEqFloat64StructValidate(obj *ValidatorEqFloat64Struct) []error { + var errs []error + if !(obj.Field == 12.34) { + errs = append(errs, types.NewValidationError("Field must be equal to 12.34")) + } + return errs +} +func ValidatorEqInt16PointerStructValidate(obj *ValidatorEqInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt16StructValidate(obj *ValidatorEqInt16Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt32PointerStructValidate(obj *ValidatorEqInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt32StructValidate(obj *ValidatorEqInt32Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt64PointerStructValidate(obj *ValidatorEqInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt64StructValidate(obj *ValidatorEqInt64Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt8PointerStructValidate(obj *ValidatorEqInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqInt8StructValidate(obj *ValidatorEqInt8Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqIntPointerStructValidate(obj *ValidatorEqIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqIntStructValidate(obj *ValidatorEqIntStruct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqStringPointerStructValidate(obj *ValidatorEqStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == "abcde") { + errs = append(errs, types.NewValidationError("Field must be equal to 'abcde'")) + } + return errs +} +func ValidatorEqStringStructValidate(obj *ValidatorEqStringStruct) []error { + var errs []error + if !(obj.Field == "abcde") { + errs = append(errs, types.NewValidationError("Field must be equal to 'abcde'")) + } + return errs +} +func ValidatorEqUint16PointerStructValidate(obj *ValidatorEqUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint16StructValidate(obj *ValidatorEqUint16Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint32PointerStructValidate(obj *ValidatorEqUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint32StructValidate(obj *ValidatorEqUint32Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint64PointerStructValidate(obj *ValidatorEqUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint64StructValidate(obj *ValidatorEqUint64Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint8PointerStructValidate(obj *ValidatorEqUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUint8StructValidate(obj *ValidatorEqUint8Struct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUintPointerStructValidate(obj *ValidatorEqUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEqUintStructValidate(obj *ValidatorEqUintStruct) []error { + var errs []error + if !(obj.Field == 32) { + errs = append(errs, types.NewValidationError("Field must be equal to 32")) + } + return errs +} +func ValidatorEq_ignore_caseStringPointerStructValidate(obj *ValidatorEq_ignore_caseStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && strings.EqualFold(*obj.Field, "abcde")) { + errs = append(errs, types.NewValidationError("Field must be equal to 'abcde'")) + } + return errs +} +func ValidatorEq_ignore_caseStringStructValidate(obj *ValidatorEq_ignore_caseStringStruct) []error { + var errs []error + if !(strings.EqualFold(obj.Field, "abcde")) { + errs = append(errs, types.NewValidationError("Field must be equal to 'abcde'")) + } + return errs +} +func ValidatorGtFloat32PointerStructValidate(obj *ValidatorGtFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 12.34) { + errs = append(errs, types.NewValidationError("Field must be > 12.34")) + } + return errs +} +func ValidatorGtFloat32StructValidate(obj *ValidatorGtFloat32Struct) []error { + var errs []error + if !(obj.Field > 12.34) { + errs = append(errs, types.NewValidationError("Field must be > 12.34")) + } + return errs +} +func ValidatorGtFloat64PointerStructValidate(obj *ValidatorGtFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 12.34) { + errs = append(errs, types.NewValidationError("Field must be > 12.34")) + } + return errs +} +func ValidatorGtFloat64StructValidate(obj *ValidatorGtFloat64Struct) []error { + var errs []error + if !(obj.Field > 12.34) { + errs = append(errs, types.NewValidationError("Field must be > 12.34")) + } + return errs +} +func ValidatorGtInt16PointerStructValidate(obj *ValidatorGtInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt16StructValidate(obj *ValidatorGtInt16Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt32PointerStructValidate(obj *ValidatorGtInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt32StructValidate(obj *ValidatorGtInt32Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt64PointerStructValidate(obj *ValidatorGtInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt64StructValidate(obj *ValidatorGtInt64Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt8PointerStructValidate(obj *ValidatorGtInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtInt8StructValidate(obj *ValidatorGtInt8Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtIntPointerStructValidate(obj *ValidatorGtIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtIntStructValidate(obj *ValidatorGtIntStruct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint16PointerStructValidate(obj *ValidatorGtUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint16StructValidate(obj *ValidatorGtUint16Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint32PointerStructValidate(obj *ValidatorGtUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint32StructValidate(obj *ValidatorGtUint32Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint64PointerStructValidate(obj *ValidatorGtUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint64StructValidate(obj *ValidatorGtUint64Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint8PointerStructValidate(obj *ValidatorGtUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUint8StructValidate(obj *ValidatorGtUint8Struct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUintPointerStructValidate(obj *ValidatorGtUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGtUintStructValidate(obj *ValidatorGtUintStruct) []error { + var errs []error + if !(obj.Field > 32) { + errs = append(errs, types.NewValidationError("Field must be > 32")) + } + return errs +} +func ValidatorGteFloat32PointerStructValidate(obj *ValidatorGteFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 12.34) { + errs = append(errs, types.NewValidationError("Field must be >= 12.34")) + } + return errs +} +func ValidatorGteFloat32StructValidate(obj *ValidatorGteFloat32Struct) []error { + var errs []error + if !(obj.Field >= 12.34) { + errs = append(errs, types.NewValidationError("Field must be >= 12.34")) + } + return errs +} +func ValidatorGteFloat64PointerStructValidate(obj *ValidatorGteFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 12.34) { + errs = append(errs, types.NewValidationError("Field must be >= 12.34")) + } + return errs +} +func ValidatorGteFloat64StructValidate(obj *ValidatorGteFloat64Struct) []error { + var errs []error + if !(obj.Field >= 12.34) { + errs = append(errs, types.NewValidationError("Field must be >= 12.34")) + } + return errs +} +func ValidatorGteInt16PointerStructValidate(obj *ValidatorGteInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt16StructValidate(obj *ValidatorGteInt16Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt32PointerStructValidate(obj *ValidatorGteInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt32StructValidate(obj *ValidatorGteInt32Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt64PointerStructValidate(obj *ValidatorGteInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt64StructValidate(obj *ValidatorGteInt64Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt8PointerStructValidate(obj *ValidatorGteInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteInt8StructValidate(obj *ValidatorGteInt8Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteIntPointerStructValidate(obj *ValidatorGteIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteIntStructValidate(obj *ValidatorGteIntStruct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint16PointerStructValidate(obj *ValidatorGteUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint16StructValidate(obj *ValidatorGteUint16Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint32PointerStructValidate(obj *ValidatorGteUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint32StructValidate(obj *ValidatorGteUint32Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint64PointerStructValidate(obj *ValidatorGteUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint64StructValidate(obj *ValidatorGteUint64Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint8PointerStructValidate(obj *ValidatorGteUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUint8StructValidate(obj *ValidatorGteUint8Struct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUintPointerStructValidate(obj *ValidatorGteUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorGteUintStructValidate(obj *ValidatorGteUintStruct) []error { + var errs []error + if !(obj.Field >= 32) { + errs = append(errs, types.NewValidationError("Field must be >= 32")) + } + return errs +} +func ValidatorInInt16PointerStructValidate(obj *ValidatorInInt16PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt16StructValidate(obj *ValidatorInInt16Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt32PointerStructValidate(obj *ValidatorInInt32PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt32StructValidate(obj *ValidatorInInt32Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt64PointerStructValidate(obj *ValidatorInInt64PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt64StructValidate(obj *ValidatorInInt64Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt8PointerStructValidate(obj *ValidatorInInt8PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInInt8StructValidate(obj *ValidatorInInt8Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInIntPointerStructValidate(obj *ValidatorInIntPointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInIntStructValidate(obj *ValidatorInIntStruct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInStringPointerStructValidate(obj *ValidatorInStringPointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == "ab") || (obj.Field != nil && *obj.Field == "cd") || (obj.Field != nil && *obj.Field == "ef")) { + errs = append(errs, types.NewValidationError("Field must be one of 'ab' 'cd' 'ef'")) + } + return errs +} +func ValidatorInStringStructValidate(obj *ValidatorInStringStruct) []error { + var errs []error + if !(obj.Field == "ab" || obj.Field == "cd" || obj.Field == "ef") { + errs = append(errs, types.NewValidationError("Field must be one of 'ab' 'cd' 'ef'")) + } + return errs +} +func ValidatorInUint16PointerStructValidate(obj *ValidatorInUint16PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint16StructValidate(obj *ValidatorInUint16Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint32PointerStructValidate(obj *ValidatorInUint32PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint32StructValidate(obj *ValidatorInUint32Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint64PointerStructValidate(obj *ValidatorInUint64PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint64StructValidate(obj *ValidatorInUint64Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint8PointerStructValidate(obj *ValidatorInUint8PointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUint8StructValidate(obj *ValidatorInUint8Struct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUintPointerStructValidate(obj *ValidatorInUintPointerStruct) []error { + var errs []error + if !((obj.Field != nil && *obj.Field == 12) || (obj.Field != nil && *obj.Field == 34) || (obj.Field != nil && *obj.Field == 56)) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorInUintStructValidate(obj *ValidatorInUintStruct) []error { + var errs []error + if !(obj.Field == 12 || obj.Field == 34 || obj.Field == 56) { + errs = append(errs, types.NewValidationError("Field must be one of '12' '34' '56'")) + } + return errs +} +func ValidatorLenBoolMapPointerStructValidate(obj *ValidatorLenBoolMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenBoolMapStructValidate(obj *ValidatorLenBoolMapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenBoolSlicePointerStructValidate(obj *ValidatorLenBoolSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenBoolSliceStructValidate(obj *ValidatorLenBoolSliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat32MapPointerStructValidate(obj *ValidatorLenFloat32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat32MapStructValidate(obj *ValidatorLenFloat32MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat32SlicePointerStructValidate(obj *ValidatorLenFloat32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat32SliceStructValidate(obj *ValidatorLenFloat32SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat64MapPointerStructValidate(obj *ValidatorLenFloat64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat64MapStructValidate(obj *ValidatorLenFloat64MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat64SlicePointerStructValidate(obj *ValidatorLenFloat64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenFloat64SliceStructValidate(obj *ValidatorLenFloat64SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt16MapPointerStructValidate(obj *ValidatorLenInt16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt16MapStructValidate(obj *ValidatorLenInt16MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt16SlicePointerStructValidate(obj *ValidatorLenInt16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt16SliceStructValidate(obj *ValidatorLenInt16SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt32MapPointerStructValidate(obj *ValidatorLenInt32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt32MapStructValidate(obj *ValidatorLenInt32MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt32SlicePointerStructValidate(obj *ValidatorLenInt32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt32SliceStructValidate(obj *ValidatorLenInt32SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt64MapPointerStructValidate(obj *ValidatorLenInt64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt64MapStructValidate(obj *ValidatorLenInt64MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt64SlicePointerStructValidate(obj *ValidatorLenInt64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt64SliceStructValidate(obj *ValidatorLenInt64SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt8MapPointerStructValidate(obj *ValidatorLenInt8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt8MapStructValidate(obj *ValidatorLenInt8MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt8SlicePointerStructValidate(obj *ValidatorLenInt8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenInt8SliceStructValidate(obj *ValidatorLenInt8SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenIntMapPointerStructValidate(obj *ValidatorLenIntMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenIntMapStructValidate(obj *ValidatorLenIntMapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenIntSlicePointerStructValidate(obj *ValidatorLenIntSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenIntSliceStructValidate(obj *ValidatorLenIntSliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenStringMapPointerStructValidate(obj *ValidatorLenStringMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenStringMapStructValidate(obj *ValidatorLenStringMapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenStringPointerStructValidate(obj *ValidatorLenStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field length must be 2")) + } + return errs +} +func ValidatorLenStringSlicePointerStructValidate(obj *ValidatorLenStringSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenStringSliceStructValidate(obj *ValidatorLenStringSliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenStringStructValidate(obj *ValidatorLenStringStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field length must be 2")) + } + return errs +} +func ValidatorLenUint16MapPointerStructValidate(obj *ValidatorLenUint16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint16MapStructValidate(obj *ValidatorLenUint16MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint16SlicePointerStructValidate(obj *ValidatorLenUint16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint16SliceStructValidate(obj *ValidatorLenUint16SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint32MapPointerStructValidate(obj *ValidatorLenUint32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint32MapStructValidate(obj *ValidatorLenUint32MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint32SlicePointerStructValidate(obj *ValidatorLenUint32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint32SliceStructValidate(obj *ValidatorLenUint32SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint64MapPointerStructValidate(obj *ValidatorLenUint64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint64MapStructValidate(obj *ValidatorLenUint64MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint64SlicePointerStructValidate(obj *ValidatorLenUint64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint64SliceStructValidate(obj *ValidatorLenUint64SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint8MapPointerStructValidate(obj *ValidatorLenUint8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint8MapStructValidate(obj *ValidatorLenUint8MapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint8SlicePointerStructValidate(obj *ValidatorLenUint8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUint8SliceStructValidate(obj *ValidatorLenUint8SliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUintMapPointerStructValidate(obj *ValidatorLenUintMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUintMapStructValidate(obj *ValidatorLenUintMapStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUintSlicePointerStructValidate(obj *ValidatorLenUintSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLenUintSliceStructValidate(obj *ValidatorLenUintSliceStruct) []error { + var errs []error + if !(len(obj.Field) == 2) { + errs = append(errs, types.NewValidationError("Field must have exactly 2 elements")) + } + return errs +} +func ValidatorLtFloat32PointerStructValidate(obj *ValidatorLtFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 12.34) { + errs = append(errs, types.NewValidationError("Field must be < 12.34")) + } + return errs +} +func ValidatorLtFloat32StructValidate(obj *ValidatorLtFloat32Struct) []error { + var errs []error + if !(obj.Field < 12.34) { + errs = append(errs, types.NewValidationError("Field must be < 12.34")) + } + return errs +} +func ValidatorLtFloat64PointerStructValidate(obj *ValidatorLtFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 12.34) { + errs = append(errs, types.NewValidationError("Field must be < 12.34")) + } + return errs +} +func ValidatorLtFloat64StructValidate(obj *ValidatorLtFloat64Struct) []error { + var errs []error + if !(obj.Field < 12.34) { + errs = append(errs, types.NewValidationError("Field must be < 12.34")) + } + return errs +} +func ValidatorLtInt16PointerStructValidate(obj *ValidatorLtInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt16StructValidate(obj *ValidatorLtInt16Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt32PointerStructValidate(obj *ValidatorLtInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt32StructValidate(obj *ValidatorLtInt32Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt64PointerStructValidate(obj *ValidatorLtInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt64StructValidate(obj *ValidatorLtInt64Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt8PointerStructValidate(obj *ValidatorLtInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtInt8StructValidate(obj *ValidatorLtInt8Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtIntPointerStructValidate(obj *ValidatorLtIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtIntStructValidate(obj *ValidatorLtIntStruct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint16PointerStructValidate(obj *ValidatorLtUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint16StructValidate(obj *ValidatorLtUint16Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint32PointerStructValidate(obj *ValidatorLtUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint32StructValidate(obj *ValidatorLtUint32Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint64PointerStructValidate(obj *ValidatorLtUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint64StructValidate(obj *ValidatorLtUint64Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint8PointerStructValidate(obj *ValidatorLtUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUint8StructValidate(obj *ValidatorLtUint8Struct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUintPointerStructValidate(obj *ValidatorLtUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLtUintStructValidate(obj *ValidatorLtUintStruct) []error { + var errs []error + if !(obj.Field < 32) { + errs = append(errs, types.NewValidationError("Field must be < 32")) + } + return errs +} +func ValidatorLteFloat32PointerStructValidate(obj *ValidatorLteFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 12.34) { + errs = append(errs, types.NewValidationError("Field must be <= 12.34")) + } + return errs +} +func ValidatorLteFloat32StructValidate(obj *ValidatorLteFloat32Struct) []error { + var errs []error + if !(obj.Field <= 12.34) { + errs = append(errs, types.NewValidationError("Field must be <= 12.34")) + } + return errs +} +func ValidatorLteFloat64PointerStructValidate(obj *ValidatorLteFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 12.34) { + errs = append(errs, types.NewValidationError("Field must be <= 12.34")) + } + return errs +} +func ValidatorLteFloat64StructValidate(obj *ValidatorLteFloat64Struct) []error { + var errs []error + if !(obj.Field <= 12.34) { + errs = append(errs, types.NewValidationError("Field must be <= 12.34")) + } + return errs +} +func ValidatorLteInt16PointerStructValidate(obj *ValidatorLteInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt16StructValidate(obj *ValidatorLteInt16Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt32PointerStructValidate(obj *ValidatorLteInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt32StructValidate(obj *ValidatorLteInt32Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt64PointerStructValidate(obj *ValidatorLteInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt64StructValidate(obj *ValidatorLteInt64Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt8PointerStructValidate(obj *ValidatorLteInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteInt8StructValidate(obj *ValidatorLteInt8Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteIntPointerStructValidate(obj *ValidatorLteIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteIntStructValidate(obj *ValidatorLteIntStruct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint16PointerStructValidate(obj *ValidatorLteUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint16StructValidate(obj *ValidatorLteUint16Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint32PointerStructValidate(obj *ValidatorLteUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint32StructValidate(obj *ValidatorLteUint32Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint64PointerStructValidate(obj *ValidatorLteUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint64StructValidate(obj *ValidatorLteUint64Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint8PointerStructValidate(obj *ValidatorLteUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUint8StructValidate(obj *ValidatorLteUint8Struct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUintPointerStructValidate(obj *ValidatorLteUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorLteUintStructValidate(obj *ValidatorLteUintStruct) []error { + var errs []error + if !(obj.Field <= 32) { + errs = append(errs, types.NewValidationError("Field must be <= 32")) + } + return errs +} +func ValidatorMaxBoolMapPointerStructValidate(obj *ValidatorMaxBoolMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 1) { + errs = append(errs, types.NewValidationError("Field must have at most 1 elements")) + } + return errs +} +func ValidatorMaxBoolMapStructValidate(obj *ValidatorMaxBoolMapStruct) []error { + var errs []error + if !(len(obj.Field) <= 1) { + errs = append(errs, types.NewValidationError("Field must have at most 1 elements")) + } + return errs +} +func ValidatorMaxBoolSlicePointerStructValidate(obj *ValidatorMaxBoolSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxBoolSliceStructValidate(obj *ValidatorMaxBoolSliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat32MapPointerStructValidate(obj *ValidatorMaxFloat32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat32MapStructValidate(obj *ValidatorMaxFloat32MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat32SlicePointerStructValidate(obj *ValidatorMaxFloat32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat32SliceStructValidate(obj *ValidatorMaxFloat32SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat64MapPointerStructValidate(obj *ValidatorMaxFloat64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat64MapStructValidate(obj *ValidatorMaxFloat64MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat64SlicePointerStructValidate(obj *ValidatorMaxFloat64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxFloat64SliceStructValidate(obj *ValidatorMaxFloat64SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt16MapPointerStructValidate(obj *ValidatorMaxInt16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt16MapStructValidate(obj *ValidatorMaxInt16MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt16SlicePointerStructValidate(obj *ValidatorMaxInt16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt16SliceStructValidate(obj *ValidatorMaxInt16SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt32MapPointerStructValidate(obj *ValidatorMaxInt32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt32MapStructValidate(obj *ValidatorMaxInt32MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt32SlicePointerStructValidate(obj *ValidatorMaxInt32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt32SliceStructValidate(obj *ValidatorMaxInt32SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt64MapPointerStructValidate(obj *ValidatorMaxInt64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt64MapStructValidate(obj *ValidatorMaxInt64MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt64SlicePointerStructValidate(obj *ValidatorMaxInt64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt64SliceStructValidate(obj *ValidatorMaxInt64SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt8MapPointerStructValidate(obj *ValidatorMaxInt8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt8MapStructValidate(obj *ValidatorMaxInt8MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt8SlicePointerStructValidate(obj *ValidatorMaxInt8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxInt8SliceStructValidate(obj *ValidatorMaxInt8SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxIntMapPointerStructValidate(obj *ValidatorMaxIntMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxIntMapStructValidate(obj *ValidatorMaxIntMapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxIntSlicePointerStructValidate(obj *ValidatorMaxIntSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxIntSliceStructValidate(obj *ValidatorMaxIntSliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxStringMapPointerStructValidate(obj *ValidatorMaxStringMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxStringMapStructValidate(obj *ValidatorMaxStringMapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxStringPointerStructValidate(obj *ValidatorMaxStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 3) { + errs = append(errs, types.NewValidationError("Field length must be <= 3")) + } + return errs +} +func ValidatorMaxStringSlicePointerStructValidate(obj *ValidatorMaxStringSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxStringSliceStructValidate(obj *ValidatorMaxStringSliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxStringStructValidate(obj *ValidatorMaxStringStruct) []error { + var errs []error + if !(len(obj.Field) <= 3) { + errs = append(errs, types.NewValidationError("Field length must be <= 3")) + } + return errs +} +func ValidatorMaxUint16MapPointerStructValidate(obj *ValidatorMaxUint16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint16MapStructValidate(obj *ValidatorMaxUint16MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint16SlicePointerStructValidate(obj *ValidatorMaxUint16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint16SliceStructValidate(obj *ValidatorMaxUint16SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint32MapPointerStructValidate(obj *ValidatorMaxUint32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint32MapStructValidate(obj *ValidatorMaxUint32MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint32SlicePointerStructValidate(obj *ValidatorMaxUint32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint32SliceStructValidate(obj *ValidatorMaxUint32SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint64MapPointerStructValidate(obj *ValidatorMaxUint64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint64MapStructValidate(obj *ValidatorMaxUint64MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint64SlicePointerStructValidate(obj *ValidatorMaxUint64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint64SliceStructValidate(obj *ValidatorMaxUint64SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint8MapPointerStructValidate(obj *ValidatorMaxUint8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint8MapStructValidate(obj *ValidatorMaxUint8MapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint8SlicePointerStructValidate(obj *ValidatorMaxUint8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUint8SliceStructValidate(obj *ValidatorMaxUint8SliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUintMapPointerStructValidate(obj *ValidatorMaxUintMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUintMapStructValidate(obj *ValidatorMaxUintMapStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUintSlicePointerStructValidate(obj *ValidatorMaxUintSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMaxUintSliceStructValidate(obj *ValidatorMaxUintSliceStruct) []error { + var errs []error + if !(len(obj.Field) <= 2) { + errs = append(errs, types.NewValidationError("Field must have at most 2 elements")) + } + return errs +} +func ValidatorMinBoolMapPointerStructValidate(obj *ValidatorMinBoolMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinBoolMapStructValidate(obj *ValidatorMinBoolMapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinBoolSlicePointerStructValidate(obj *ValidatorMinBoolSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinBoolSliceStructValidate(obj *ValidatorMinBoolSliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat32MapPointerStructValidate(obj *ValidatorMinFloat32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat32MapStructValidate(obj *ValidatorMinFloat32MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat32SlicePointerStructValidate(obj *ValidatorMinFloat32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat32SliceStructValidate(obj *ValidatorMinFloat32SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat64MapPointerStructValidate(obj *ValidatorMinFloat64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat64MapStructValidate(obj *ValidatorMinFloat64MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat64SlicePointerStructValidate(obj *ValidatorMinFloat64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinFloat64SliceStructValidate(obj *ValidatorMinFloat64SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt16MapPointerStructValidate(obj *ValidatorMinInt16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt16MapStructValidate(obj *ValidatorMinInt16MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt16SlicePointerStructValidate(obj *ValidatorMinInt16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt16SliceStructValidate(obj *ValidatorMinInt16SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt32MapPointerStructValidate(obj *ValidatorMinInt32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt32MapStructValidate(obj *ValidatorMinInt32MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt32SlicePointerStructValidate(obj *ValidatorMinInt32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt32SliceStructValidate(obj *ValidatorMinInt32SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt64MapPointerStructValidate(obj *ValidatorMinInt64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt64MapStructValidate(obj *ValidatorMinInt64MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt64SlicePointerStructValidate(obj *ValidatorMinInt64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt64SliceStructValidate(obj *ValidatorMinInt64SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt8MapPointerStructValidate(obj *ValidatorMinInt8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt8MapStructValidate(obj *ValidatorMinInt8MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt8SlicePointerStructValidate(obj *ValidatorMinInt8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinInt8SliceStructValidate(obj *ValidatorMinInt8SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinIntMapPointerStructValidate(obj *ValidatorMinIntMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinIntMapStructValidate(obj *ValidatorMinIntMapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinIntSlicePointerStructValidate(obj *ValidatorMinIntSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinIntSliceStructValidate(obj *ValidatorMinIntSliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinStringMapPointerStructValidate(obj *ValidatorMinStringMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinStringMapStructValidate(obj *ValidatorMinStringMapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinStringPointerStructValidate(obj *ValidatorMinStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 5) { + errs = append(errs, types.NewValidationError("Field length must be >= 5")) + } + return errs +} +func ValidatorMinStringSlicePointerStructValidate(obj *ValidatorMinStringSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinStringSliceStructValidate(obj *ValidatorMinStringSliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinStringStructValidate(obj *ValidatorMinStringStruct) []error { + var errs []error + if !(len(obj.Field) >= 5) { + errs = append(errs, types.NewValidationError("Field length must be >= 5")) + } + return errs +} +func ValidatorMinUint16MapPointerStructValidate(obj *ValidatorMinUint16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint16MapStructValidate(obj *ValidatorMinUint16MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint16SlicePointerStructValidate(obj *ValidatorMinUint16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint16SliceStructValidate(obj *ValidatorMinUint16SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint32MapPointerStructValidate(obj *ValidatorMinUint32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint32MapStructValidate(obj *ValidatorMinUint32MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint32SlicePointerStructValidate(obj *ValidatorMinUint32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint32SliceStructValidate(obj *ValidatorMinUint32SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint64MapPointerStructValidate(obj *ValidatorMinUint64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint64MapStructValidate(obj *ValidatorMinUint64MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint64SlicePointerStructValidate(obj *ValidatorMinUint64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint64SliceStructValidate(obj *ValidatorMinUint64SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint8MapPointerStructValidate(obj *ValidatorMinUint8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint8MapStructValidate(obj *ValidatorMinUint8MapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint8SlicePointerStructValidate(obj *ValidatorMinUint8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUint8SliceStructValidate(obj *ValidatorMinUint8SliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUintMapPointerStructValidate(obj *ValidatorMinUintMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUintMapStructValidate(obj *ValidatorMinUintMapStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUintSlicePointerStructValidate(obj *ValidatorMinUintSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorMinUintSliceStructValidate(obj *ValidatorMinUintSliceStruct) []error { + var errs []error + if !(len(obj.Field) >= 2) { + errs = append(errs, types.NewValidationError("Field must have at least 2 elements")) + } + return errs +} +func ValidatorNeqBoolPointerStructValidate(obj *ValidatorNeqBoolPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != true) { + errs = append(errs, types.NewValidationError("Field must not be equal to true")) + } + return errs +} +func ValidatorNeqBoolStructValidate(obj *ValidatorNeqBoolStruct) []error { + var errs []error + if !(obj.Field != true) { + errs = append(errs, types.NewValidationError("Field must not be equal to true")) + } + return errs +} +func ValidatorNeqFloat32PointerStructValidate(obj *ValidatorNeqFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 12.34) { + errs = append(errs, types.NewValidationError("Field must not be equal to 12.34")) + } + return errs +} +func ValidatorNeqFloat32StructValidate(obj *ValidatorNeqFloat32Struct) []error { + var errs []error + if !(obj.Field != 12.34) { + errs = append(errs, types.NewValidationError("Field must not be equal to 12.34")) + } + return errs +} +func ValidatorNeqFloat64PointerStructValidate(obj *ValidatorNeqFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 12.34) { + errs = append(errs, types.NewValidationError("Field must not be equal to 12.34")) + } + return errs +} +func ValidatorNeqFloat64StructValidate(obj *ValidatorNeqFloat64Struct) []error { + var errs []error + if !(obj.Field != 12.34) { + errs = append(errs, types.NewValidationError("Field must not be equal to 12.34")) + } + return errs +} +func ValidatorNeqInt16PointerStructValidate(obj *ValidatorNeqInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt16StructValidate(obj *ValidatorNeqInt16Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt32PointerStructValidate(obj *ValidatorNeqInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt32StructValidate(obj *ValidatorNeqInt32Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt64PointerStructValidate(obj *ValidatorNeqInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt64StructValidate(obj *ValidatorNeqInt64Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt8PointerStructValidate(obj *ValidatorNeqInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqInt8StructValidate(obj *ValidatorNeqInt8Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqIntPointerStructValidate(obj *ValidatorNeqIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqIntStructValidate(obj *ValidatorNeqIntStruct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqStringPointerStructValidate(obj *ValidatorNeqStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != "abcde") { + errs = append(errs, types.NewValidationError("Field must not be equal to 'abcde'")) + } + return errs +} +func ValidatorNeqStringStructValidate(obj *ValidatorNeqStringStruct) []error { + var errs []error + if !(obj.Field != "abcde") { + errs = append(errs, types.NewValidationError("Field must not be equal to 'abcde'")) + } + return errs +} +func ValidatorNeqUint16PointerStructValidate(obj *ValidatorNeqUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint16StructValidate(obj *ValidatorNeqUint16Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint32PointerStructValidate(obj *ValidatorNeqUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint32StructValidate(obj *ValidatorNeqUint32Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint64PointerStructValidate(obj *ValidatorNeqUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint64StructValidate(obj *ValidatorNeqUint64Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint8PointerStructValidate(obj *ValidatorNeqUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUint8StructValidate(obj *ValidatorNeqUint8Struct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUintPointerStructValidate(obj *ValidatorNeqUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeqUintStructValidate(obj *ValidatorNeqUintStruct) []error { + var errs []error + if !(obj.Field != 32) { + errs = append(errs, types.NewValidationError("Field must not be equal to 32")) + } + return errs +} +func ValidatorNeq_ignore_caseStringPointerStructValidate(obj *ValidatorNeq_ignore_caseStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && !strings.EqualFold(*obj.Field, "abcde")) { + errs = append(errs, types.NewValidationError("Field must not be equal to 'abcde'")) + } + return errs +} +func ValidatorNeq_ignore_caseStringStructValidate(obj *ValidatorNeq_ignore_caseStringStruct) []error { + var errs []error + if !(!strings.EqualFold(obj.Field, "abcde")) { + errs = append(errs, types.NewValidationError("Field must not be equal to 'abcde'")) + } + return errs +} +func ValidatorRequiredBoolArrayPointerStructValidate(obj *ValidatorRequiredBoolArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredBoolMapPointerStructValidate(obj *ValidatorRequiredBoolMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredBoolMapStructValidate(obj *ValidatorRequiredBoolMapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredBoolPointerStructValidate(obj *ValidatorRequiredBoolPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != false) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredBoolSlicePointerStructValidate(obj *ValidatorRequiredBoolSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredBoolSliceStructValidate(obj *ValidatorRequiredBoolSliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredBoolStructValidate(obj *ValidatorRequiredBoolStruct) []error { + var errs []error + if !(obj.Field != false) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredFloat32ArrayPointerStructValidate(obj *ValidatorRequiredFloat32ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat32MapPointerStructValidate(obj *ValidatorRequiredFloat32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat32MapStructValidate(obj *ValidatorRequiredFloat32MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat32PointerStructValidate(obj *ValidatorRequiredFloat32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredFloat32SlicePointerStructValidate(obj *ValidatorRequiredFloat32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat32SliceStructValidate(obj *ValidatorRequiredFloat32SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat32StructValidate(obj *ValidatorRequiredFloat32Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredFloat64ArrayPointerStructValidate(obj *ValidatorRequiredFloat64ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat64MapPointerStructValidate(obj *ValidatorRequiredFloat64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat64MapStructValidate(obj *ValidatorRequiredFloat64MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat64PointerStructValidate(obj *ValidatorRequiredFloat64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredFloat64SlicePointerStructValidate(obj *ValidatorRequiredFloat64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat64SliceStructValidate(obj *ValidatorRequiredFloat64SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredFloat64StructValidate(obj *ValidatorRequiredFloat64Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt16ArrayPointerStructValidate(obj *ValidatorRequiredInt16ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt16MapPointerStructValidate(obj *ValidatorRequiredInt16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt16MapStructValidate(obj *ValidatorRequiredInt16MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt16PointerStructValidate(obj *ValidatorRequiredInt16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt16SlicePointerStructValidate(obj *ValidatorRequiredInt16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt16SliceStructValidate(obj *ValidatorRequiredInt16SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt16StructValidate(obj *ValidatorRequiredInt16Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt32ArrayPointerStructValidate(obj *ValidatorRequiredInt32ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt32MapPointerStructValidate(obj *ValidatorRequiredInt32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt32MapStructValidate(obj *ValidatorRequiredInt32MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt32PointerStructValidate(obj *ValidatorRequiredInt32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt32SlicePointerStructValidate(obj *ValidatorRequiredInt32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt32SliceStructValidate(obj *ValidatorRequiredInt32SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt32StructValidate(obj *ValidatorRequiredInt32Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt64ArrayPointerStructValidate(obj *ValidatorRequiredInt64ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt64MapPointerStructValidate(obj *ValidatorRequiredInt64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt64MapStructValidate(obj *ValidatorRequiredInt64MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt64PointerStructValidate(obj *ValidatorRequiredInt64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt64SlicePointerStructValidate(obj *ValidatorRequiredInt64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt64SliceStructValidate(obj *ValidatorRequiredInt64SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt64StructValidate(obj *ValidatorRequiredInt64Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt8ArrayPointerStructValidate(obj *ValidatorRequiredInt8ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt8MapPointerStructValidate(obj *ValidatorRequiredInt8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt8MapStructValidate(obj *ValidatorRequiredInt8MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt8PointerStructValidate(obj *ValidatorRequiredInt8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredInt8SlicePointerStructValidate(obj *ValidatorRequiredInt8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt8SliceStructValidate(obj *ValidatorRequiredInt8SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredInt8StructValidate(obj *ValidatorRequiredInt8Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredIntArrayPointerStructValidate(obj *ValidatorRequiredIntArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredIntMapPointerStructValidate(obj *ValidatorRequiredIntMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredIntMapStructValidate(obj *ValidatorRequiredIntMapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredIntPointerStructValidate(obj *ValidatorRequiredIntPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredIntSlicePointerStructValidate(obj *ValidatorRequiredIntSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredIntSliceStructValidate(obj *ValidatorRequiredIntSliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredIntStructValidate(obj *ValidatorRequiredIntStruct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredStringArrayPointerStructValidate(obj *ValidatorRequiredStringArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredStringMapPointerStructValidate(obj *ValidatorRequiredStringMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredStringMapStructValidate(obj *ValidatorRequiredStringMapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredStringPointerStructValidate(obj *ValidatorRequiredStringPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != "") { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredStringSlicePointerStructValidate(obj *ValidatorRequiredStringSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredStringSliceStructValidate(obj *ValidatorRequiredStringSliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredStringStructValidate(obj *ValidatorRequiredStringStruct) []error { + var errs []error + if !(obj.Field != "") { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint16ArrayPointerStructValidate(obj *ValidatorRequiredUint16ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint16MapPointerStructValidate(obj *ValidatorRequiredUint16MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint16MapStructValidate(obj *ValidatorRequiredUint16MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint16PointerStructValidate(obj *ValidatorRequiredUint16PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint16SlicePointerStructValidate(obj *ValidatorRequiredUint16SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint16SliceStructValidate(obj *ValidatorRequiredUint16SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint16StructValidate(obj *ValidatorRequiredUint16Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint32ArrayPointerStructValidate(obj *ValidatorRequiredUint32ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint32MapPointerStructValidate(obj *ValidatorRequiredUint32MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint32MapStructValidate(obj *ValidatorRequiredUint32MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint32PointerStructValidate(obj *ValidatorRequiredUint32PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint32SlicePointerStructValidate(obj *ValidatorRequiredUint32SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint32SliceStructValidate(obj *ValidatorRequiredUint32SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint32StructValidate(obj *ValidatorRequiredUint32Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint64ArrayPointerStructValidate(obj *ValidatorRequiredUint64ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint64MapPointerStructValidate(obj *ValidatorRequiredUint64MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint64MapStructValidate(obj *ValidatorRequiredUint64MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint64PointerStructValidate(obj *ValidatorRequiredUint64PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint64SlicePointerStructValidate(obj *ValidatorRequiredUint64SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint64SliceStructValidate(obj *ValidatorRequiredUint64SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint64StructValidate(obj *ValidatorRequiredUint64Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint8ArrayPointerStructValidate(obj *ValidatorRequiredUint8ArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint8MapPointerStructValidate(obj *ValidatorRequiredUint8MapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint8MapStructValidate(obj *ValidatorRequiredUint8MapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint8PointerStructValidate(obj *ValidatorRequiredUint8PointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUint8SlicePointerStructValidate(obj *ValidatorRequiredUint8SlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint8SliceStructValidate(obj *ValidatorRequiredUint8SliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUint8StructValidate(obj *ValidatorRequiredUint8Struct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUintArrayPointerStructValidate(obj *ValidatorRequiredUintArrayPointerStruct) []error { + var errs []error + if !(obj.Field != nil) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUintMapPointerStructValidate(obj *ValidatorRequiredUintMapPointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUintMapStructValidate(obj *ValidatorRequiredUintMapStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUintPointerStructValidate(obj *ValidatorRequiredUintPointerStruct) []error { + var errs []error + if !(obj.Field != nil && *obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} +func ValidatorRequiredUintSlicePointerStructValidate(obj *ValidatorRequiredUintSlicePointerStruct) []error { + var errs []error + if !(obj.Field != nil && len(*obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUintSliceStructValidate(obj *ValidatorRequiredUintSliceStruct) []error { + var errs []error + if !(len(obj.Field) != 0) { + errs = append(errs, types.NewValidationError("Field must not be empty")) + } + return errs +} +func ValidatorRequiredUintStructValidate(obj *ValidatorRequiredUintStruct) []error { + var errs []error + if !(obj.Field != 0) { + errs = append(errs, types.NewValidationError("Field is required")) + } + return errs +} From 71bcc2681eccdb11b80be43b4c0935776d963776 Mon Sep 17 00:00:00 2001 From: Leo Cavalcante Date: Tue, 29 Sep 2026 19:08:14 -0300 Subject: [PATCH 3/3] Ignore a blank validation tag instead of panicking. An empty valid or validate value, or a blank piece between commas, is not a rule. --- docs/internals.md | 6 +++--- internal/analyzer/analyzer.go | 12 +++++++++++- internal/analyzer/common_example_test.go | 10 ++++++++++ internal/analyzer/parser_validation.go | 2 +- internal/analyzer/parser_validation_test.go | 5 +++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/internals.md b/docs/internals.md index 77f2069..b2e2716 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -72,11 +72,11 @@ Slices, arrays, maps, and pointers keep a marker on that name, such as `[]` ### Tag parsing -`analyzeFieldValidations` copies each `parser.Struct` into an `analyzer.Struct`. A field counts as validated when its struct tag has a `valid` key, or a `validate` key if `valid` is absent. The analyzer sets `HasValidTag` if any field matches. It splits that key's value on commas. `reflect.StructTag` reads the key, so `json:"email" validate:"required,email"` is accepted. +`analyzeFieldValidations` copies each `parser.Struct` into an `analyzer.Struct`. A field counts as validated when its struct tag has a `valid` key, or a `validate` key if `valid` is absent. The analyzer sets `HasValidTag` if any field matches. It splits that key's value on commas and drops blank pieces, including a blank value such as `validate:""`. `reflect.StructTag` reads the key, so `json:"email" validate:"required,email"` is accepted. -`ParserValidation` splits one validation on `=`. More than two pieces is an error. The operation's `CountValues` selects the shape. +`ParserValidation` splits one validation on `=`. More than two pieces, or none, is an error. The operation's `CountValues` selects the shape. -`ZeroValue` operations `required`, `email`, `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` reject a target. `OneValue` operations require one target. `ManyValues` operations `in`, `nin`, and `oneof` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. `iscolor` is the alias for `hexcolor|rgb|rgba|hsl|hsla` and calls `types.IsColor`. `ne` and `ne_ignore_case` are read as `neq` and `neq_ignore_case`. +`ZeroValue` operations `required`, `email`, `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, `iscolor`, `dive`, `keys`, and `endkeys` reject a target. `OneValue` operations require one target. `ManyValues` operations `in`, `nin`, and `oneof` require a target list. Spaces and commas separate tokens. A single-quoted token keeps its interior, including spaces, and quoted tokens can be mixed with bare tokens, as in `oneof=red 'light blue'`. `iscolor` is the alias for `hexcolor|rgb|rgba|hsl|hsla` and calls `types.IsColor`. `ne` and `ne_ignore_case` are read as `neq` and `neq_ignore_case`. The result is an `analyzer.Validation` with `Operation`, `ExpectedValues`, and `Values`. diff --git a/internal/analyzer/analyzer.go b/internal/analyzer/analyzer.go index cfdafd3..cb97847 100644 --- a/internal/analyzer/analyzer.go +++ b/internal/analyzer/analyzer.go @@ -74,7 +74,17 @@ func parseFieldValidations(fieldTag string) ([]string, bool) { return nil, false } - return strings.Split(value, ","), true + parts := strings.Split(value, ",") + fieldValidations := make([]string, 0, len(parts)) + for _, part := range parts { + part = strings.TrimSpace(part) + if part == "" { + continue + } + fieldValidations = append(fieldValidations, part) + } + + return fieldValidations, true } func checkForInvalidOperations(structs []*Struct) error { diff --git a/internal/analyzer/common_example_test.go b/internal/analyzer/common_example_test.go index 4a2bb2c..cafcf7b 100644 --- a/internal/analyzer/common_example_test.go +++ b/internal/analyzer/common_example_test.go @@ -78,6 +78,16 @@ func TestValidationTagKey(t *testing.T) { tag: `json:"email"`, want: nil, }, + { + name: "empty validate value", + tag: `validate:""`, + want: nil, + }, + { + name: "blank piece between commas", + tag: `valid:"required, ,email"`, + want: []string{"required", "email"}, + }, } for _, tt := range tests { diff --git a/internal/analyzer/parser_validation.go b/internal/analyzer/parser_validation.go index f87c069..0a72e7f 100644 --- a/internal/analyzer/parser_validation.go +++ b/internal/analyzer/parser_validation.go @@ -41,7 +41,7 @@ func ParserValidation(fieldValidation string) (*Validation, error) { func parserValidationString(tag string) (string, string, error) { tokens := removeEmptyValues(strings.Split(tag, "=")) - if len(tokens) > 2 { + if len(tokens) == 0 || len(tokens) > 2 { return "", "", types.NewValidationError("malformed validation %s", tag) } diff --git a/internal/analyzer/parser_validation_test.go b/internal/analyzer/parser_validation_test.go index 3d4b1b1..9b13c76 100644 --- a/internal/analyzer/parser_validation_test.go +++ b/internal/analyzer/parser_validation_test.go @@ -251,6 +251,11 @@ func TestParserInvalidValidation(t *testing.T) { validation: "eq=aaa=bbb", expectedErr: types.NewValidationError("malformed validation eq=aaa=bbb"), }, + { + name: "empty validation", + validation: "", + expectedErr: types.NewValidationError("malformed validation "), + }, { name: "undefined validation", validation: "xpto=a",