Add oneof and iscolor for the common validator example - #116
Merged
Merged
Conversation
The usual User and Address structs need space-separated oneof, the iscolor alias, and the validate tag key, including dive into address elements.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Numeric and quoted oneof inputs can break benchmark generation or produce incorrect and uncompilable validators.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Adds compatibility with the common go-playground validator example.
Changes:
- Supports
validatetags,oneof, and color validations. - Adds nested
divevalidation coverage. - Documents and tests the new behavior.
| File | Description |
|---|---|
types/color.go |
Adds color predicates. |
types/color_test.go |
Compares color behavior with validator. |
tests/endtoend/main.go |
Runs the new scenario. |
tests/endtoend/commonexample/validator__.go |
Adds generated example validators. |
tests/endtoend/commonexample/user.go |
Defines example models. |
tests/endtoend/common_validator_example.go |
Tests example validation end to end. |
README.md |
Documents tags and validations. |
internal/parser/common_example_test.go |
Tests example parsing. |
internal/codegenerator/get_test_elements_string_test.go |
Tests scalar generation. |
internal/codegenerator/get_test_elements_pointer_test.go |
Tests pointer generation. |
internal/codegenerator/condition_table.go |
Adds generation rules. |
internal/codegenerator/common_example_test.go |
Tests generated example code. |
internal/analyzer/parser_validation_test.go |
Tests new validation parsing. |
internal/analyzer/operations/operations_test.go |
Tests operation metadata. |
internal/analyzer/operations/operations_list.go |
Registers new operations. |
internal/analyzer/common_example_test.go |
Tests example analysis. |
internal/analyzer/analyzer.go |
Accepts validate tags. |
docs/internals.md |
Updates internal documentation. |
Files not reviewed (1)
- tests/endtoend/commonexample/validator__.go: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+103
to
+106
| "oneof": { | ||
| CountValues: common.ManyValues, | ||
| IsFieldOperation: false, | ||
| ValidTypes: []string{"<STRING>"}, |
| { | ||
| AcceptedTypes: []string{"<STRING>"}, | ||
| ConditionTable: ConditionTable{ | ||
| operation: `obj.{{.Name}} == "{{.Target}}"`, |
Comment on lines
+103
to
+104
| "oneof": { | ||
| CountValues: common.ManyValues, |
Reading validate tags also sees the comparison fixtures, so oneof has to accept integers, quoted tokens, and Go string escaping, and ne stays an alias of neq.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Empty validation tag values currently trigger an analyzer panic and must be handled safely.
Review effort: Balanced
Findings: 2
Open (5)
Files not reviewed (1)
- tests/endtoend/commonexample/validator__.go: Generated file
| } | ||
|
|
||
| return fieldValidations, hasValidTag | ||
| return strings.Split(value, ","), true |
| `ParserValidation` splits one validation on `=`. More than two pieces is an error. The operation's `CountValues` selects the shape. | ||
|
|
||
| `ZeroValue` operations `required` and `email` reject a target. `OneValue` operations require one target. `ManyValues` operations `in` and `nin` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. | ||
| `ZeroValue` operations `required`, `email`, `hexcolor`, `rgb`, `rgba`, `hsl`, `hsla`, and `iscolor` reject a target. `OneValue` operations require one target. `ManyValues` operations `in`, `nin`, and `oneof` require a target list. A list that starts with a single quote is read as quoted strings. Any other list is split on commas and spaces. `iscolor` is the alias for `hexcolor|rgb|rgba|hsl|hsla` and calls `types.IsColor`. `ne` and `ne_ignore_case` are read as `neq` and `neq_ignore_case`. |
An empty valid or validate value, or a blank piece between commas, is not a rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
oneofandiscolor(hexcolor,rgb,rgba,hsl,hsla) so the common go-playground User and Address example validates, includingdiveinto address elements.validatestruct tag key as well asvalid.Test plan
make unittestsmake endtoendtests, including the published invalid User (Age135,#000-, missing city) and nested addressdiveFixes #4