vertx/src/main/java/eu/internetofus/common/vertx/OpenAPIValidator.java
/**
   * Validate that the value is a valid array.
   *
   * @param promise     to inform of the validation.
   * @param environment to use for the validation.
   *
   * @return the future that says if the array is valid or not.
   */
Validate that the value is a valid array.
@param promise     to inform of the validation.
@param environment to use for the validation.

@return the future that says if the array is valid or not.
Validate that the value is a valid array . @param promise to inform of the validation . @param environment to use for the validation . @return the future that says if the array is valid or not .
static Future<ValueEnvironment> validateArrayValue(@NotNull final Promise<ValueEnvironment> promise,
      @NotNull final ValueEnvironment environment) {
    var future = promise.future();
    if (environment.value instanceof JsonArray) {
      final var value = (JsonArray) environment.value;
      final var max = value.size();
      final var minItems = environment.specification.getNumber("minItems", null);
      if (minItems != null && minItems.intValue() > max) {
        promise.fail(environment.notValid("The value require at least " + minItems + " items."));
      } else {
        final var maxItems = environment.specification.getNumber("maxItems", null);
        if (maxItems != null && maxItems.intValue() < max) {
          promise.fail(environment.notValid("The value require at maximum " + maxItems + " items."));
        } else {
          final var items = environment.specification.getJsonObject("items");
          for (var i = 0; i < max; i++) {
            final var pos = i;
            final var element = value.getValue(pos);
            future = future
                .compose(chain -> validateValue(chain.prefixFor(pos), chain.vertx, items, element).map(validElement -> {
                  final var chainArray = (JsonArray) chain.value;
                  if (chainArray.getValue(pos) != validElement) {
                    chainArray.set(pos, validElement);
                  }
                  chain.match = true;
                  return chain;
                }));
          }
          if (environment.specification.getBoolean("uniqueItems", false)) {
            future = composeValidation(future, OpenAPIValidator::validateArrayUniqueItemsValue);
          }
        }
      }
    } else {
      promise.fail(environment.notValid("Expecting a 'JsonArray' value."));
    }
    return future;
  }
static Future < ValueEnvironment > validateArrayValue ( @ NotNull final Promise < ValueEnvironment > promise , @ NotNull final ValueEnvironment environment ) { var future = promise . future ( ) ; if ( environment . value instanceof JsonArray ) { final var value = ( JsonArray ) environment . value ; final var max = value . size ( ) ; final var minItems = environment . specification . getNumber ( "minItems" , null ) ; if ( minItems != null && minItems . intValue ( ) > max ) { promise . fail ( environment . notValid ( "The value require at least " + minItems + " items." ) ) ; } else { final var maxItems = environment . specification . getNumber ( "maxItems" , null ) ; if ( maxItems != null && maxItems . intValue ( ) < max ) { promise . fail ( environment . notValid ( "The value require at maximum " + maxItems + " items." ) ) ; } else { final var items = environment . specification . getJsonObject ( "items" ) ; for ( var i = 0 ; i < max ; i ++ ) { final var pos = i ; final var element = value . getValue ( pos ) ; future = future . compose ( chain -> validateValue ( chain . prefixFor ( pos ) , chain . vertx , items , element ) . map ( validElement -> { final var chainArray = ( JsonArray ) chain . value ; if ( chainArray . getValue ( pos ) != validElement ) { chainArray . set ( pos , validElement ) ; } chain . match = true ; return chain ; } ) ) ; } if ( environment . specification . getBoolean ( "uniqueItems" , false ) ) { future = composeValidation ( future , OpenAPIValidator :: validateArrayUniqueItemsValue ) ; } } } } else { promise . fail ( environment . notValid ( "Expecting a 'JsonArray' value." ) ) ; } return future ; }
Validate that the value is a valid array.
Validate that the value is a valid array .