vertx/src/main/java/eu/internetofus/common/vertx/OpenAPIValidator.java
/**
     * Obtain the schema defined by a reference.
     *
     * @param ref reference of the schema to obtain.
     *
     * @return the future with the schema.
     */
Obtain the schema defined by a reference.
@param ref reference of the schema to obtain.

@return the future with the schema.
Obtain the schema defined by a reference . @param ref reference of the schema to obtain . @return the future with the schema .
public Future<JsonObject> obtainSchemaFor(@NotNull final String ref) {
      final var schema = references.get(ref);
      if (schema instanceof JsonObject) {
        return Future.succeededFuture(schema);
      } else {
        final var index = ref.lastIndexOf(SCHEMAS_PREFIX);
        if (index < 0) {
          return Future.failedFuture(this.notValid("$ref", "Not specified the schema path."));
        } else {
          final var name = ref.substring(index + SCHEMAS_PREFIX.length());
          final var path = ref.substring(0, index);
          String url;
          if (index == 0) {
            url = OpenAPIValidator.class.getClassLoader().getResource(COMMON_MODELS_RESOURCE_NAME).toString();
          } else {
            url = ref.substring(0, index);
          }
          return this.load(url).compose(resource -> {
            final Promise<JsonObject> promise = Promise.promise();
            final var schemas = resource.getJsonObject("components", new JsonObject()).getJsonObject("schemas",
                new JsonObject());
            for (final var field : schemas.fieldNames()) {
              final var value = schemas.getValue(field);
              if (value instanceof JsonObject) {
                final var newSchema = (JsonObject) value;
                references.put(path + SCHEMAS_PREFIX + field, newSchema);
                if (field.equals(name)) {
                  promise.complete(newSchema);
                }
              }
            }
            promise.tryFail(this.notValid("$ref", "Not found schema '" + name + "'."));
            return promise.future();
          });
        }
      }
    }
public Future < JsonObject > obtainSchemaFor ( @ NotNull final String ref ) { final var schema = references . get ( ref ) ; if ( schema instanceof JsonObject ) { return Future . succeededFuture ( schema ) ; } else { final var index = ref . lastIndexOf ( SCHEMAS_PREFIX ) ; if ( index < 0 ) { return Future . failedFuture ( this . notValid ( "$ref" , "Not specified the schema path." ) ) ; } else { final var name = ref . substring ( index + SCHEMAS_PREFIX . length ( ) ) ; final var path = ref . substring ( 0 , index ) ; String url ; if ( index == 0 ) { url = OpenAPIValidator . class . getClassLoader ( ) . getResource ( COMMON_MODELS_RESOURCE_NAME ) . toString ( ) ; } else { url = ref . substring ( 0 , index ) ; } return this . load ( url ) . compose ( resource -> { final Promise < JsonObject > promise = Promise . promise ( ) ; final var schemas = resource . getJsonObject ( "components" , new JsonObject ( ) ) . getJsonObject ( "schemas" , new JsonObject ( ) ) ; for ( final var field : schemas . fieldNames ( ) ) { final var value = schemas . getValue ( field ) ; if ( value instanceof JsonObject ) { final var newSchema = ( JsonObject ) value ; references . put ( path + SCHEMAS_PREFIX + field , newSchema ) ; if ( field . equals ( name ) ) { promise . complete ( newSchema ) ; } } } promise . tryFail ( this . notValid ( "$ref" , "Not found schema '" + name + "'." ) ) ; return promise . future ( ) ; } ) ; } } }
Obtain the schema defined by a reference.
Obtain the schema defined by a reference .