Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

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

  • Expanded the set of valid types for many validation operations (such as 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]
  • Updated the IsValidByType function to correctly handle pointer types by stripping the pointer modifier and allowing the required operation on all pointer types.

Error Reporting and Messaging

  • Improved error messages for invalid operations by including the normalized field type (e.g., invalid string(<STRING>) type), providing more context for debugging. [1] [2] [3]

Testing Enhancements

  • Significantly expanded the TestOperationsIsValidByType test 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]
  • Added a comprehensive new test, 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

  • Updated the Makefile to run unit tests only for the internal and types directories, and improved the end-to-end test generation step to handle more general file patterns. [1] [2]

Code Quality

  • Minor refactoring, such as importing strings for 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.

@alexgarzao alexgarzao self-assigned this Oct 22, 2025
@alexgarzao alexgarzao requested a review from Copilot October 22, 2025 00:21
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 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 IsValidEmail function
  • 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

@alexgarzao alexgarzao requested a review from Copilot October 22, 2025 00:31
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

Copilot reviewed 33 out of 35 changed files in this pull request and generated 5 comments.

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? 😁

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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!

@alexgarzao alexgarzao requested a review from Copilot October 22, 2025 17:50
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

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

@alexgarzao alexgarzao requested a review from Copilot October 22, 2025 17:58
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

Copilot reviewed 33 out of 35 changed files in this pull request and generated no new comments.

@alexgarzao alexgarzao merged commit 4ca1796 into main Oct 22, 2025
4 checks passed
@alexgarzao alexgarzao deleted the 54-pointer-support branch October 22, 2025 18:00
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.

Implement support for pointers

4 participants