vertx/src/main/java/eu/internetofus/common/vertx/OpenAPIValidator.java
/**
   * Check that an specification is right.
   *
   * @param promise with the future to use.
   * @param env     environment with the data to validate.
   *
   * @return the future that inform if the specification is right or not.
   */
Check that an specification is right.
@param promise with the future to use.
@param env     environment with the data to validate.

@return the future that inform if the specification is right or not.
Check that an specification is right . @param promise with the future to use . @param env environment with the data to validate . @return the future that inform if the specification is right or not .
static private Future<SpecificationEnvironment> validateSpecification(
      @NotNull final Promise<SpecificationEnvironment> promise, @NotNull final SpecificationEnvironment env) {
    var future = promise.future();
    if (env.specification == null) {
      promise.fail(env.notValid("The OpenAPI specification can not be null."));
    } else if (!env.specification.isEmpty()) {
      if (!env.specification.containsKey("type") && !env.specification.containsKey("oneOf")
          && !env.specification.containsKey("anyOf") && !env.specification.containsKey("allOf")
          && !env.specification.containsKey("$ref") && !env.specification.containsKey("not")) {
        promise.fail(env.notValid("You must define the 'type'."));
      } else {
        try {
          for (final var fieldName : env.specification.fieldNames()) {
            switch (fieldName) {
            case "type":
              checkType(env);
              break;
            case "multipleOf":
              checkMultipleOf(env);
              break;
            case "minimum":
              checkMinimum(env);
              break;
            case "maximum":
              checkMaximum(env);
              break;
            case "exclusiveMinimum":
            case "exclusiveMaximum":
              checkInstanceOfFor(fieldName, Boolean.class, env);
              checkIfTypeIsOneOf(fieldName, env, "integer", "number");
              break;
            case "nullable":
              checkInstanceOfFor(fieldName, Boolean.class, env);
              break;
            case "uniqueItems":
              checkInstanceOfFor(fieldName, Boolean.class, env);
              checkIfTypeIs(fieldName, env, "array");
              break;
            case "default":
              future = checkDefault(future, env);
              break;
            case "properties":
              future = checkProperties(future, env);
              break;
            case "items":
              future = checkItems(future, env);
              break;
            case "required":
              checkRequired(env);
              break;
            case "minItems":
              checkMinOf(fieldName, "array", env);
              break;
            case "maxItems":
              checkMaxOf(fieldName, "minItems", "array", env);
              break;
            case "minProperties":
              checkMinOf(fieldName, "object", env);
              break;
            case "maxProperties":
              checkMaxOf(fieldName, "minProperties", "object", env);
              break;
            case "minLength":
              checkMinOf(fieldName, "string", env);
              break;
            case "maxLength":
              checkMaxOf(fieldName, "minLength", "string", env);
              break;
            case "enum":
              future = checkEnum(future, env);
              break;
            case "pattern":
              checkPattern(env);
              break;
            case "additionalProperties":
              future = checkAdditionalProperties(future, env);
              break;
            case "oneOf":
            case "anyOf":
            case "allOf":
              future = checkComposedType(fieldName, future, env);
              break;
            case "not":
              future = checkNot(future, env);
              break;
            case "$ref":
              future = checkRef(future, env);
              break;
            case "description":
            case "title":
              checkInstanceOfFor(fieldName, String.class, env);
              break;
            case "example":
            case "examples":
            case "format":
              break;
            default:
              throw env.notValid(fieldName, "Unexpected OpenAPI field.");
            }
          }
        } catch (final ValidationErrorException error) {
          promise.fail(error);
        }
      }
    } 
    return future;
  }
static private Future < SpecificationEnvironment > validateSpecification ( @ NotNull final Promise < SpecificationEnvironment > promise , @ NotNull final SpecificationEnvironment env ) { var future = promise . future ( ) ; if ( env . specification == null ) { promise . fail ( env . notValid ( "The OpenAPI specification can not be null." ) ) ; } else if ( ! env . specification . isEmpty ( ) ) { if ( ! env . specification . containsKey ( "type" ) && ! env . specification . containsKey ( "oneOf" ) && ! env . specification . containsKey ( "anyOf" ) && ! env . specification . containsKey ( "allOf" ) && ! env . specification . containsKey ( "$ref" ) && ! env . specification . containsKey ( "not" ) ) { promise . fail ( env . notValid ( "You must define the 'type'." ) ) ; } else { try { for ( final var fieldName : env . specification . fieldNames ( ) ) { switch ( fieldName ) { case "type" : checkType ( env ) ; break ; case "multipleOf" : checkMultipleOf ( env ) ; break ; case "minimum" : checkMinimum ( env ) ; break ; case "maximum" : checkMaximum ( env ) ; break ; case "exclusiveMinimum" : case "exclusiveMaximum" : checkInstanceOfFor ( fieldName , Boolean . class , env ) ; checkIfTypeIsOneOf ( fieldName , env , "integer" , "number" ) ; break ; case "nullable" : checkInstanceOfFor ( fieldName , Boolean . class , env ) ; break ; case "uniqueItems" : checkInstanceOfFor ( fieldName , Boolean . class , env ) ; checkIfTypeIs ( fieldName , env , "array" ) ; break ; case "default" : future = checkDefault ( future , env ) ; break ; case "properties" : future = checkProperties ( future , env ) ; break ; case "items" : future = checkItems ( future , env ) ; break ; case "required" : checkRequired ( env ) ; break ; case "minItems" : checkMinOf ( fieldName , "array" , env ) ; break ; case "maxItems" : checkMaxOf ( fieldName , "minItems" , "array" , env ) ; break ; case "minProperties" : checkMinOf ( fieldName , "object" , env ) ; break ; case "maxProperties" : checkMaxOf ( fieldName , "minProperties" , "object" , env ) ; break ; case "minLength" : checkMinOf ( fieldName , "string" , env ) ; break ; case "maxLength" : checkMaxOf ( fieldName , "minLength" , "string" , env ) ; break ; case "enum" : future = checkEnum ( future , env ) ; break ; case "pattern" : checkPattern ( env ) ; break ; case "additionalProperties" : future = checkAdditionalProperties ( future , env ) ; break ; case "oneOf" : case "anyOf" : case "allOf" : future = checkComposedType ( fieldName , future , env ) ; break ; case "not" : future = checkNot ( future , env ) ; break ; case "$ref" : future = checkRef ( future , env ) ; break ; case "description" : case "title" : checkInstanceOfFor ( fieldName , String . class , env ) ; break ; case "example" : case "examples" : case "format" : break ; default : throw env . notValid ( fieldName , "Unexpected OpenAPI field." ) ; } } } catch ( final ValidationErrorException error ) { promise . fail ( error ) ; } } } return future ; }
Check that an specification is right.
Check that an specification is right .
// Allow free examples because are not used for anything // No format is validated so it is unused // else accept any value