Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,34 @@ message MessageRequiredOneof {
}

message MessageWith3dInside {}

message MessageOneofSingleField {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test case for MessageOneofSingleFieldRequired?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do in followup PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: #379

option (buf.validate.message).oneof = {
fields: ["str_field"]
};
string str_field = 1;
bool bool_field = 2;
}

message MessageOneofMultipleFields {
option (buf.validate.message).oneof = {
fields: [
"str_field",
"bool_field"
]
};
string str_field = 1;
bool bool_field = 2;
}

message MessageOneofMultipleFieldsRequired {
option (buf.validate.message).oneof = {
fields: [
"str_field",
"bool_field"
]
required: true
};
string str_field = 1;
bool bool_field = 2;
}
20 changes: 20 additions & 0 deletions proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ message MessageRules {
// }
// ```
repeated Rule cel = 3;

// `oneof` is a repeated field of type MessageOneofRule that specifies a list of fields
// of which exactly one can be present. If `required` is also specified, then exactly one
// of the specified fields _must_ be present.
//
//
// ```proto
// message MyMessage {
// // Only one of 'field1' or 'field2' _can_ be present in this message.
// option (buf.validate.message).oneof = { fields: ["field1", "field2"] };
// // Only one of 'field3' or 'field4' _must_ be present in this message.
// option (buf.validate.message).oneof = { fields: ["field3", "field4"], required: true };
// }
// ```
repeated MessageOneofRule oneof = 4;
}

message MessageOneofRule {
repeated string fields = 1;
optional bool required = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments on the fields too?

}

// The `OneofRules` message type enables you to manage rules for
Expand Down
216 changes: 197 additions & 19 deletions tools/internal/gen/buf/validate/conformance/cases/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading