-
Notifications
You must be signed in to change notification settings - Fork 2
Refact to support nested structs #37
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 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
validgenpackage into three specialized internal packages with clear responsibilities - Introduces a processing pipeline where
parserextracts structs,analyzerprocesses validation tags, andcodegeneratorcreates 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) { |
Copilot
AI
Jul 27, 2025
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.
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.
| fieldName string | ||
| fieldValidation string | ||
| fieldType string | ||
| fieldValidation string |
Copilot
AI
Jul 27, 2025
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.
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.
This PR refactors and enhances the
validgencodebase 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:
validgenpackage has been split into three new internal packages:parser,analyzer, andcodegenerator, 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:
parsermodule to extract and parse Go structs from.gofiles, 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))analyzermodule 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))codegeneratormodule 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:
GetTestElementstoDefineTestElements). ([[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))parser.Structand 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:
main.goto 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))