vertx/src/main/java/eu/internetofus/common/vertx/OpenAPIValidator.java
/**
   * Check a composed type.
   *
   * @param field           name of the composed type.
   * @param futureToCompose future to compose.
   * @param env             validation environment to use.
   *
   * @throws ValidationErrorException if it is not an instance of.
   *
   * @return the future to check the composed type.
   */
Check a composed type.
@param field           name of the composed type.
@param futureToCompose future to compose.
@param env             validation environment to use.

@throws ValidationErrorException if it is not an instance of.

@return the future to check the composed type.
Check a composed type . @param field name of the composed type . @param futureToCompose future to compose . @param env validation environment to use . @throws ValidationErrorException if it is not an instance of . @return the future to check the composed type .
static Future<SpecificationEnvironment> checkComposedType(@NotNull final String field,
      @NotNull final Future<SpecificationEnvironment> futureToCompose, @NotNull final SpecificationEnvironment env)
      throws ValidationErrorException {
    var future = futureToCompose;
    final var value = env.specification.getValue(field);
    if (value instanceof JsonArray) {
      final var array = (JsonArray) value;
      final var max = array.size();
      if (max == 0) {
        throw env.notValid(field, "Expecting at least one type definition.");
      } else {
        for (var i = 0; i < max; i++) {
          final var elementPrefix = field + "[" + i + "]";
          final var elementValue = array.getValue(i);
          if (elementValue instanceof JsonObject) {
            future = composeValidation(env.futureChildFor(elementPrefix, (JsonObject) elementValue),
                OpenAPIValidator::validateSpecification).map(chain -> env.addFoundTypesOf(chain));
          } else {
            throw env.notValid(elementPrefix, "Expecting a 'JsonObject' value.");
          }
        }
        if ("allOf".equals(field)) {
          future = future.compose(chain -> {
            final Promise<SpecificationEnvironment> promise = Promise.promise();
            if (chain.foundTypes != null && chain.foundTypes.size() > 1) {
              promise.fail(
                  chain.notValid(field, "This specification does not allow any value, because you have mixed types."));
            } else {
              promise.complete(chain);
            }
            return promise.future();
          });
        }
      }
    } else {
      throw env.notValid(field, "Expecting a 'JsonArray' value.");
    }
    return future;
  }
static Future < SpecificationEnvironment > checkComposedType ( @ NotNull final String field , @ NotNull final Future < SpecificationEnvironment > futureToCompose , @ NotNull final SpecificationEnvironment env ) throws ValidationErrorException { var future = futureToCompose ; final var value = env . specification . getValue ( field ) ; if ( value instanceof JsonArray ) { final var array = ( JsonArray ) value ; final var max = array . size ( ) ; if ( max == 0 ) { throw env . notValid ( field , "Expecting at least one type definition." ) ; } else { for ( var i = 0 ; i < max ; i ++ ) { final var elementPrefix = field + "[" + i + "]" ; final var elementValue = array . getValue ( i ) ; if ( elementValue instanceof JsonObject ) { future = composeValidation ( env . futureChildFor ( elementPrefix , ( JsonObject ) elementValue ) , OpenAPIValidator :: validateSpecification ) . map ( chain -> env . addFoundTypesOf ( chain ) ) ; } else { throw env . notValid ( elementPrefix , "Expecting a 'JsonObject' value." ) ; } } if ( "allOf" . equals ( field ) ) { future = future . compose ( chain -> { final Promise < SpecificationEnvironment > promise = Promise . promise ( ) ; if ( chain . foundTypes != null && chain . foundTypes . size ( ) > 1 ) { promise . fail ( chain . notValid ( field , "This specification does not allow any value, because you have mixed types." ) ) ; } else { promise . complete ( chain ) ; } return promise . future ( ) ; } ) ; } } } else { throw env . notValid ( field , "Expecting a 'JsonArray' value." ) ; } return future ; }
Check a composed type.
Check a composed type .