Skip to content

feat: integrate buf/validate (protovalidate) for field-level validation#378

Open
Kybxd wants to merge 7 commits intomasterfrom
buf-validate
Open

feat: integrate buf/validate (protovalidate) for field-level validation#378
Kybxd wants to merge 7 commits intomasterfrom
buf-validate

Conversation

@Kybxd
Copy link
Copy Markdown
Collaborator

@Kybxd Kybxd commented Apr 3, 2026

Summary

Integrate buf/validate (protovalidate) to support field-level validation rules in generated proto files and configuration generation.

Changes

Core Features

  • Field-level validation: Add field_validate property to FieldProp, enabling proto field-level constraints (e.g., string:{min_len:1 max_len:20}, int32:{gt:0 lte:100}) via buf.validate.field option.
  • Message-level validation: Add message_validate property to FieldProp, supporting CEL-based message-level constraints (e.g., cross-field validation like this.value <= 0 || this.name != '') via buf.validate.message option.
  • Worksheet-level validation: Add Validate column in @TABLEAU metasheet, supporting CEL-based worksheet-level constraints via buf.validate.message option on the top-level message.
  • CEL expression shorthand: Support cel_expression as a shorthand for simple CEL expressions (e.g., this.start_time < this.end_time), powered by upgrading buf.build/go/protovalidate to v1.1.0.

Implementation Details

  • Add validate field to FieldProp in tableau.proto, and validate field to MetasheetOptions in metabook.proto.
  • Update internal/protogen/exporter.go to generate buf.validate.field and buf.validate.message options in proto output.
  • Update internal/protogen/field_prop.go to parse field_validate and message_validate properties.
  • Update internal/confgen/util.go to handle buf/validate/validate.proto import path resolution.
  • Add buf/validate/validate.proto to the proto compiler's well-known import paths.

Testing

  • Add functional test CSV files: Validate#ValidateFieldLevel.csv, Validate#ValidateMessageLevel.csv, Validate#ValidateWorksheetLevel.csv with corresponding @TABLEAU.csv metasheet.
  • Add expected proto and JSON output files for validation.
  • Add unit tests for exporter_test.go and util_test.go.

Other

  • Upgrade Go version to 1.24.x in CI workflows.
  • Update go.mod dependencies including buf.build/go/protovalidate v1.1.0.

Bug Fixes (drive-by)

  • Fix confgen.go: use sheetName instead of undefined specifiedSheetName in error context.
  • Fix parser.go: remove redundant fmt.Sprintf wrapping inside xerrors.Newf.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 91.02564% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.01%. Comparing base (31e9ace) to head (3fa0aef).

Files with missing lines Patch % Lines
internal/confgen/confgen.go 0.00% 3 Missing ⚠️
internal/confgen/parser.go 0.00% 2 Missing ⚠️
internal/protogen/exporter.go 93.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #378      +/-   ##
==========================================
+ Coverage   73.93%   74.01%   +0.08%     
==========================================
  Files          87       87              
  Lines        8670     8706      +36     
==========================================
+ Hits         6410     6444      +34     
- Misses       1700     1701       +1     
- Partials      560      561       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

fieldprop(check): support CEL to write custom rules

1 participant