Search in sources :

Example 1 with ValidationException

use of io.vertx.json.schema.ValidationException in project vertx-web by vert-x3.

the class RouterBuilder method create.

/**
 * Create a new {@link RouterBuilder}
 *
 * @param vertx
 * @param url     location of your spec. It can be an absolute path, a local path or remote url (with HTTP/HTTPS
 *                protocol)
 * @param options options for specification loading
 * @return Future completed with success when specification is loaded and valid
 */
static Future<RouterBuilder> create(Vertx vertx, String url, OpenAPILoaderOptions options) {
    ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext();
    Promise<RouterBuilder> promise = ctx.promise();
    HttpClient httpClient = vertx.createHttpClient();
    OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx, httpClient, vertx.fileSystem(), options);
    loader.loadOpenAPI(url).onComplete(ar -> {
        if (ar.failed()) {
            if (ar.cause() instanceof ValidationException) {
                promise.fail(RouterBuilderException.createInvalidSpec(ar.cause()));
            } else {
                promise.fail(RouterBuilderException.createInvalidSpecFile(url, ar.cause()));
            }
        } else {
            RouterBuilder factory;
            try {
                factory = new OpenAPI3RouterBuilderImpl(vertx, httpClient, loader, options);
            } catch (Exception e) {
                promise.fail(RouterBuilderException.createRouterBuilderInstantiationError(e, url));
                return;
            }
            promise.complete(factory);
        }
    });
    return promise.future();
}
Also used : OpenAPIHolderImpl(io.vertx.ext.web.openapi.impl.OpenAPIHolderImpl) ValidationException(io.vertx.json.schema.ValidationException) HttpClient(io.vertx.core.http.HttpClient) ContextInternal(io.vertx.core.impl.ContextInternal) OpenAPI3RouterBuilderImpl(io.vertx.ext.web.openapi.impl.OpenAPI3RouterBuilderImpl) ValidationException(io.vertx.json.schema.ValidationException)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)1 ContextInternal (io.vertx.core.impl.ContextInternal)1 OpenAPI3RouterBuilderImpl (io.vertx.ext.web.openapi.impl.OpenAPI3RouterBuilderImpl)1 OpenAPIHolderImpl (io.vertx.ext.web.openapi.impl.OpenAPIHolderImpl)1 ValidationException (io.vertx.json.schema.ValidationException)1