use of io.vertx.ext.web.openapi.impl.OpenAPIHolderImpl 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();
}
Aggregations