Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
eaa2abf
feat: type struct to deal with complex types (array, slice)
alexgarzao Sep 27, 2025
c80a584
chore: use FieldType instead of string
alexgarzao Sep 27, 2025
0d9b9b9
refact: IsGoType is a FieldType method now
alexgarzao Sep 27, 2025
97671da
chore: register a possible refactor
alexgarzao Sep 28, 2025
dc85a43
chore: removes unused tests
alexgarzao Sep 29, 2025
1b54cad
chore: forgot to update docs and tests related to bool type
alexgarzao Sep 29, 2025
7ee2bd2
Merge branch 'main' into 59-support-all-numeric-types
alexgarzao Oct 1, 2025
9eddafb
chore: use the correct template engine (text)
alexgarzao Oct 1, 2025
36acdd0
tests: generator to check for all integer types
alexgarzao Oct 1, 2025
c90d351
feat: normalize the specific type to a class (int, float, string, bool)
alexgarzao Oct 1, 2025
c0a76e6
feat: normalize the specific type to a class (int, float, string, bool)
alexgarzao Oct 1, 2025
dd1fd7b
tests: run generator to check for all integer types
alexgarzao Oct 1, 2025
8ba7c7b
feat: parser list of integers
alexgarzao Oct 1, 2025
7d013de
feat: deal with generic type in the analyzer
alexgarzao Oct 1, 2025
64343e5
feat: deal with generic int types during code generation
alexgarzao Oct 1, 2025
e6b991a
doc: update readme with new validations
alexgarzao Oct 1, 2025
630af30
fix: avoid panic with invalid parameter
alexgarzao Oct 2, 2025
1878544
fix: only known types can use validations
alexgarzao Oct 2, 2025
be64ec8
feat: new operations related to slice and array with integers
alexgarzao Oct 2, 2025
00fe1f8
test: helper funcs to support tests with normalized tests
alexgarzao Oct 2, 2025
cda5ad1
test: parser are correct with slice and arrays of string and int
alexgarzao Oct 2, 2025
9d906a4
feat: new array and slices operations with string and integers
alexgarzao Oct 2, 2025
9182a1a
chore: remove useless func
alexgarzao Oct 2, 2025
11aefcd
refact: move test to helper file
alexgarzao Oct 2, 2025
873b63f
refact: helper prefix in func related to tests
alexgarzao Oct 3, 2025
0d71163
chore: remove all about partial float support
alexgarzao Oct 3, 2025
42a86c3
feat: missed []int operations
alexgarzao Oct 3, 2025
489c591
chore: remove useless TODO
alexgarzao Oct 3, 2025
63a711d
FIX: avoid normalized types with an invalid go type
alexgarzao Oct 3, 2025
7cfd625
chore: generated numeric tests more idiomatic
alexgarzao Oct 3, 2025
d3b9919
tests: invalid array type, invalid array size, invalid type
alexgarzao Oct 3, 2025
612ded6
fix: avoid log fatal
alexgarzao Oct 3, 2025
76f36f5
refact: avoid duplication in helpers func
alexgarzao Oct 3, 2025
6d66ed8
chore: change from strings.Title to cases.Title
alexgarzao Oct 3, 2025
30b1c3f
fix: format %s with struct
alexgarzao Oct 3, 2025
ebd8052
Merge branch 'main' into 59-support-integer-types
alexgarzao Oct 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ build: clean
endtoendtests: build
@echo "Running endtoend tests"
find tests/endtoend/ -name 'validator__.go' -exec rm \{} \;
cd tests/endtoend/generate_tests/; rm -f numeric.go; go run generate_numeric_tests_main.go; mv numeric.go ..
$(VALIDGEN_BIN) tests/endtoend
cd tests/endtoend; go run .

Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,32 @@ The following table shows the validations and possible types, where:

- "I" means "Implemented"
- "W" means "Will be implemented"
- "P" means "Partially implemented"
- "-" means "Will not be implemented"

| Validation/Type | String | Numeric types (uint8 only) | Boolean | Slice | Array | Map | Time | Duration |
| - | - | - | - | - | - | - | - | - |
| eq | I | W | I | - | - | - | W | W |
| eq_ignore_case | I | - | - | - | - | - | - | - |
| gt | - | W | - | - | - | - | W | W |
| gte | - | I | - | - | - | - | W | W |
| lt | - | W | - | - | - | - | W | W |
| lte | - | I | - | - | - | - | W | W |
| neq | I | W | I | - | - | - | W | W |
| neq_ignore_case | I | - | - | - | - | - | - | - |
| len | I | - | - | I | - | W | - | - |
| max | I | - | - | I | - | W | W | W |
| min | I | - | - | I | - | W | W | W |
| in | I | W | - | I | I | W | - | W |
| nin | I | W | - | I | I | W | - | W |
| required | I | W | - | I | - | W | W | W |
| email | I | - | - | - | - | - | - | - |
| eqfield | I | I | I | - | - | - | W | W |
| neqfield | I | I | I | - | - | - | W | W |
| gtefield | - | I | - | - | - | - | W | W |
| gtfield | - | I | - | - | - | - | W | W |
| ltefield | - | I | - | - | - | - | W | W |
| ltfield | - | I | - | - | - | - | W | W |
| Validation/Type | String | Numeric types (integers) | Boolean | Slice | Array | Map | Time | Duration |
| - | - | - | - | - | - | - | - | - |
| eq | I | I | I | - | - | - | W | W |
| eq_ignore_case | I | - | - | - | - | - | - | - |
| gt | - | I | - | - | - | - | W | W |
| gte | - | I | - | - | - | - | W | W |
| lt | - | I | - | - | - | - | W | W |
| lte | - | I | - | - | - | - | W | W |
| neq | I | I | I | - | - | - | W | W |
| neq_ignore_case | I | - | - | - | - | - | - | - |
| len | I | - | - | I | - | W | - | - |
| max | I | - | - | I | - | W | W | W |
| min | I | - | - | I | - | W | W | W |
| in | I | I | - | I | I | W | - | W |
| nin | I | I | - | I | I | W | - | W |
| required | I | I | - | I | - | W | W | W |
| email | I | - | - | - | - | - | - | - |
| eqfield | I | P | I | - | - | - | W | W |
| neqfield | I | P | I | - | - | - | W | W |
| gtefield | - | P | - | - | - | - | W | W |
| gtfield | - | P | - | - | - | - | W | W |
| ltefield | - | P | - | - | - | - | W | W |
| ltfield | - | P | - | - | - | - | W | W |

## Steps to run the unit tests

Expand Down
20 changes: 18 additions & 2 deletions internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func parseFieldValidations(fieldTag string) ([]string, bool) {

func checkForInvalidOperations(structs []*Struct) error {

structsWithValidation := map[string]bool{}

for _, st := range structs {
structsWithValidation[common.KeyPath(st.PackageName, st.StructName)] = true
}

for _, st := range structs {
for i, fd := range st.Fields {
for _, val := range st.FieldsValidations[i].Validations {
Expand All @@ -87,9 +93,19 @@ func checkForInvalidOperations(structs []*Struct) error {
return types.NewValidationError("unsupported operation %s", op)
}

// Check if is a valid operation for this type.
// If is a custom struct, check if it has validations.
fdType := fd.Type
if fdType.IsGoType() && !operations[op].ValidTypes[fdType.ToString()] {
if structsWithValidation[fdType.BaseType] {
continue
}

// If has a validation, must be for a go type.
if !fdType.IsGoType() {
return types.NewValidationError("unsupported operation %s with unknown go type %s", op, fdType.BaseType)
}

// Check if is a valid operation for this type.
if !operations[op].ValidTypes[fdType.ToNormalizedString()] {
return types.NewValidationError("operation %s: invalid %s type", op, fdType.BaseType)
}
}
Expand Down
30 changes: 30 additions & 0 deletions internal/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,61 @@ func TestAnalyzeStructsWithValidInnerFieldOperations(t *testing.T) {
fType: "uint8",
op: "eqfield",
},
{
name: "valid eqfield between int",
fType: "int",
op: "eqfield",
},
{
name: "valid neqfield between uint8",
fType: "uint8",
op: "neqfield",
},
{
name: "valid neqfield between int",
fType: "int",
op: "neqfield",
},
{
name: "valid gtefield between uint8",
fType: "uint8",
op: "gtefield",
},
{
name: "valid gtefield between int",
fType: "int",
op: "gtefield",
},
{
name: "valid gtfield between uint8",
fType: "uint8",
op: "gtfield",
},
{
name: "valid gtfield between int",
fType: "int",
op: "gtfield",
},
{
name: "valid ltefield between uint8",
fType: "uint8",
op: "ltefield",
},
{
name: "valid ltefield between int",
fType: "int",
op: "ltefield",
},
{
name: "valid ltfield between uint8",
fType: "uint8",
op: "ltfield",
},
{
name: "valid ltfield between int",
fType: "int",
op: "ltfield",
},
}

for _, tt := range tests {
Expand Down
Loading