@@ -74,11 +74,7 @@ message SimpleRule {
74
74
protodata.Value other_value = 4 ;
75
75
76
76
// A human-readable message explaining the error.
77
- //
78
- // May include tokens `{value}` and `{other}`, which will be replaced with the runtime values
79
- // when the error is constructed.
80
- //
81
- string error_message = 5 ;
77
+ ErrorMessage error_message = 5 ;
82
78
83
79
// If `true`, this rule is ignored when the field is not set.
84
80
//
@@ -169,18 +165,6 @@ message Rule {
169
165
}
170
166
}
171
167
172
- // Describes a format string for `ConstraintViolation` message.
173
- enum ErrorMessageFormat {
174
- EM_UNDEFINED = 0 ;
175
- EM_PRINTF = 1 ;
176
- EM_PLACEHOLDERS = 2 ;
177
- }
178
-
179
- enum RuntimePlaceholder {
180
- RP_UNDEFINED = 0 ;
181
- RP_VALUE = 1 ;
182
- }
183
-
184
168
// A validation rule which is a combination of two or more rules.
185
169
//
186
170
// For example, if a value must be less than 100 and greater than 0, the two simple rules are
@@ -198,14 +182,7 @@ message CompositeRule {
198
182
Rule right = 3 ;
199
183
200
184
// A human-readable message explaining the error.
201
- //
202
- // May include tokens `{left}`, `{right}`, and `{operator}`, which will be replaced with at
203
- // runtime with the error messages of the `left` and `right` rules and the words "and" or "or"
204
- // or "xor".
205
- //
206
- // May also include the token `{value}`, but only if the `field` is also set.
207
- //
208
- string error_message = 4 ;
185
+ ErrorMessage error_message = 4 ;
209
186
210
187
// If this rule describes several constraints of the same field, this is the name of the field.
211
188
//
@@ -215,16 +192,6 @@ message CompositeRule {
215
192
// If `left` and `right` do not describe constraints of the same field, this value is empty.
216
193
//
217
194
protodata.FieldName field = 5 ;
218
-
219
- // The expected format of the error message string.
220
- ErrorMessageFormat error_message_format = 6 ;
221
-
222
- // The list of the supported placeholders.
223
- map <string , string > option_placeholders = 7 ;
224
-
225
- map <string , RuntimePlaceholder > runtime_placeholders = 8 ;
226
-
227
- bool passFieldValue = 9 ;
228
195
}
229
196
230
197
// A boolean operator.
@@ -254,3 +221,53 @@ enum LogicalOperator {
254
221
//
255
222
XOR = 3 ;
256
223
}
224
+
225
+ // TODO:2024-12-11:yevhenii.nadtochii: Remove.
226
+ // Describes a format string for `ConstraintViolation` message.
227
+ enum ErrorMessageFormat {
228
+ EM_UNDEFINED = 0 ;
229
+ EM_PRINTF = 1 ;
230
+ EM_PLACEHOLDERS = 2 ;
231
+ }
232
+
233
+ // A placeholder-based error message.
234
+ //
235
+ // Such a message may contain zero, one or more placeholders like `{fieldName}`,
236
+ // `{currentValue}`, `{pattern}`, etc. It is up to an option to define the supported placeholder
237
+ // and their values.
238
+ //
239
+ message ErrorMessage {
240
+
241
+ // An error message string which may contain placeholders.
242
+ string placeholder_format = 1 ;
243
+
244
+ // Associates the supported buildtime placeholders with their `string` values.
245
+ //
246
+ // Values for such placeholders are known during the code generation. For example, `{fieldName}`
247
+ // placeholder is already known during the build phase and can be provided immediately.
248
+ //
249
+ map <string , string > buildtime = 2 ;
250
+
251
+ // Associates the supported runtime placeholders with their values.
252
+ //
253
+ // Values for such placeholders are known in runtime. For example, `{fieldValue}` can NOT
254
+ // be provided during the build phase. The generated code should provide it.
255
+ //
256
+ // A set of such placeholders is restricted by `PlaceholderValue` enum. Tough, the option can
257
+ // introduce its own names for them, accordingly to the option's context.
258
+ //
259
+ map <string , PlaceholderValue > runtime = 3 ;
260
+ }
261
+
262
+ // Known runtime values associated with the field rule.
263
+ //
264
+ // The actual values will be substituted by the generated code in runtime.
265
+ //
266
+ enum PlaceholderValue {
267
+
268
+ // Undefined placeholder value.
269
+ RP_UNDEFINED = 0 ;
270
+
271
+ // The field value.
272
+ RP_VALUE = 1 ;
273
+ }
0 commit comments