Skip to content

Add regex pattern validation#87

Merged
cubahno merged 1 commit into
mainfrom
ig/regex-validation
Jun 18, 2026
Merged

Add regex pattern validation#87
cubahno merged 1 commit into
mainfrom
ig/regex-validation

Conversation

@cubahno

@cubahno cubahno commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Enforce OpenAPI pattern constraints in generated validation

Generated Validate() methods now respect the OpenAPI pattern (regex) keyword. Until now pattern was parsed but never enforced, so values that violated a schema's regex still passed validation.

What it does

  • String fields, array items, and map values that declare a pattern are checked against the regex inside Validate().
  • Empty values pass the pattern check (use required to reject empties), consistent with how the other constraints behave.
  • Failures report the field and the expected pattern.

Notes

  • validation.simple: true keeps using validate.Struct() and does not enforce pattern, in line with its other documented limitations.
  • Patterns that Go's regex engine can't compile (e.g. lookahead/backreferences) are skipped with a warning instead of breaking generation.

@cubahno cubahno marked this pull request as ready for review June 18, 2026 13:37
@cubahno cubahno merged commit 50de3d8 into main Jun 18, 2026
3 checks passed
@cubahno cubahno deleted the ig/regex-validation branch June 18, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant