@@ -32,13 +32,14 @@ import io.spine.annotation.SPI
32
32
/* *
33
33
* A validator for an external Protobuf message of type [M].
34
34
*
35
- * This interface allows adding validation logic to messages, for which there is
36
- * no control over the generated code.
35
+ * This interface enforces validation rules for `Message`s whose Java/Kotlin classes
36
+ * are already generated by third parties, in case they are used in the Protobuf
37
+ * codebase to which the Validation library is applied.
37
38
*
38
39
* ## Problem
39
40
*
40
41
* Java/Kotlin libraries that use Protobuf messages often distribute both the `.proto`
41
- * definitions and the compiled class files (.class) for these messages.
42
+ * definitions and the compiled class files (` .class` ) for these messages.
42
43
* As these classes are pre-generated, consumers cannot modify their underlying
43
44
* `.proto` files to define validation constraints and the Validation library
44
45
* cannot use code generation to enforce the constraints.
@@ -103,12 +104,20 @@ import io.spine.annotation.SPI
103
104
* and `EarphonesValidator` classes are declared, then the generated code of `WorkingSetup`
104
105
* will apple the validator to each instance passed to the `WorkingSetup.earphones` field.
105
106
*
107
+ * Please note that the following use cases are NOT supported and will lead to an error:
108
+ *
109
+ * 1) Declaring a validator for a local message is prohibited. Only external messages are
110
+ * allowed to have a validator. Use built-in or custom validation options to declare
111
+ * constraints for local messages.
112
+ * 2) Declaring multiple validators for the same message type is prohibited. The library
113
+ * scans the module’s classpath to discover validators, and expects exactly one validator
114
+ * per message type.
115
+ *
106
116
* ## Implementation
107
117
*
108
- * The message validator does not have restrictions upon how exactly the message
109
- * must be validated. It can validate a particular field, several fields,
110
- * the whole message instance (for example, checking the field relations),
111
- * and perform a deep validation.
118
+ * The interface offers flexible validation strategies. Implementations can choose to
119
+ * validate a particular field, several fields, the whole message instance (for example,
120
+ * checking the field relations), and perform a deep validation.
112
121
*
113
122
* It is a responsibility of the validator to provide the correct instances
114
123
* of [DetectedViolation]. Before reporting to the user, the library converts
@@ -119,14 +128,6 @@ import io.spine.annotation.SPI
119
128
* is created. Every implementation of [MessageValidator] must have a public,
120
129
* no-args constructor.
121
130
*
122
- * An implementation of [MessageValidator] will be rejected by the library
123
- * in the following cases:
124
- *
125
- * 1) It is used to validate a local message. Only external messages are allowed
126
- * to have a validator.
127
- * 2) There already exists a validator for the specified message type. Having several
128
- * validators for the same message type is prohibited.
129
- *
130
131
* @param M the type of Protobuf [Message] being validated.
131
132
*/
132
133
@SPI
0 commit comments