-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for required on oneof fields in buf lint (#2528)
This adds a check in `PROTOVALIDATE` rules in `buf lint` that checks oneof fields do not have `(buf.validate.field).required`.
- Loading branch information
1 parent
dad51a5
commit 5b912f4
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
private/bufpkg/bufcheck/buflint/testdata/protovalidate_rules/oneof.proto
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
|
||
package what; | ||
|
||
import "buf/validate/validate.proto"; | ||
import "google/protobuf/duration.proto"; | ||
|
||
message OneofTest { | ||
oneof foo { | ||
int32 v1 = 1 [ | ||
(buf.validate.field).int32.lt = 3, | ||
// must not have required | ||
(buf.validate.field).required = true | ||
]; | ||
string v2 = 2; | ||
google.protobuf.Duration v3 = 3 [ | ||
(buf.validate.field).duration.gt = {seconds: 5}, | ||
// must not have required | ||
(buf.validate.field).required = true, | ||
(buf.validate.field).duration.lt = {seconds: 10} | ||
]; | ||
} | ||
// required is OK for non-oneof fields | ||
string f4 = 4 [(buf.validate.field).required = true]; | ||
} |