-
Notifications
You must be signed in to change notification settings - Fork 54
Add new MessageOneof rule
#377
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
Changes from 6 commits
5bd0da8
4e0ef35
7498240
1b4d5d4
57e344b
34eac5b
57ee667
fd2217b
f5211e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,3 +58,48 @@ message MessageRequiredOneof { | |
| } | ||
|
|
||
| message MessageWith3dInside {} | ||
|
|
||
| message MessageOneofSingleField { | ||
| 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; | ||
| } | ||
|
|
||
| message MessageOneofUnknownFieldName { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider also having oneof with no fields (which should also be an error) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few rough edges (like this, like if you specify the same field name multiple times, and certainly others we haven't had time to think of yet), but the desire was to get this out fast. We'll keep track of these and hopefully can fix them soon, but I don't want to block this on edge cases. The faster you can start using this, the faster you can help us find more of those edges cases and we can take care of them!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In light of this, I removed the |
||
| option (buf.validate.message).oneof = { | ||
| fields: ["xxx"] | ||
| }; | ||
| string str_field = 1; | ||
| } | ||
|
|
||
| message MessageOneofNoFields { | ||
| option (buf.validate.message).oneof = { | ||
| fields: [] | ||
| }; | ||
| string str_field = 1; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,33 @@ 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. | ||
timostamm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // | ||
| // | ||
| // ```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 }; | ||
| // string field1 = 1; | ||
| // bytes field2 = 2; | ||
| // bool field3 = 3; | ||
| // int32 field4 = 4; | ||
| // } | ||
| // ``` | ||
| repeated MessageOneofRule oneof = 4; | ||
| } | ||
|
|
||
| message MessageOneofRule { | ||
| // A list of field names to include in the oneof. All field names must be | ||
| // defined in the message. | ||
| repeated string fields = 1; | ||
| // If true, one of the fields specified _must_ be set. | ||
| optional bool required = 2; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up: #379