protobuf-es
protobuf-es copied to clipboard
Support buf.validate.oneof for Valid Types
If (buf.validate.oneof).required = true; is used should the union for the valid msg exclude the undefined variant?
message MyOneOf {
oneof variant {
option (buf.validate.oneof).required = true;
string value1 = 1;
string value2 = 2;
}
}
/**
* @generated from message inputs.model.v1.MyOneOf
*/
export type MyOneOf = Message<"inputs.model.v1.MyOneOf"> & {
/**
* @generated from oneof inputs.model.v1.MyOneOf.variant
*/
variant: {
/**
* @generated from field: string value1 = 1;
*/
value: string;
case: "value1";
} | {
/**
* @generated from field: string value2 = 2;
*/
value: string;
case: "value2";
} | { case: undefined; value?: undefined };
};
export type MyOneOfValid = MyOneOf;
Valid types is an experimental feature. For a start, we only honor the required rule on message fields.
But we'd definitely love to support more rules in the future, and oneof.required is probably one of the first ones we want to add. 👍