Package build.buf.protovalidate
Class Validator
java.lang.Object
build.buf.protovalidate.Validator
Performs validation on any proto.Message values. The Validator is safe for concurrent use.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidloadDescriptors(com.google.protobuf.Descriptors.Descriptor... descriptors) Loads message descriptors that are expected to be validated, allowing theValidatorto warm up.voidloadMessages(com.google.protobuf.Message... messages) Loads messages that are expected to be validated, allowing theValidatorto warm up.validate(com.google.protobuf.Message msg) Checks that message satisfies its constraints.
-
Constructor Details
-
Method Details
-
validate
Checks that message satisfies its constraints. Constraints are defined within the Protobuf file as options from the buf.validate package. AValidationResultis returned which contains a list of violations. If the list is empty, the message is valid. If the list is non-empty, the message is invalid. An exception is thrown if the message cannot be validated because the evaluation logic for the message cannot be built (CompilationException), or there is a type error when attempting to evaluate a CEL expression associated with the message (ExecutionException).- Parameters:
msg- theMessageto be validated.- Returns:
- the
ValidationResultfrom the evaluation. - Throws:
ValidationException- if there are any compilation or validation execution errors.
-
loadMessages
Loads messages that are expected to be validated, allowing theValidatorto warm up. Messages included transitively (i.e., fields with message values) are automatically handled.- Parameters:
messages- the list ofMessageto load.- Throws:
CompilationException- if there are any compilation errors during warm-up.
-
loadDescriptors
public void loadDescriptors(com.google.protobuf.Descriptors.Descriptor... descriptors) throws CompilationException Loads message descriptors that are expected to be validated, allowing theValidatorto warm up. Messages included transitively (i.e., fields with message values) are automatically handled.- Parameters:
descriptors- the list ofDescriptors.Descriptorto load.- Throws:
CompilationException- if there are any compilation errors during warm-up.
-