Class RequestValidator
java.lang.Object
io.github.belgif.rest.problem.validation.RequestValidator
Performs validation on input parameters of an API request.
This validation does not stop on the first invalid input. It performs all configured validations and if any of
them failed, a BadRequestProblem is thrown, containing each encountered InputValidationIssue.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionValidate that any of the given inputs is present.custom(InputValidator validator) Register a customInputValidator.enterpriseNumber(Input<String> enterpriseNumber) Validate the structure of a Belgif openapi-organization-identifier EnterpriseNumber.Validate that the given inputs are equal (according toObject.equals(Object)).establishmentUnitNumber(Input<String> establishmentUnitNumber) Validate the structure of a Belgif openapi-organization-identifier EstablishmentUnitNumber.exactlyOneOf(Input<?>... inputs) Validate that exactly one of the given inputs is present.incompleteDate(Input<String> incompleteDate) Validate the structure of a Belgif openapi-time IncompleteDate.<T extends Comparable<T>>
RequestValidatorValidate that the given input value does not exceed the given maximum.<T extends Comparable<T>>
RequestValidatorValidate that the given input value is not less than the given minimum.nullOrEqual(Input<?> nullableInput, Input<?> mustMatch) Validate that the given input is either null, or equal to another given input if present.Validate the structure of a Belgif openapi-time Period or PeriodOptionalEnd.<T extends Temporal & Comparable<? super T>>
RequestValidatorValidate that two comparable temporal inputs make a valid period.<T extends Comparable<T>>
RequestValidatorValidate that the given input value is in the given [min, max] range.<T> RequestValidatorrefData(Input<T> input, Collection<T> allowedRefData) Validate that the given input is in the allowed reference data.<T> RequestValidatorValidate that the given input is in the allowed reference data.<T> RequestValidatorrefData(Input<T> input, Supplier<Collection<T>> allowedRefDataSupplier) Validate that the given input is in the allowed reference data.<T> RequestValidatorrefDatas(Input<List<T>> input, Collection<T> allowedRefData) Validate that the given input is in the allowed reference data.<T> RequestValidatorValidate that the given input is in the allowed reference data.<T> RequestValidatorrefDatas(Input<List<T>> input, Supplier<Collection<T>> allowedRefDataSupplier) Validate that the given input is in the allowed reference data.<T> RequestValidatorValidate that the given input is not present.<T> RequestValidatorValidate that the given input is present.requireIfPresent(Input<?> target, Input<?>... inputs) Validate that all the given inputs are present when the given target input is present.Validate the structure of a Belgif openapi-person-identifier SSIN.Validate the structure of a list of Belgif openapi-person-identifier SSIN.voidvalidate()Perform all configured validations.when(boolean condition, Consumer<RequestValidator> requestValidatorConsumer) Conditionally register input validators.Validate the structure of a Belgif openapi-time YearMonth.zeroOrAllOf(Input<?>... inputs) Validate that all or none of the given inputs are present.zeroOrExactlyOneOf(Input<?>... inputs) Validate that exactly one or none of the given inputs are present.
-
Constructor Details
-
RequestValidator
public RequestValidator()
-
-
Method Details
-
validate
Perform all configured validations.- Throws:
BadRequestProblem- if the validation fails, containing each encounteredInputValidationIssue
-
ssin
Validate the structure of a Belgif openapi-person-identifier SSIN.- Parameters:
ssin- the SSIN to validate- Returns:
- this RequestValidator
- See Also:
-
ssins
Validate the structure of a list of Belgif openapi-person-identifier SSIN.- Parameters:
ssins- the SSINs to validate- Returns:
- this RequestValidator
- See Also:
-
enterpriseNumber
Validate the structure of a Belgif openapi-organization-identifier EnterpriseNumber.- Parameters:
enterpriseNumber- the enterprise number to validate- Returns:
- this RequestValidator
- See Also:
-
establishmentUnitNumber
Validate the structure of a Belgif openapi-organization-identifier EstablishmentUnitNumber.- Parameters:
establishmentUnitNumber- the establishment unit number to validate- Returns:
- this RequestValidator
- See Also:
-
period
Validate the structure of a Belgif openapi-time Period or PeriodOptionalEnd.- Parameters:
period- the Period or PeriodOptionalEnd to validate- Returns:
- this RequestValidator
- See Also:
-
period
public <T extends Temporal & Comparable<? super T>> RequestValidator period(Input<T> start, Input<T> end) Validate that two comparable temporal inputs make a valid period.This can be used with types like
LocalDate,LocalDateTime,OffsetDateTime,Year,YearMonth, ...- Type Parameters:
T- the comparable temporal type- Parameters:
start- the input with the startend- the input with the end- Returns:
- this RequestValidator
-
incompleteDate
Validate the structure of a Belgif openapi-time IncompleteDate.- Parameters:
incompleteDate- the IncompleteDate to validate- Returns:
- this RequestValidator
- See Also:
-
yearMonth
Validate the structure of a Belgif openapi-time YearMonth.- Parameters:
yearMonth- the YearMonth to validate- Returns:
- this RequestValidator
- See Also:
-
exactlyOneOf
Validate that exactly one of the given inputs is present.- Parameters:
inputs- the inputs to validate- Returns:
- this RequestValidator
-
anyOf
Validate that any of the given inputs is present.- Parameters:
inputs- the inputs to validate- Returns:
- this RequestValidator
-
zeroOrAllOf
Validate that all or none of the given inputs are present.- Parameters:
inputs- the inputs to validate- Returns:
- this RequestValidator
-
zeroOrExactlyOneOf
Validate that exactly one or none of the given inputs are present.- Parameters:
inputs- the inputs to validate- Returns:
- this RequestValidator
-
equal
Validate that the given inputs are equal (according toObject.equals(Object)).- Parameters:
inputs- the inputs to validate- Returns:
- this RequestValidator
-
nullOrEqual
Validate that the given input is either null, or equal to another given input if present.- Parameters:
nullableInput- the input that can be null or equalmustMatch- the reference input that must be matched against- Returns:
- this RequestValidator
-
refData
Validate that the given input is in the allowed reference data.- Type Parameters:
T- the input type- Parameters:
input- the input to validateallowedRefData- the allowed reference data- Returns:
- this RequestValidator
-
refData
Validate that the given input is in the allowed reference data.- Type Parameters:
T- the input type- Parameters:
input- the input to validateallowedRefDataSupplier- the supplier of the allowed reference data- Returns:
- this RequestValidator
-
refData
Validate that the given input is in the allowed reference data.- Type Parameters:
T- the input type- Parameters:
input- the input to validateallowedRefDataPredicate- the predicate for verifying the reference data- Returns:
- this RequestValidator
-
refDatas
Validate that the given input is in the allowed reference data.- Type Parameters:
T- the input type- Parameters:
input- the input to validateallowedRefData- the allowed reference data- Returns:
- this RequestValidator
-
refDatas
public <T> RequestValidator refDatas(Input<List<T>> input, Supplier<Collection<T>> allowedRefDataSupplier) Validate that the given input is in the allowed reference data.- Type Parameters:
T- the input type- Parameters:
input- the input to validateallowedRefDataSupplier- the supplier of the allowed reference data- Returns:
- this RequestValidator
-
refDatas
Validate that the given input is in the allowed reference data.- Type Parameters:
T- the input type- Parameters:
input- the input to validateallowedRefDataPredicate- the predicate for verifying the reference data- Returns:
- this RequestValidator
-
reject
Validate that the given input is not present.- Type Parameters:
T- the input type- Parameters:
input- the input to validate- Returns:
- this RequestValidator
-
require
Validate that the given input is present.- Type Parameters:
T- the input type- Parameters:
input- the input to validate- Returns:
- this RequestValidator
-
requireIfPresent
Validate that all the given inputs are present when the given target input is present.- Parameters:
target- the target inputinputs- the inputs that are required when the target input is present- Returns:
- this RequestValidator
-
when
public RequestValidator when(boolean condition, Consumer<RequestValidator> requestValidatorConsumer) Conditionally register input validators.- Parameters:
condition- the conditionrequestValidatorConsumer- the RequestValidator consumer that will only be called if condition is true- Returns:
- this RequestValidator
-
range
Validate that the given input value is in the given [min, max] range.- Type Parameters:
T- the input type- Parameters:
input- the input to validatemin- the minimum (inclusive)max- the maximum (inclusive)- Returns:
- this RequestValidator
-
minimum
Validate that the given input value is not less than the given minimum.- Type Parameters:
T- the input type- Parameters:
input- the input to validatemin- the minimum (inclusive)- Returns:
- this RequestValidator
-
maximum
Validate that the given input value does not exceed the given maximum.- Type Parameters:
T- the input type- Parameters:
input- the input to validatemax- the maximum (inclusive)- Returns:
- this RequestValidator
-
custom
Register a customInputValidator.- Parameters:
validator- the custom validator- Returns:
- this RequestValidator
-