Skip to content

Commit 53182fc

Browse files
Restore and deprecate if_invalid
1 parent aafe2e1 commit 53182fc

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/main/proto/spine/options.proto

+42-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ extend google.protobuf.FieldOptions {
148148
//
149149
bool validate = 73821;
150150

151-
// Reserved 73822 for deleted `(if_invalid)` option.
151+
// See `IfInvalidOption`.
152+
IfInvalidOption if_invalid = 73822 [deprecated = true];
152153

153154
// See `GoesOption`.
154155
GoesOption goes = 73823;
@@ -868,6 +869,46 @@ message PatternOption {
868869
}
869870
}
870871

872+
// Specifies the message to show if a validated field happens to be invalid.
873+
//
874+
// It is applicable only to fields marked with `(validate)`.
875+
//
876+
message IfInvalidOption {
877+
878+
// Do not specify error message for `(validate)`, it is no longer used by
879+
// the validation library.
880+
option deprecated = true;
881+
882+
// The default error message.
883+
option (default_message) = "The field `${parent.type}.${field.path}` of the type `${field.type}` is invalid. The field value: `${field.value}`.";
884+
885+
// A user-defined validation error format message.
886+
//
887+
// Use `error_msg` instead.
888+
//
889+
string msg_format = 1 [deprecated = true];
890+
891+
// A user-defined error message.
892+
//
893+
// The specified message may include the following placeholders:
894+
//
895+
// 1. `${field.path}` – the field path.
896+
// 2. `${field.value}` - the field value.
897+
// 3. `${field.type}` – the fully qualified name of the field type.
898+
// 4. `${parent.type}` – the fully qualified name of the field declaring type.
899+
//
900+
// The placeholders will be replaced at runtime when the error is constructed.
901+
//
902+
// Example: Using the `(if_invalid)` option.
903+
//
904+
// message Transaction {
905+
// TransactionDetails details = 1 [(validate) = true,
906+
// (if_invalid).error_msg = "The `${field.path}` field is invalid."];
907+
// }
908+
//
909+
string error_msg = 2;
910+
}
911+
871912
// Specifies that another field must be present if the option's target field is present.
872913
//
873914
// Unlike the `required_field` that handles combination of required fields, this option is useful

0 commit comments

Comments
 (0)