-
Notifications
You must be signed in to change notification settings - Fork 2
Implement pointer support #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive pointer type support to the validation generator, enabling validation of pointer fields including basic types, slices, arrays, and maps. The implementation extends the existing validation logic to handle nil checks and dereferences appropriately for pointer types, while also expanding test coverage and refactoring the email validation behavior.
Key Changes:
- Added pointer type support across all validation operations (required, eq, min, max, in, etc.)
- Enhanced type parsing to recognize and process pointer syntax (
*T) - Removed empty string validation from
IsValidEmailfunction - Expanded test coverage with generated test files for pointer and non-pointer types
- Refactored test generation infrastructure
Reviewed Changes
Copilot reviewed 33 out of 35 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/parser/parser.go | Refactored field extraction to recursively handle pointer types via new extractCompleteType function |
| internal/common/helpers.go | Updated normalized type helpers to support pointer prefixes |
| internal/common/field_type.go | Added pointer type handling in ToType(), ToNormalizedString(), and new ToStringName() method |
| internal/codegenerator/condition_table.go | Extended validation conditions for all pointer type variants with nil checks |
| types/string_utils.go | Removed empty string handling from IsValidEmail |
| tests/endtoend/generate_tests/*.go | Added comprehensive test generation for pointer and non-pointer types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 33 out of 35 changed files in this pull request and generated 5 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pq esse arquivo tem dois __ no final do nome? 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
É para ser uma forma de facilmente identificar o que foi gerado pelo projeto e, se necessário, apagar.
Por exemplo, com proto/grpc, como todo o código gerado vai para uma pasta específica, no "clean" do meu makefile eu removo a pasta toda.
Mas no validgen, como fazer isso se temos um arquivo gerado por pasta? Este o motivo do nome estranho rsrs. Tentar ser o mais estranho possível para possibilitar a remoção com, por exemplo, um "find . -exec rm -f validator__.go". Se fosse só "validator.go" poderia ter este arquivo no projeto ou ser apagado por engano.
Mas, como sempre, aceito sugestões :-D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu estou terminando alguns ajustes sugeridos pelo copilot, e na sequência irei mergear. Mas qualquer ideia, responde que eu vejo e ajusto posteriormente.
Valeu pelos feedbacks e revisões!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 33 out of 35 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
tests/endtoend/generate_tests/generate_usecase_tests.go:1
- This commented-out code should be removed as it serves no purpose in the final implementation.
package main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 33 out of 35 changed files in this pull request and generated no new comments.
Closes #54
This PR extends and improves validation logic in several areas, with a focus on supporting pointer types, enhancing operation/type compatibility, and expanding test coverage. The most important changes are grouped below:
Validation Logic and Type Support
required,min,max,len,in,nin) to include<BOOL>, pointer types (e.g.,*<STRING>,*[]<INT>), and map/array pointer types, making validations more flexible and comprehensive. [1] [2] [3] [4]IsValidByTypefunction to correctly handle pointer types by stripping the pointer modifier and allowing therequiredoperation on all pointer types.Error Reporting and Messaging
invalid string(<STRING>) type), providing more context for debugging. [1] [2] [3]Testing Enhancements
TestOperationsIsValidByTypetest to cover all supported types, including pointers, arrays, and maps, for every operation. The test now iterates over multiple field types per operation for thorough coverage. [1] [2]TestBuildValidationCodeWithPointerTypes, to verify that validation code is generated correctly for pointer types, including pointers to basic types, slices, arrays, and maps.Build and Test Infrastructure
Makefileto run unit tests only for theinternalandtypesdirectories, and improved the end-to-end test generation step to handle more general file patterns. [1] [2]Code Quality
stringsfor pointer handling and cleaning up test code structure. [1] [2]These changes collectively make the validation system more robust, especially regarding pointer types and type compatibility, and ensure that the codebase is thoroughly tested for these scenarios.