Skip to content

Commit ed00afe

Browse files
author
yevhenii-nadtochii
committed
Enhance docs
1 parent 34f7049 commit ed00afe

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

java-api/src/main/kotlin/io/spine/validation/api/MessageValidator.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ import io.spine.annotation.SPI
3232
/**
3333
* A validator for an external Protobuf message of type [M].
3434
*
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.
3738
*
3839
* ## Problem
3940
*
4041
* 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.
4243
* As these classes are pre-generated, consumers cannot modify their underlying
4344
* `.proto` files to define validation constraints and the Validation library
4445
* cannot use code generation to enforce the constraints.
@@ -103,12 +104,20 @@ import io.spine.annotation.SPI
103104
* and `EarphonesValidator` classes are declared, then the generated code of `WorkingSetup`
104105
* will apple the validator to each instance passed to the `WorkingSetup.earphones` field.
105106
*
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+
*
106116
* ## Implementation
107117
*
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.
112121
*
113122
* It is a responsibility of the validator to provide the correct instances
114123
* of [DetectedViolation]. Before reporting to the user, the library converts
@@ -119,14 +128,6 @@ import io.spine.annotation.SPI
119128
* is created. Every implementation of [MessageValidator] must have a public,
120129
* no-args constructor.
121130
*
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-
*
130131
* @param M the type of Protobuf [Message] being validated.
131132
*/
132133
@SPI

0 commit comments

Comments
 (0)