Class AbstractRequestValidator<SELF extends AbstractRequestValidator<SELF>>
java.lang.Object
io.github.belgif.rest.problem.validation.AbstractRequestValidator<SELF>
- Type Parameters:
SELF
- self-referencing AbstractRequestValidator type (for extensible fluent builder pattern)
- Direct Known Subclasses:
RequestValidator
public abstract class AbstractRequestValidator<SELF extends AbstractRequestValidator<SELF>>
extends Object
Abstract base class for
RequestValidator
(for extensible fluent builder pattern).
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 TypeMethodDescriptionprotected SELF
addValidator
(InputValidator validator) Add anInputValidator
.Validate 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.protected SELF
getThis()
Get a self-reference to return from validator methods (for extensible fluent builder pattern)incompleteDate
(Input<String> incompleteDate) Validate the structure of a Belgif openapi-time IncompleteDate.<T extends Comparable<T>>
SELFValidate that the given input value does not exceed the given maximum.<T extends Comparable<T>>
SELFValidate 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>>
SELFValidate that two comparable temporal inputs make a valid period.<T extends Comparable<T>>
SELFValidate that the given input value is in the given [min, max] range.<T> SELF
refData
(Input<T> input, Collection<T> allowedRefData) Validate that the given input is in the allowed reference data.<T> SELF
Validate that the given input is in the allowed reference data.<T> SELF
refData
(Input<T> input, Supplier<Collection<T>> allowedRefDataSupplier) Validate that the given input is in the allowed reference data.<T> SELF
refDatas
(Input<List<T>> input, Collection<T> allowedRefData) Validate that the given input is in the allowed reference data.<T> SELF
Validate that the given input is in the allowed reference data.<T> SELF
refDatas
(Input<List<T>> input, Supplier<Collection<T>> allowedRefDataSupplier) Validate that the given input is in the allowed reference data.<T> SELF
Validate that the given input is not present.<T> SELF
Validate 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.void
validate()
Perform all configured validations.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
-
AbstractRequestValidator
public AbstractRequestValidator()
-
-
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 request validator
- See Also:
-
ssins
Validate the structure of a list of Belgif openapi-person-identifier SSIN.- Parameters:
ssins
- the SSINs to validate- Returns:
- this request validator
- See Also:
-
enterpriseNumber
Validate the structure of a Belgif openapi-organization-identifier EnterpriseNumber.- Parameters:
enterpriseNumber
- the enterprise number to validate- Returns:
- this request validator
- See Also:
-
establishmentUnitNumber
Validate the structure of a Belgif openapi-organization-identifier EstablishmentUnitNumber.- Parameters:
establishmentUnitNumber
- the establishment unit number to validate- Returns:
- this request validator
- See Also:
-
period
Validate the structure of a Belgif openapi-time Period or PeriodOptionalEnd.- Parameters:
period
- the Period or PeriodOptionalEnd to validate- Returns:
- this request validator
- See Also:
-
period
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 request validator
-
incompleteDate
Validate the structure of a Belgif openapi-time IncompleteDate.- Parameters:
incompleteDate
- the IncompleteDate to validate- Returns:
- this request validator
- See Also:
-
yearMonth
Validate the structure of a Belgif openapi-time YearMonth.- Parameters:
yearMonth
- the YearMonth to validate- Returns:
- this request validator
- See Also:
-
exactlyOneOf
Validate that exactly one of the given inputs is present.- Parameters:
inputs
- the inputs to validate- Returns:
- this request validator
-
anyOf
Validate that any of the given inputs is present.- Parameters:
inputs
- the inputs to validate- Returns:
- this request validator
-
zeroOrAllOf
Validate that all or none of the given inputs are present.- Parameters:
inputs
- the inputs to validate- Returns:
- this request validator
-
zeroOrExactlyOneOf
Validate that exactly one or none of the given inputs are present.- Parameters:
inputs
- the inputs to validate- Returns:
- this request validator
-
equal
Validate that the given inputs are equal (according toObject.equals(Object)
).- Parameters:
inputs
- the inputs to validate- Returns:
- this request validator
-
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 request validator
-
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 request validator
-
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 request validator
-
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 request validator
-
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 request validator
-
refDatas
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 request validator
-
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 request validator
-
reject
Validate that the given input is not present.- Type Parameters:
T
- the input type- Parameters:
input
- the input to validate- Returns:
- this request validator
-
require
Validate that the given input is present.- Type Parameters:
T
- the input type- Parameters:
input
- the input to validate- Returns:
- this request validator
-
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 request validator
-
when
Conditionally register input validators.- Parameters:
condition
- the conditionrequestValidatorConsumer
- the request validator consumer that will only be called if condition is true- Returns:
- this request validator
-
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 request validator
-
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 request validator
-
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 request validator
-
custom
Register a customInputValidator
.- Parameters:
validator
- the custom validator- Returns:
- this request validator
-
addValidator
Add anInputValidator
.- Parameters:
validator
- the validator- Returns:
- this request validator
-
getThis
Get a self-reference to return from validator methods (for extensible fluent builder pattern)- Returns:
- a self-reference
-