Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

Closes #46

This PR adds comprehensive support for slice ([]string) field validations in the code generator, ensuring that validations like required, min, max, len, in, and nin work 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:

  • Added handling for required, min, max, len, in, and nin validations on []string fields in the code generator logic and templates (internal/codegenerator/test_elements.go, README.md). [1] [2]
  • Introduced a new test suite to verify TestElements logic for slice fields, covering all supported validations (internal/codegenerator/get_test_elements_slice_test.go).
  • Expanded unit and integration tests to cover slice validation code generation and error messaging for both flat and nested struct scenarios (internal/codegenerator/build_validator_test.go, internal/codegenerator/integration_tests_test.go). [1] [2] [3] [4] [5] [6]

Struct Parsing Refactor:

  • Refactored struct parsing in the parser to use helper functions for extracting package/imports, struct definitions, and field information, improving readability and maintainability. This includes robust handling for slice and nested struct fields (internal/parser/parser.go). [1] [2]

Utility Improvements:

  • Updated IsGoType utility to correctly handle slice types by stripping the [] prefix (internal/common/utils.go).

Minor Improvements:

  • Minor cleanup in test assertions and error handling across unit and integration tests for consistency. [1] [2] [3] [4] [5]

These changes collectively improve the generator's ability to handle more complex struct field types and validations, with robust test coverage to ensure correctness.

@alexgarzao alexgarzao self-assigned this Aug 8, 2025
Copy link
Contributor

Copilot AI left a 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 []string fields
  • Refactoring of struct parsing to use helper functions for better maintainability
  • Addition of SlicesContains utility 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

@alexgarzao alexgarzao merged commit 982ae13 into main Aug 8, 2025
1 check passed
@alexgarzao alexgarzao deleted the 46-deal-with-slices branch August 8, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deal with slice of string

4 participants