Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buf lint mistaking proto3 optional fields for oneof fields #2590

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ func checkConstraintsForField(
if fieldDescriptor.IsExtension() {
checkConstraintsForExtension(adder, fieldConstraints)
}
if fieldDescriptor.ContainingOneof() != nil && fieldConstraints.GetRequired() {
if fieldDescriptor.ContainingOneof() != nil &&
!protodesc.ToFieldDescriptorProto(fieldDescriptor).GetProto3Optional() &&
fieldConstraints.GetRequired() {
adder.addForPathf(
[]int32{requiredFieldNumber},
"Field %q has %s but is in a oneof (%s). Oneof fields must not have %s.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ message OneofTest {
}
// required is OK for non-oneof fields
string f4 = 4 [(buf.validate.field).required = true];
// optional in proto3 is a synthetic oneof, we should not report error.
optional string f5 = 5 [(buf.validate.field).required = true];
optional google.protobuf.Duration f6 = 6 [(buf.validate.field).required = true];
}