Skip to content

Add oneof and iscolor for the common validator example - #116

Merged
leocavalcante merged 5 commits into
mainfrom
feat/common-validator-example
Sep 29, 2026
Merged

leocavalcante merged 5 commits into
mainfrom
feat/common-validator-example

Conversation

@leocavalcante

Copy link
Copy Markdown
Member

Summary

  • Add oneof and iscolor (hexcolor, rgb, rgba, hsl, hsla) so the common go-playground User and Address example validates, including dive into address elements.
  • Accept a validate struct tag key as well as valid.
  • Color checks use the validator v10.28.0 patterns and are compared against that library in tests.

Test plan

  • make unittests
  • make endtoendtests, including the published invalid User (Age 135, #000-, missing city) and nested address dive
  • CI build

Fixes #4

The usual User and Address structs need space-separated oneof, the iscolor alias, and the validate tag key, including dive into address elements.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 High severity · 1 Medium severity

Open (3)
What changed in this PR

Adds compatibility with the common go-playground validator example.

Changes:

  • Supports validate tags, oneof, and color validations.
  • Adds nested dive validation 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Empty validation tag values currently trigger an analyzer panic and must be handled safely.

Review effort: Balanced
Findings: 2 High severity · 2 Medium severity · 1 Low severity

Open (5)
Files not reviewed (1)
  • tests/endtoend/commonexample/validator__.go: Generated file

Comment thread internal/analyzer/analyzer.go Outdated
}

return fieldValidations, hasValidTag
return strings.Split(value, ","), true
Comment thread docs/internals.md Outdated
`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.
@leocavalcante
leocavalcante merged commit c3a917d into main Sep 29, 2026
3 checks passed
@leocavalcante
leocavalcante deleted the feat/common-validator-example branch September 29, 2026 22:08
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.

Be compliant with the most common example of validator package

2 participants