Class RequestValidator

java.lang.Object
io.github.belgif.rest.problem.validation.RequestValidator

public class RequestValidator extends Object
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 Details

    • RequestValidator

      public RequestValidator()
  • Method Details

    • validate

      public void validate() throws BadRequestProblem
      Perform all configured validations.
      Throws:
      BadRequestProblem - if the validation fails, containing each encountered InputValidationIssue
    • ssin

      public RequestValidator ssin(Input<String> ssin)
      Validate the structure of a Belgif openapi-person-identifier SSIN.
      Parameters:
      ssin - the SSIN to validate
      Returns:
      this RequestValidator
      See Also:
    • ssins

      public RequestValidator ssins(Input<List<String>> 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

      public RequestValidator enterpriseNumber(Input<String> enterpriseNumber)
      Validate the structure of a Belgif openapi-organization-identifier EnterpriseNumber.
      Parameters:
      enterpriseNumber - the enterprise number to validate
      Returns:
      this RequestValidator
      See Also:
    • establishmentUnitNumber

      public RequestValidator establishmentUnitNumber(Input<String> 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

      public RequestValidator period(Input<?> 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 start
      end - the input with the end
      Returns:
      this RequestValidator
    • incompleteDate

      public RequestValidator incompleteDate(Input<String> incompleteDate)
      Validate the structure of a Belgif openapi-time IncompleteDate.
      Parameters:
      incompleteDate - the IncompleteDate to validate
      Returns:
      this RequestValidator
      See Also:
    • yearMonth

      public RequestValidator yearMonth(Input<String> yearMonth)
      Validate the structure of a Belgif openapi-time YearMonth.
      Parameters:
      yearMonth - the YearMonth to validate
      Returns:
      this RequestValidator
      See Also:
    • exactlyOneOf

      public RequestValidator exactlyOneOf(Input<?>... inputs)
      Validate that exactly one of the given inputs is present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this RequestValidator
    • anyOf

      public RequestValidator anyOf(Input<?>... inputs)
      Validate that any of the given inputs is present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this RequestValidator
    • zeroOrAllOf

      public RequestValidator zeroOrAllOf(Input<?>... inputs)
      Validate that all or none of the given inputs are present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this RequestValidator
    • zeroOrExactlyOneOf

      public RequestValidator zeroOrExactlyOneOf(Input<?>... inputs)
      Validate that exactly one or none of the given inputs are present.
      Parameters:
      inputs - the inputs to validate
      Returns:
      this RequestValidator
    • equal

      public RequestValidator equal(Input<?>... inputs)
      Validate that the given inputs are equal (according to Object.equals(Object)).
      Parameters:
      inputs - the inputs to validate
      Returns:
      this RequestValidator
    • nullOrEqual

      public RequestValidator nullOrEqual(Input<?> nullableInput, Input<?> mustMatch)
      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 equal
      mustMatch - the reference input that must be matched against
      Returns:
      this RequestValidator
    • refData

      public <T> RequestValidator refData(Input<T> input, Collection<T> allowedRefData)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefData - the allowed reference data
      Returns:
      this RequestValidator
    • refData

      public <T> RequestValidator refData(Input<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 validate
      allowedRefDataSupplier - the supplier of the allowed reference data
      Returns:
      this RequestValidator
    • refData

      public <T> RequestValidator refData(Input<T> input, Predicate<T> allowedRefDataPredicate)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefDataPredicate - the predicate for verifying the reference data
      Returns:
      this RequestValidator
    • refDatas

      public <T> RequestValidator refDatas(Input<List<T>> input, Collection<T> allowedRefData)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefData - 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 validate
      allowedRefDataSupplier - the supplier of the allowed reference data
      Returns:
      this RequestValidator
    • refDatas

      public <T> RequestValidator refDatas(Input<List<T>> input, Predicate<T> allowedRefDataPredicate)
      Validate that the given input is in the allowed reference data.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      allowedRefDataPredicate - the predicate for verifying the reference data
      Returns:
      this RequestValidator
    • reject

      public <T> RequestValidator reject(Input<T> input)
      Validate that the given input is not present.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      Returns:
      this RequestValidator
    • require

      public <T> RequestValidator require(Input<T> input)
      Validate that the given input is present.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      Returns:
      this RequestValidator
    • requireIfPresent

      public RequestValidator requireIfPresent(Input<?> target, Input<?>... inputs)
      Validate that all the given inputs are present when the given target input is present.
      Parameters:
      target - the target input
      inputs - 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 condition
      requestValidatorConsumer - the RequestValidator consumer that will only be called if condition is true
      Returns:
      this RequestValidator
    • range

      public <T extends Comparable<T>> RequestValidator range(Input<T> input, T min, T max)
      Validate that the given input value is in the given [min, max] range.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      min - the minimum (inclusive)
      max - the maximum (inclusive)
      Returns:
      this RequestValidator
    • minimum

      public <T extends Comparable<T>> RequestValidator minimum(Input<T> input, T min)
      Validate that the given input value is not less than the given minimum.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      min - the minimum (inclusive)
      Returns:
      this RequestValidator
    • maximum

      public <T extends Comparable<T>> RequestValidator maximum(Input<T> input, T max)
      Validate that the given input value does not exceed the given maximum.
      Type Parameters:
      T - the input type
      Parameters:
      input - the input to validate
      max - the maximum (inclusive)
      Returns:
      this RequestValidator
    • custom

      public RequestValidator custom(InputValidator validator)
      Register a custom InputValidator.
      Parameters:
      validator - the custom validator
      Returns:
      this RequestValidator