From 5c17b7ceb9ad24dde1c4a8f4af6b3efa4f6f73d9 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Tue, 17 Nov 2026 14:56:54 -0500 Subject: [PATCH] Fix protovalidate runtime examples The Go example imported `github.com/bufbuild/protovalidate-go`, which now declares its module path as `buf.build/go/protovalidate`, and didn't compile (`err` from `protovalidate.New` was unused). Use the package-level `protovalidate.Validate` instead. The TypeScript example called `validate` without the message schema, which v1 requires, and treated the result as a list of violations. Also: - Document `isHostAndPort`'s required `port_required` argument; calling it with none fails to compile. - Describe protovalidate as evaluating rules at runtime rather than through generated code. - Add the missing sections to the table of contents. --- .../protobuf/references/protovalidate.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/protobuf/skills/protobuf/references/protovalidate.md b/plugins/protobuf/skills/protobuf/references/protovalidate.md index 9271c3b..2461d8d 100644 --- a/plugins/protobuf/skills/protobuf/references/protovalidate.md +++ b/plugins/protobuf/skills/protobuf/references/protovalidate.md @@ -1,7 +1,7 @@ # Protovalidate Reference Protovalidate declares validation constraints directly in `.proto` files, making the schema the single source of truth for both structure and validation. -Rules are field annotations enforced at runtime via generated code and CEL expressions. +Rules are annotations on fields, messages, and oneofs, enforced at runtime by a protovalidate library that evaluates them as CEL expressions. **Documentation:** [protovalidate.com](https://protovalidate.com) @@ -19,8 +19,13 @@ Rules are field annotations enforced at runtime via generated code and CEL expre - [Oneof Rules](#oneof-rules) - [Timestamp Rules](#timestamp-rules) - [Duration Rules](#duration-rules) +- [FieldMask Rules](#fieldmask-rules) +- [Any Rules](#any-rules) +- [Ignore Rules](#ignore-rules) - [Custom CEL Rules](#custom-cel-rules) +- [CEL Extension Functions](#cel-extension-functions) - [Common Patterns](#common-patterns) +- [Predefined Constraint Rules](#predefined-constraint-rules) - [Runtime Validation](#runtime-validation) --- @@ -414,7 +419,7 @@ message SearchFilters { | `isNan()`, `isInf()` | Test for NaN or infinity | | `isEmail()`, `isHostname()`, `isUri()`, `isUriRef()` | Format validation | | `isIp()`, `isIp(version)`, `isIpPrefix()` | IP/CIDR validation | -| `isHostAndPort()` | Host:port validation | +| `isHostAndPort(port_required)` | Host:port validation | | `unique()` | Check list items are unique | | `this` | Current value being validated | | `now` | Current timestamp | @@ -479,10 +484,9 @@ Add validation calls at your service boundaries—typically in RPC handlers or m **Go:** ```go -import protovalidate "github.com/bufbuild/protovalidate-go" +import "buf.build/go/protovalidate" -validator, err := protovalidate.New() -if err := validator.Validate(msg); err != nil { +if err := protovalidate.Validate(msg); err != nil { // Handle validation error } ``` @@ -492,7 +496,10 @@ if err := validator.Validate(msg); err != nil { import { createValidator } from "@bufbuild/protovalidate"; const validator = createValidator(); -const violations = validator.validate(msg); +const result = validator.validate(UserSchema, msg); +if (result.kind !== "valid") { + // Handle result.error +} ``` For Python, Java, and other languages, see [protovalidate.com](https://protovalidate.com).