feat: add protovalidate support to template#28
Conversation
- Add buf.build/bufbuild/protovalidate to buf.yaml deps - Import buf/validate/validate.proto in the proto template - Add example min_len=1 validation on EchoRequest.msg - Validation is enforced automatically by the protovalidate interceptor in the default ColdBrew chain
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 22 minutes and 14 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA Protobuf project is enhanced with validation capabilities by adding the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds protovalidate-based field validation to the generated service template so proto annotations compile and the default interceptor chain can enforce request validation.
Changes:
- Add
buf.build/bufbuild/protovalidateas a Buf module dependency. - Import
buf/validate/validate.protoand add amin_len = 1constraint toEchoRequest.msgin the template proto.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
{{cookiecutter.app_name}}/buf.yaml |
Adds the protovalidate BSR module dependency so buf/validate/validate.proto can be resolved. |
| `{{cookiecutter.app_name}}/proto/{{cookiecutter.app_name | lower}}.proto` |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add buf.build/bufbuild/protovalidate to buf.lock - Remove unused buf.build/envoyproxy/protoc-gen-validate (old PGV) - Update all buf deps to latest commits (googleapis, grpc-gateway, grpc)
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @{{cookiecutter.app_name}}/buf.yaml:
- Line 25: The buf.yaml currently includes an unused dependency
"buf.build/envoyproxy/protoc-gen-validate"; remove that entry from the deps list
so only "buf.build/bufbuild/protovalidate" (used by import
"buf/validate/validate.proto" and [(buf.validate.field).string.min_len = 1])
remains, ensuring buf.yaml's deps no longer contain
"buf.build/envoyproxy/protoc-gen-validate".
In @{{cookiecutter.app_name}}/proto/{{cookiecutter.app_name|lower}}.proto:
- Line 7: The gRPC server in InitGRPC (main.go) is missing the protovalidate
interceptor so the proto `min_len` rules won't be enforced; instantiate the
protovalidate validator (from the protovalidate package you imported) and
register its unary interceptor in the grpc.NewServer options passed by InitGRPC
(e.g., include protovalidate's UnaryServerInterceptor in the
grpc.UnaryInterceptor chain), then remove or correct the misleading proto
comment if you decide not to enable validation at runtime; reference the
InitGRPC function and the protovalidate interceptor symbol when making the
change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0c9c3f7a-0072-4ceb-8436-6a463604ee5b
📒 Files selected for processing (2)
{{cookiecutter.app_name}}/buf.yaml{{cookiecutter.app_name}}/proto/{{cookiecutter.app_name|lower}}.proto
Summary
buf.build/bufbuild/protovalidateto buf.yaml depsbuf/validate/validate.protoin the proto templatemin_len = 1validation annotation onEchoRequest.msgDepends on: go-coldbrew/interceptors#35
Test plan
Summary by CodeRabbit