Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

This PR refactors and enhances the validgen codebase by introducing modular components for parsing, analyzing, and generating validation code for Go structs. Basically now we have a pipeline composed of the parser, the analyzer and the code generator. It includes significant restructuring, new functionality for validation code generation, and updates to tests and integration logic.

Refactoring and Modularization:

  • The validgen package has been split into three new internal packages: parser, analyzer, and codegenerator, each handling a distinct aspect of the validation process. Files and functions have been renamed and moved accordingly. ([[1]](https://github.com/opencodeco/validgen/pull/37/files#diff-2e516d6180c079f7445cc566a07cb613237db1dcae80a15f9427e31b106f11feL1-R1), [[2]](https://github.com/opencodeco/validgen/pull/37/files#diff-4a2689cbce28727a3ba2f050fcd06330829b7631d36bfb5d0bb3f2e28d359189L1-R1), [[3]](https://github.com/opencodeco/validgen/pull/37/files#diff-a805abe62add9666cbcd835268eed6be4343bcd6647ec608325825137aadc6a6L1-R7), [[4]](https://github.com/opencodeco/validgen/pull/37/files#diff-739ba07c8d00c05d17bdfe8fddf15e12650806d3112ed68324de3986678a171fL1-R13))

New Features:

  • Added a parser module to extract and parse Go structs from .go files, including their tags and fields. ([[1]](https://github.com/opencodeco/validgen/pull/37/files#diff-d1655fd776ca5fcf2821d7a478d18e80e68fc75d43a8aabeb5fbb07197c4f3ccR1-R134), [[2]](https://github.com/opencodeco/validgen/pull/37/files#diff-dc19824db1734891e5fdc65f58908f0620c7611b24053fd1dd9c8cac69657d07R1-R43))
  • Introduced an analyzer module to process struct tags and extract validation rules into a structured format. ([internal/analyzer/analyzer.goR1-R40](https://github.com/opencodeco/validgen/pull/37/files#diff-b126d19c61b7249f14710696139d71e966aa643a9a363ad19e639e14cef6e41eR1-R40))
  • Implemented a codegenerator module to generate validation code based on analyzed structs, including template-based code generation and file writing. ([[1]](https://github.com/opencodeco/validgen/pull/37/files#diff-9728e9b6a97707c0f2346e4c5fd741bd13be944daf36d331344a0acfdb646ab1R1-R100), [[2]](https://github.com/opencodeco/validgen/pull/37/files#diff-afd35748b7d2538c0a5a6052ba12a9319c2aaeda0328e95e131e45527daf61e1R1-R17))

Test Updates:

  • Updated tests to align with the new modular structure and renamed functions (e.g., GetTestElements to DefineTestElements). ([[1]](https://github.com/opencodeco/validgen/pull/37/files#diff-8d32a9c408197046acde77ba1dfab1521cc0bc32365f0f98fa4c956dbadd3d39L1-R7), [[2]](https://github.com/opencodeco/validgen/pull/37/files#diff-2f2c97ac3d4ef9c052822c7c74f806c5bc7bebc6bbedb5fb5a299e890776a429L1-R1), [[3]](https://github.com/opencodeco/validgen/pull/37/files#diff-945128e013ade394999700244bb16023d6b90522a9b0bed73777242359fe6f31L1-R8), [[4]](https://github.com/opencodeco/validgen/pull/37/files#diff-40d01e1f757c04a3361c930f71762f16d1b092922b5482247e38deb024938d57L1-R8))
  • Updated integration tests to use the new parser.Struct and validate the generated code. ([[1]](https://github.com/opencodeco/validgen/pull/37/files#diff-739ba07c8d00c05d17bdfe8fddf15e12650806d3112ed68324de3986678a171fL23-R50), [[2]](https://github.com/opencodeco/validgen/pull/37/files#diff-739ba07c8d00c05d17bdfe8fddf15e12650806d3112ed68324de3986678a171fL70-R96))

Main Application Changes:

  • Refactored main.go to use the new modular structure, integrating parsing, analyzing, and code generation steps. Improved error handling and clarified command-line arguments. ([main.goL7-R33](https://github.com/opencodeco/validgen/pull/37/files#diff-2873f79a86c0d8b3335cd7731b0ecf7dd4301eb19a82ef7a1cba7589b5252261L7-R33))

@alexgarzao alexgarzao requested a review from Copilot July 27, 2025 18:35
@alexgarzao alexgarzao self-assigned this Jul 27, 2025

This comment was marked as outdated.

@alexgarzao alexgarzao marked this pull request as draft July 27, 2025 18:36
@alexgarzao alexgarzao requested a review from Copilot July 27, 2025 22:34

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot July 27, 2025 22:39

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot July 27, 2025 22:49
@alexgarzao alexgarzao marked this pull request as ready for review July 27, 2025 22:49

This comment was marked as outdated.

@alexgarzao alexgarzao requested a review from Copilot July 27, 2025 22:56
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 refactors the validgen codebase to support nested structs by introducing a modular architecture with three distinct internal packages: parser, analyzer, and codegenerator. The refactoring enhances code maintainability and separates concerns in the validation code generation pipeline.

  • Splits the original monolithic validgen package into three specialized internal packages with clear responsibilities
  • Introduces a processing pipeline where parser extracts structs, analyzer processes validation tags, and codegenerator creates validation code
  • Updates the main application to use the new modular architecture with improved error handling

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
main.go Refactored to use new modular pipeline with separate parsing, analysis, and code generation steps
validgen/*.go Removed original monolithic files (struct.go, if_code.go, find_files.go, code_generator.go)
internal/parser/*.go New parser module for extracting Go structs and fields from source files
internal/analyzer/*.go New analyzer module for processing validation tags and creating structured validation rules
internal/codegenerator/*.go New code generator module for creating validation functions with template-based generation

}

func GetTestElements(fieldName, fieldValidation, fieldType string) (TestElements, error) {
func DefineTestElements(fieldName, fieldType, fieldValidation string) (TestElements, error) {
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function parameter order has changed from the original GetTestElements(fieldName, fieldValidation, fieldType) to DefineTestElements(fieldName, fieldType, fieldValidation). This inconsistency in parameter ordering could cause confusion and maintainability issues. Consider maintaining consistent parameter ordering across the codebase.

Copilot generated this review using guidance from repository custom instructions.
fieldName string
fieldValidation string
fieldType string
fieldValidation string
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test struct field order has been changed to match the new function signature, but this creates inconsistency with string tests where the original order is maintained. For better maintainability, all test files should use consistent field ordering.

Copilot generated this review using guidance from repository custom instructions.
@alexgarzao alexgarzao merged commit 70f5856 into main Jul 28, 2025
1 check passed
@alexgarzao alexgarzao deleted the refact-to-support-nested-structs branch July 28, 2025 22:25
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.

3 participants