Skip to content

Add protovalidate support for UUID, pattern, email, and length constraints - #33

Merged
birdayz merged 1 commit into
mainfrom
jb/regex
Sep 30, 2025
Merged

birdayz merged 1 commit into
mainfrom
jb/regex

Conversation

@birdayz

@birdayz birdayz commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

Summary

Adds support for protovalidate constraints in JSON schema generation, resolving validation errors where fields with UUID constraints were being rejected at runtime.

UUID validation: (buf.validate.field).string.uuid = true"format": "uuid"
Email validation: (buf.validate.field).string.email = true"format": "email"
Pattern validation: (buf.validate.field).string.pattern = "regex""pattern": "regex"
Length constraints: min_len/max_len"minLength"/"maxLength"
Numeric ranges: gte/lte/gt/lt"minimum"/"maximum"

Test plan

  • Added comprehensive test cases with all constraint types in test proto
  • Verified JSON schemas include proper validation in both standard and OpenAI modes
  • Updated examples and golden files
  • All existing tests pass
  • Integration tests pass
  • Linting passes

Example

Before: resource_group_id: "cloud" would be rejected with UUID validation error
After: JSON schema includes "format": "uuid" and validation works properly

The implementation supports both standard and OpenAI compatibility modes and maintains backward compatibility.

🤖 Generated with Claude Code

…aints in JSON schemas

This resolves validation errors where fields like resource_group_id with UUID constraints
were being rejected. The JSON schemas now properly include format and constraint validation.

Key changes:
- Added protovalidate dependency and imports
- Implemented extractValidateConstraints() helper function
- Added support for string constraints: uuid, email, pattern, minLength, maxLength
- Added support for numeric constraints: minimum, maximum values
- Updated test cases and examples with new TestValidation method
- Fixed buf configuration to avoid duplicate protovalidate generation
- Updated golden files to include validation constraint schemas

The generated JSON schemas now include proper validation:
- string.uuid → "format": "uuid"
- string.email → "format": "email"
- string.pattern → "pattern": "regex"
- string.min_len/max_len → "minLength"/"maxLength"
- numeric gte/lte/gt/lt → "minimum"/"maximum"

Works in both standard and OpenAI compatibility modes.
@birdayz
birdayz requested a review from rockwotj September 27, 2025 08:58
@birdayz
birdayz merged commit a98b94b into main Sep 30, 2025
4 checks passed
@birdayz
birdayz deleted the jb/regex branch September 30, 2025 09:20
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.

2 participants