validate: integrate protovalidate for CEL validation#378
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #378 +/- ##
==========================================
+ Coverage 74.11% 74.26% +0.14%
==========================================
Files 87 87
Lines 8727 8836 +109
==========================================
+ Hits 6468 6562 +94
- Misses 1698 1707 +9
- Partials 561 567 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
wenchy
requested changes
Apr 8, 2026
wenchy
requested changes
Apr 8, 2026
Comment on lines
+279
to
+285
| if validator != nil { | ||
| if err := validator.Validate(msg); err != nil { | ||
| return xerrors.Wrap(err) | ||
| } | ||
| } else if err := protovalidate.Validate(msg); err != nil { | ||
| return xerrors.Wrap(err) | ||
| } |
Member
There was a problem hiding this comment.
Discussion: validate on each parsed cell? for the exact cell position when printing errors.
wenchy
requested changes
Apr 9, 2026
| message ValidateStructType { | ||
| option (tableau.struct) = {name:"ValidateStructType"}; | ||
| option (buf.validate.message) = {cel:{id:"validate_struct.num_positive" message:"num must be positive when id > 0" expression:"this.id == 0u || this.num > 0"}}; | ||
| option (buf.validate.message) = {cel:{id:"validate_struct.range" expression:"this.min > this.max ? 'min(%d) must be less than or equal to max(%d)'.format([this.min, this.max]) : ''"}}; |
Member
There was a problem hiding this comment.
- Should also support assigning
validatetoMODE_STRUCT_TYPE_MULTIandMODE_UNION_TYPE_MULTIsheets - Improve readability, change
less than or equal to-><= - Add new struct
Timespan, and validate thebeginandendtimestamp fields.
wenchy
requested changes
Apr 9, 2026
wenchy
requested changes
Apr 9, 2026
feat: Add validate field to FieldProp for protovalidate feat: Add protovalidate message-level validation support refactor: Align field validation naming and Go version to 1.24.x refactor: Refactor worksheet validation to use item_map structure refactor: Unify protovalidate usage and imports refactor: Simplify proto export and improve naming clarity feat: Add validation support for struct and union types feat: Integrate protovalidate for custom rule validation The code introduces protovalidate integration to support custom predefined validation rules. It adds validator initialization, modifies message exporting to use the validator, and includes tests for custom rule validation. chore: Add go_package and trim top blank line refactor: Improve error handling and update dependencies chore: Remove unused bufValidateProtoPath constant feat: Add validation tests and proto for well-known and predefined types refactor: Migrate range validations to timespan with CEL refactor: Rename FieldValidate to Validate, constraints to rules refactor: Rename message validation and split field validation into Validate/ValidateComplex feat: Add uint32/gt and map min_pairs validations refactor: Simplify FieldOptions init in test refactor(exporter): Update comments and enhance validate usage
wenchy
approved these changes
Apr 10, 2026
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.
Overview
Integrates protovalidate (buf's proto validation framework) into the tableau pipeline, enabling users to declare validation rules directly in spreadsheet field/worksheet properties, which are then compiled into generated proto files and enforced at config generation time.
Proto Schema Changes (
tableau.proto)Added new fields to support validation rule declarations:
FieldProp.validate— field-level rules for scalar and well-known types (text-formatbuf.validate.FieldRules, e.g."string:{max_len:10}")FieldProp.validate_complex— field-level rules for complex types (list/map), e.g."repeated:{min_items:1}"FieldProp.validate_message— message-level rules for the nested message of a field (text-formatbuf.validate.MessageRules)WorksheetOptions.validate— message-level rules at the worksheet/messager levelProto Generation (
protogen)exporter.go: During proto file export, the threevalidate*fields are parsed from text-format intovalidate.FieldRules/validate.MessageRules, then emitted as(buf.validate.field)/(buf.validate.message)options in the generated.protofile. The raw string fields are cleared afterward to avoid leaking them into(tableau.field)options.marshalToText/unmarshalFromText: Converted from package-level functions tobookExportermethods, using aProtoRegistryTypesresolver to correctly handle custom predefined rule extensions.genFieldOptionsString: Now acceptsfieldRulesand appends(buf.validate.field)when present.addMessageExtensionImports: New helper that recursively walks a proto message to collect and register import paths for all extension fields (needed for custom rule definitions).field_prop.go:ExtractMapFieldProp,ExtractListFieldProp,ExtractStructFieldProp, andExtractScalarFieldPropnow propagate the newvalidate*fields to their respective extracted prop copies.Config Generation (
confgen)confgen.go: Aprotovalidate.Validatoris created withWithExtensionTypeResolver(dynamicpb.NewTypes(...))to support custom predefined rules, and passed down toSheetExporter.util.go: A newvalidate()helper runs protovalidate on each generated config message. Violations are collected and wrapped asE2027errors (with violation description and the offending field value), then joined and returned.storeMessage: Now accepts avalidatorand callsvalidate()before writing output files.Error Reporting (
xerrors/ i18n)E2027:protovalidate violation— reports{{ quote .FieldValue }} violates rule: {{.Violation}}with the violation description fromv.String()and the actual field value.i18n.FuncMapexported so theecodecode-generator tool can reuse it (fixing aquotefunction not defined panic duringgo generate).Tests & Testdata
Added comprehensive functional test cases covering: