Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions plugins/protobuf/skills/protobuf/references/protovalidate.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)

---
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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
}
```
Expand All @@ -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).