4.15. Eclipse Vert.x OpenAPI の変更点
Eclipse Vert.x 4 では、新しいモジュール vertx-web-openapi が利用できるようになりました。このモジュールは vertx-web と併用して、コントラクト駆動型アプリケーションを開発します。
新しいモジュールは、Eclipse Vert.x Web Router と適切に機能します。新しいモジュールには以下の Eclipse Vert.x 依存関係が必要です。
-
vertx-json-schema -
vertx-web-validation
新しいモジュールは、io .vertx.ext.web.openapi パッケージで利用できます。
Eclipse Vert.x 4 では、新しいモジュールへの移行を容易にするために、古い OpenAPI モジュール vertx-web-api-contract がサポートされます。新しい機能を活用するには、新しいモジュール vertx-web-openapi に移行することが推奨されます。
4.15.1. 新規モジュールはルータービルダーを使用 リンクのコピーリンクがクリップボードにコピーされました!
Vertx -web-openapi モジュールは RouterBuilder を使用して Eclipse Vert.x Web ルーターをビルドします。このルータービルダーは、vertx- web-api-contract モジュールのルータービルダー OpenAPI3RouterFactory と似ています。
Vertx -web-openapi モジュールの使用を開始するには、RouterBuilder をインスタンス化します。
RouterBuilder.create(vertx, "petstore.yaml").onComplete(ar -> {
if (ar.succeeded()) {
// Spec loaded with success
RouterBuilder routerBuilder = ar.result();
} else {
// Something went wrong during router builder initialization
Throwable exception = ar.cause();
}
});
Future を使用して RouterBuilder をインスタンス化することもできます。
RouterBuilder.create(vertx, "petstore.yaml")
.onSuccess(routerBuilder -> {
// Spec loaded with success
})
.onFailure(exception -> {
// Something went wrong during router builder initialization
});
Vertx -web-openapi モジュールは、Eclipse Vert.x ファイルシステム API を使用してファイルを読み込みます。そのため、クラスパスリソースに / を指定する必要はありません。たとえば、アプリケーションに petstore.yaml を指定できます。RouterBuilder は、クラスパスリソースからコントラクトを特定できます。