-
Notifications
You must be signed in to change notification settings - Fork 2
40 one validator file per package #52
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 implements a significant architectural refactor that consolidates validator generation from per-struct files to per-package files. The refactor introduces cleaner separation of concerns by separating code generation logic from file writing operations and groups all validator functions for structs within the same package into a single validator__.go file.
Key changes include:
- Introduction of a new
pkgwriterpackage to handle file writing operations separately from code generation - Consolidation of validator functions into package-level files named
validator__.goinstead of individual{struct}_validator.gofiles - Updated data structures to group structs by package for consolidated file generation
Reviewed Changes
Copilot reviewed 30 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
main.go |
Updated to use new two-step process: code generation followed by file writing |
internal/codegenerator/codegen.go |
Refactored to return package map instead of writing files directly |
internal/codegenerator/build_validator.go |
Separated function code generation from file operations |
internal/codegenerator/types.go |
Added new data structures for package-level organization |
internal/pkgwriter/file_validator.go |
New package handling consolidated validator file generation |
internal/pkgwriter/file_validator_test.go |
Tests for the new file writer functionality |
tests/endtoend/validator__.go |
New consolidated validator file replacing individual struct files |
Multiple *_validator.go files |
Removed individual struct validator files |
Makefile |
Updated cleanup pattern to match new file naming convention |
Closes #40.
This PR introduces a significant refactor to the code generation and validator writing process. The core logic for generating validator functions is now separated from the logic for writing validator files, resulting in a cleaner architecture and improved testability. Validator functions are generated per struct and then assembled into a single file per package. Additionally, tests and Makefile logic have been updated to reflect these changes.
Key changes include:
Refactor and Separation of Concerns:
BuildFuncValidatorCode) is now separated from file writing, which is handled by a newpkgwriterpackage. (internal/codegenerator/build_validator.go[1]internal/pkgwriter/file_validator.go[2]Pkg) is introduced to group structs and their generated validator code by package. (internal/codegenerator/types.gointernal/codegenerator/types.goR1-R18)Validator File Generation and Test Updates:
internal/pkgwriter/file_validator.go[1]main.go[2]internal/pkgwriter/file_validator_test.go[1]internal/codegenerator/build_func_validator_test.go[2]Project Structure and Clean-up:
validator__.goand Makefile/test logic is updated accordingly. (MakefileMakefileL28-R28)tests/cmpbenchtests/generated_tests/validator__.go[1]tests/cmpbenchtests/generated_tests/validgenstringemailstruct_validator.go[2]tests/cmpbenchtests/generated_tests/validgenstringeqicstruct_validator.go[3]API and Function Signature Changes:
GenerateCodefunction now returns a map of packages to be written, rather than writing files directly. (internal/codegenerator/codegen.gointernal/codegenerator/codegen.goL3-R22)internal/codegenerator/build_validator.go[1] [2]File Renames and Minor Cleanups:
validator__.go). (_examples/email_test/validator__.go[1]_examples/test01/validator__.go[2]_examples/test02/structsinpkg/validator__.go[3]_examples/test03/validator__.go[4]tests/bench/validator__.go[5]This refactor lays the groundwork for better modularity and future extensibility in how validators are generated and written to files.
References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17]