-
Notifications
You must be signed in to change notification settings - Fork 2
deal with slices of strings (#46) #49
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 support for slice validation in ValidGen's code generator, specifically for []string fields. The implementation ensures that validations like required, min, max, len, in, and nin work correctly for slice fields.
Key changes include:
- Implementation of slice validation logic with new test elements for
[]stringfields - Refactoring of struct parsing to use helper functions for better maintainability
- Addition of
SlicesContainsutility function for slice element validation
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| types/string_utils.go | Adds SlicesContains generic function for slice validation |
| tests/endtoend/slicestring_validator.go | Generated validator code for slice string validation tests |
| tests/endtoend/slice_string.go | Test struct and validation scenarios for slice string fields |
| tests/endtoend/main.go | Integrates slice string tests into end-to-end test suite |
| internal/parser/parser_test.go | Comprehensive unit tests for struct parsing including slice fields |
| internal/parser/parser.go | Refactored parser with helper functions for better maintainability |
| internal/common/utils.go | Updated IsGoType to handle slice types by stripping [] prefix |
| internal/codegenerator/test_elements.go | Added validation rules for []string fields |
| internal/codegenerator/integration_tests_test.go | Simplified test error handling |
| internal/codegenerator/get_test_elements_slice_test.go | Unit tests for slice validation test elements |
| internal/codegenerator/build_validator_test.go | Extended tests for slice validation code generation |
| internal/codegenerator/build_validator.go | Fixed string formatting for boolean conditions |
| README.md | Updated documentation to reflect slice string support |
Closes #46
This PR adds comprehensive support for slice (
[]string) field validations in the code generator, ensuring that validations likerequired,min,max,len,in, andninwork correctly for slice fields. It also refactors the struct parsing logic for better clarity and maintainability, and adds extensive new tests for slice validation scenarios.Slice Validation Support:
required,min,max,len,in, andninvalidations on[]stringfields in the code generator logic and templates (internal/codegenerator/test_elements.go,README.md). [1] [2]TestElementslogic for slice fields, covering all supported validations (internal/codegenerator/get_test_elements_slice_test.go).internal/codegenerator/build_validator_test.go,internal/codegenerator/integration_tests_test.go). [1] [2] [3] [4] [5] [6]Struct Parsing Refactor:
internal/parser/parser.go). [1] [2]Utility Improvements:
IsGoTypeutility to correctly handle slice types by stripping the[]prefix (internal/common/utils.go).Minor Improvements:
These changes collectively improve the generator's ability to handle more complex struct field types and validations, with robust test coverage to ensure correctness.