@@ -148,7 +148,8 @@ extend google.protobuf.FieldOptions {
148
148
//
149
149
bool validate = 73821 ;
150
150
151
- // Reserved 73822 for deleted `(if_invalid)` option.
151
+ // See `IfInvalidOption`.
152
+ IfInvalidOption if_invalid = 73822 [deprecated = true ];
152
153
153
154
// See `GoesOption`.
154
155
GoesOption goes = 73823 ;
@@ -868,6 +869,46 @@ message PatternOption {
868
869
}
869
870
}
870
871
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
+
871
912
// Specifies that another field must be present if the option's target field is present.
872
913
//
873
914
// Unlike the `required_field` that handles combination of required fields, this option is useful
0 commit comments