- Overview
- Quick Start
- Introduction
- Guides
- Client Libraries
- API Reference
- Examples
- DDD Resources
- Validation user guide
- Validation developer guide
Options for oneof fields
Use this page when you have a oneof group and want to enforce that one of its cases is set.
For canonical definitions, see spine/options.proto.
Required selection: (choice)
Use (choice).required = true on a oneof group to require selecting one of its fields.
Applies to
oneofgroups (declared on theoneofitself, not on a field inside it).
Minimal example
import "spine/options.proto";
message Contact {
oneof channel {
option (choice).required = true;
string email = 1;
string phone = 2;
}
}
Common combinations / gotchas
- Use
(choice)for the group, and apply field-level constraints (like(pattern)or(required)) to individual cases when needed. - If the requirement is “at least one of these fields OR one of these other fields”, use
message-level options with
(require).fieldsand includeoneofgroup names.