OpenAPI と Swagger UI の使用
このガイドでは、Quarkus アプリケーションが OpenAPI 仕様を通じて API の記述を公開する方法と、Swagger UI というユーザーフレンドリーな UI を介してそれをテストする方法について説明します。
前提条件
このガイドを完成させるには、以下が必要です:
-
約15分
-
IDE
-
JDK 17+がインストールされ、
JAVA_HOMEが適切に設定されていること -
Apache Maven 3.9.15
-
使用したい場合は、 Quarkus CLI
-
ネイティブ実行可能ファイルをビルドしたい場合、MandrelまたはGraalVM(あるいはネイティブなコンテナビルドを使用する場合はDocker)をインストールし、 適切に設定していること
ソリューション
次のセクションの手順に従って、アプリケーションをステップバイステップで作成することをお勧めします。ただし、完成した例に直接スキップすることも可能です。
Git リポジトリーをクローンするか (git clone https://github.com/quarkusio/quarkus-quickstarts.git)、https://github.com/quarkusio/quarkus-quickstarts/archive/main.zip[アーカイブ] をダウンロードしてください。
ソリューションは openapi-swaggerui-quickstart ディレクトリ にあります。
Maven プロジェクトの作成
まず、新しいプロジェクトが必要です。次のコマンドを使用して新しいプロジェクトを作成します。
Windowsユーザーの場合:
-
cmdを使用する場合、(バックスラッシュ
\を使用せず、すべてを同じ行に書かないでください)。 -
Powershellを使用する場合は、
-Dパラメータを二重引用符で囲んでください。例:"-DprojectArtifactId=openapi-swaggerui-quickstart"
REST リソースの公開
Fruit Bean と FruitResource REST リソースを作成します (Quarkus で REST API を構築する方法の詳細については、JSON REST サービスの作成ガイド を参照してください)。
package org.acme.openapi.swaggerui;
public class Fruit {
public String name;
public String description;
public Fruit() {
}
public Fruit(String name, String description) {
this.name = name;
this.description = description;
}
}
package org.acme.openapi.swaggerui;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.Path;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;
@Path("/fruits")
public class FruitResource {
private Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));
public FruitResource() {
fruits.add(new Fruit("Apple", "Winter fruit"));
fruits.add(new Fruit("Pineapple", "Tropical fruit"));
}
@GET
public Set<Fruit> list() {
return fruits;
}
@POST
public Set<Fruit> add(Fruit fruit) {
fruits.add(fruit);
return fruits;
}
@DELETE
public Set<Fruit> delete(Fruit fruit) {
fruits.removeIf(existingFruit -> existingFruit.name.contentEquals(fruit.name));
return fruits;
}
}
テストを作成することもできます。
package org.acme.openapi.swaggerui;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import jakarta.ws.rs.core.MediaType;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
@QuarkusTest
public class FruitResourceTest {
@Test
public void testList() {
given()
.when().get("/fruits")
.then()
.statusCode(200)
.body("$.size()", is(2),
"name", containsInAnyOrder("Apple", "Pineapple"),
"description", containsInAnyOrder("Winter fruit", "Tropical fruit"));
}
@Test
public void testAdd() {
given()
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}")
.header("Content-Type", MediaType.APPLICATION_JSON)
.when()
.post("/fruits")
.then()
.statusCode(200)
.body("$.size()", is(3),
"name", containsInAnyOrder("Apple", "Pineapple", "Pear"),
"description", containsInAnyOrder("Winter fruit", "Tropical fruit", "Winter fruit"));
given()
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}")
.header("Content-Type", MediaType.APPLICATION_JSON)
.when()
.delete("/fruits")
.then()
.statusCode(200)
.body("$.size()", is(2),
"name", containsInAnyOrder("Apple", "Pineapple"),
"description", containsInAnyOrder("Winter fruit", "Tropical fruit"));
}
}
OpenAPI 仕様の公開
Quarkus は、API の OpenAPI v3 仕様 を生成するために、 MicroProfile OpenAPI 仕様に準拠した SmallRye OpenAPI エクステンションを提供しています。
Quarkus アプリケーションに openapi エクステンションを追加するだけです。
quarkus extension add quarkus-smallrye-openapi
./mvnw quarkus:add-extension -Dextensions='quarkus-smallrye-openapi'
./gradlew addExtension --extensions='quarkus-smallrye-openapi'
これにより、ビルドファイルに以下が追加されます。
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
implementation("io.quarkus:quarkus-smallrye-openapi")
これで、アプリケーションを実行する準備が整いました。
quarkus dev
./mvnw quarkus:dev
./gradlew --console=plain quarkusDev
アプリケーションが起動したら、デフォルトの /q/openapi エンドポイントにリクエストを送信できます。
$ curl http://localhost:8080/q/openapi
openapi: 3.1.0
info:
title: Generated API
version: "1.0"
paths:
/fruits:
get:
responses:
200:
description: OK
content:
application/json: {}
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Fruit'
responses:
200:
description: OK
content:
application/json: {}
delete:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Fruit'
responses:
200:
description: OK
content:
application/json: {}
components:
schemas:
Fruit:
properties:
description:
type: string
name:
type: string
|
デフォルトのエンドポイントの場所である
|
|
|
CTRL+C を押してアプリケーションを停止します。
アプリケーションレベルの OpenAPI アノテーションの提供
以下のように、グローバルな API 情報を記述する MicroProfile OpenAPI アノテーションがいくつかあります。
-
API タイトル
-
API の説明
-
バージョン
-
連絡先情報
-
ライセンス
これらの情報 (およびそれ以上) は、Jakarta REST の Application クラスに適切な OpenAPI アノテーションを使用することで、Java コードに含めることができます。Quarkus では Jakarta REST の Application クラスは必須ではないため、作成する必要があるかもしれません。これは、単に jakarta.ws.rs.core.Application を継承した空のクラスでも構いません。この空のクラスには、@OpenAPIDefinition などのさまざまな OpenAPI アノテーションを付与できます。例:
@OpenAPIDefinition(
tags = {
@Tag(name="widget", description="Widget operations."),
@Tag(name="gasket", description="Operations related to gaskets")
},
info = @Info(
title="Example API",
version = "1.0.1",
contact = @Contact(
name = "Example API Support",
url = "http://exampleurl.com/contact",
email = "techsupport@example.com"),
license = @License(
name = "Apache 2.0",
url = "https://www.apache.org/licenses/LICENSE-2.0.html"))
)
public class ExampleApiApplication extends Application {
}
別のオプションとして、SmallRye が提供する機能 (仕様の一部ではありません) ですが、設定を使用してこのグローバルな API 情報を追加することもできます。この方法では、Jakarta REST の Application クラスを用意する必要がなく、環境ごとに API に異なる名前を付けることができます。
例えば、application.properties に以下を追加します。
quarkus.smallrye-openapi.info-title=Example API
%dev.quarkus.smallrye-openapi.info-title=Example API (development)
%test.quarkus.smallrye-openapi.info-title=Example API (test)
quarkus.smallrye-openapi.info-version=1.0.1
quarkus.smallrye-openapi.info-description=Just an example service
quarkus.smallrye-openapi.info-terms-of-service=Your terms here
quarkus.smallrye-openapi.info-contact-email=techsupport@example.com
quarkus.smallrye-openapi.info-contact-name=Example API Support
quarkus.smallrye-openapi.info-contact-url=http://exampleurl.com/contact
quarkus.smallrye-openapi.info-license-name=Apache 2.0
quarkus.smallrye-openapi.info-license-url=https://www.apache.org/licenses/LICENSE-2.0.html
これにより、上記の @OpenAPIDefinition の例と同様の情報が得られます。
フィルターによる OpenAPI スキーマの強化
1 つ以上のフィルターを使用して、生成された OpenAPI スキーマを変更できます。フィルターはビルド時または実行時に実行できます。
/**
* Filter to add custom elements
*/
@OpenApiFilter(stages = {OpenApiFilter.RunStage.BUILD, OpenApiFilter.RunStage.RUNTIME_PER_REQUEST}) (1)
public class MyMultiStageFilter implements OASFilter { (2)
private IndexView view;
public MyMultiStageFilter(IndexView view) { (3)
this.view = view;
}
@Override
public void filterOpenAPI(OpenAPI openAPI) { (4)
Collection<ClassInfo> knownClasses = this.view.getKnownClasses();
Info info = OASFactory.createInfo();
info.setDescription("Created from Annotated Buildtime filter with " + knownClasses.size() + " known indexed classes");
openAPI.setInfo(info);
}
}
| 1 | クラスに @OpenApiFilter アノテーションを付与し、stages フィールドで BUILD、RUNTIME_STARTUP、RUNTIME_PER_REQUEST のいずれか 1 つ以上を指定します。このフィルターはビルド時に 1 回、および OpenAPI ドキュメントが要求されるたびに実行されます。 |
| 2 | OASFilter を実装し、そのメソッドのいずれかをオーバーライドする |
| 3 | アプリケーションのビルド中に実行されるフィルター、つまり BUILD ステージのフィルター (RunStages の高度な相互作用 も参照) では、Jandex インデックスをコンストラクターに渡すことができます。アプリケーションの実行中、Jandex インデックスは null にはなりませんが、空になります。つまり、クラスやアノテーションに関する情報は含まれません。 |
| 4 | 生成された OpenAPI スキーマを取得し、必要に応じて強化する |
スキーマにフィールドを設定すると生成されたものが上書きされるため、既存のものを取得して追加 (変更) したい場合があることに注意してください。また、生成された値が null になる可能性があるため、そのチェックも必要です。
RunStages の概要
| ステージ | 意味 |
|---|---|
BUILD |
フィルターはビルド時に実行されます。 |
RUNTIME_STARTUP |
フィルターはアプリケーションの起動時に (先行して) 実行されます。 |
RUNTIME_PER_REQUEST |
フィルターは OpenAPI ドキュメントが要求されるたびに実行されます。 |
RUN |
非推奨。 |
BOTH |
非推奨。フィルターは |
quarkus.smallrye-openapi.always-run-filter 設定プロパティーは非推奨です。代わりに、フィルターに @OpenApiFilter(stages = OpenApiFilter.RunStage.RUNTIME_PER_REQUEST) を付けてください。
|
RunStages の高度な相互作用
BUILD RunStage はその名の通りビルド時に実行されることが期待されますが、ビルド時に実行される追加の RunStage も存在します。
quarkus-smallrye-openapi エクステンションは、quarkus.smallrye-openapi.store-schema-directory が設定されている場合、OpenAPI ドキュメントをファイルに保存します。この保存されたバージョンの OpenAPI ドキュメントは、ダウンストリームのコンシューマーにとって有用です。
実行時に生成されるものと一致する可能性のある (could) OpenAPI ドキュメントを生成するために、 RUN および RUNTIME_STARTUP RunStage はビルド時に (BUILD RunStage とは別のステップで) 実行されます。この追加処理ステップ中に発生した例外は無視されます。つまり、いずれかのフィルターが例外をスローしても、それらは一切影響を及ぼしません。
この追加処理ステップは、quarkus.smallrye-openapi.store-schema-directory が設定されて いない 場合でも実行されます。
静的ファイルからの OpenAPI スキーマの読み込み
アノテーションスキャンから OpenAPI スキーマを動的に作成する代わりに、Quarkus は静的な OpenAPI ドキュメントの提供もサポートしています。提供する静的ファイルは、 OpenAPI 仕様 に準拠した有効なドキュメントである必要があります。OpenAPI 仕様に準拠した OpenAPI ドキュメントは、それ自体が有効な JSON オブジェクトであり、 yaml または json 形式で表現できます。
これを実際に確認するために、/fruits エンドポイントの OpenAPI ドキュメントを META-INF/openapi.yaml の下に配置します。お好みに応じて、Quarkus は代替の OpenAPI ドキュメントパス もサポートしています。
openapi: 3.1.0
info:
title: Static OpenAPI document of fruits resource
description: Fruit resources Open API documentation
version: "1.0"
servers:
- url: http://localhost:8080/q/openapi
description: Optional dev mode server description
paths:
/fruits:
get:
responses:
200:
description: OK - fruits list
content:
application/json: {}
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Fruit'
responses:
200:
description: new fruit resource created
content:
application/json: {}
delete:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Fruit'
responses:
200:
description: OK - fruit resource deleted
content:
application/json: {}
components:
schemas:
Fruit:
properties:
description:
type: string
name:
type: string
デフォルトでは、/q/openapi へのリクエストは、静的ファイルとアプリケーションエンドポイントのコードから生成されたモデルを組み合わせた OpenAPI ドキュメントを提供します。ただし、application.properties に mp.openapi.scan.disable=true 設定を追加することで、静的な OpenAPI ドキュメントのみを提供するように変更できます。
これで、/q/openapi エンドポイントへのリクエストは、生成されたドキュメントの代わりに静的な OpenAPI ドキュメントを提供するようになります。
|
OpenAPI ドキュメントのパスについて
Quarkus は、OpenAPI ドキュメントを保存するためのさまざまなパスをサポートしています。
開発中は静的 OpenAPI ドキュメントのライブリロードがサポートされています。OpenAPI ドキュメントへの変更は、Quarkus によって即座に反映されます。 |
OpenAPI バージョンの変更
デフォルトでは、ドキュメントが生成される際、使用される OpenAPI バージョンは 3.1.0 になります。上記のように静的ファイルを使用する場合、ファイル内のバージョンが使用されます。また、SmallRye では次の設定を使用してバージョンを定義することもできます。
quarkus.smallrye-openapi.open-api-version=3.0.4
これは、API が特定のバージョンを必要とするゲートウェイを経由する場合に役立つことがあります。
|
OpenAPI バージョンを |
Operation Id の自動生成
Operation Id は @Operation アノテーションを使用して設定でき、多くの場合、スキーマからクライアントスタブを生成するツールを使用する際に役立ちます。Operation Id は通常、クライアントスタブのメソッド名に使用されます。SmallRye では、次の設定を使用してこの Operation Id を自動生成できます。
quarkus.smallrye-openapi.operation-id-strategy=METHOD
これで @Operation アノテーションを使用する必要がなくなります。ドキュメントの生成時に、メソッド名が Operation Id として使用されます。
| プロパティー値 | 説明 |
|---|---|
|
メソッド名を使用します。 |
|
クラス名 (パッケージなし) とメソッド名を使用します。 |
|
クラス名とメソッド名を使用します。 |
複数の OpenAPI ドキュメントの生成
複数の OpenAPI ドキュメントを生成できます。各ドキュメントは独自の構成を持ち、異なる REST リソースのセットを使用するように設定できます。
例えば、アプリケーションにユーザーと注文を取得するためのリソースメソッドがあるとします。
@Path("/api")
public class MyResource {
@Path("/users")
@GET
public List<UserDTO> listUsers() {
// ...
}
@Path("/orders")
@GET
public List<OrderDTO> listOrders() {
// ...
}
}
通常、これら 2 つのリソースメソッドは同じ OpenAPI ドキュメント内に並んで記述されることになります。これらはタグを使用して同じ OpenAPI ドキュメント内で視覚的に分けることができますが、複数のリソースがある大規模なデプロイメントでは、依然として以下の問題が発生します。
-
リソースメソッドが追加されるたびにドキュメントのサイズが大きくなり、OpenAPI ドキュメントが使い物にならなくなる可能性がある
-
自動生成された API クライアントのサイズや複雑さが増大する可能性がある
したがって、リソースメソッドを個別の OpenAPI ドキュメントに分割できます。これには、わずかなアノテーションと少しの設定のみが必要です。
一般的な考え方は、リソースメソッドを個別のプロファイルにグループ化することです。これは @Extension(name = "x-smallrye-profile-<profile-name>", value = "") アノテーションを使用して行います。x-smallrye-profile- の部分はプレフィックスで、<profile-name> は自由に定義できるプロファイルの名前です。
エクステンションを追加したリソースは次のようになります。
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
@Path("/api")
public class MyResource {
@Path("/users")
@GET
@Extension(name = "x-smallrye-profile-user", value = "")
public List<UserDTO> listUsers() {
// ...
}
@Path("/orders")
@GET
@Extension(name = "x-smallrye-profile-order", value = "")
public List<OrderDTO> listOrders() {
// ...
}
}
application.properties ファイルに、以下のビルド時設定を追加します。
quarkus.smallrye-openapi.info-title=Combined documentation
quarkus.smallrye-openapi.user.scan-profiles=user (1)
quarkus.smallrye-openapi.order.scan-profiles=order
| 1 | この例では、プロファイル名とドキュメント名が一致していますが、これらは両方とも自由に定義可能です。 |
これにより、Quarkus は 3 つの OpenAPI ドキュメントを作成します。
-
すべての操作が含まれるもの。デフォルトでは
/q/openapiで提供されます。 -
ユーザー操作のみが含まれるもの。デフォルトでは
/q/openapi-userで提供されます。 -
注文操作のみが含まれるもの。デフォルトでは
/q/openapi-orderで提供されます。
quarkus.smallrye-openapi.<document-name>.scan-exclude-profiles を使用して除外することも可能です。
@Extension アノテーションはリソースクラスとリソースメソッドの両方に配置できます。ただし、両方の場所に定義されたエクステンションのリストは統合 されません。OpenAPI オペレーションの有効なエクステンションは、リソースメソッドのエクステンションリストか、存在しない場合はリソースクラスのエクステンションリストのいずれかになります。
scan-profiles および scan-exclude-profiles 設定プロパティーには複数のプロファイルを指定できます。リソースクラスおよびリソースメソッドには、複数の @Extension アノテーションを使用して複数のプロファイルを指定できます。x-smallrye-profile エクステンションは、最終的な OpenAPI ドキュメントには 含まれません。
オペレーションのフィルタリング
前のセクションで示したように、オペレーションのプロファイルは @Extension を使用して定義できます。オペレーションは、そのプロファイルに基づいてドキュメントにフィルタリングされます。
-
プロファイルのないオペレーションは常に 含まれます。
-
scan-exclude-profilesが設定されている場合: いずれかのプロファイルが一致すると、オペレーションは 除外 されます。 -
scan-profilesが設定され、scan-exclude-profilesが設定されて いない 場合: 少なくとも 1 つのプロファイルがscan-profilesと一致する場合にのみ、オペレーションは 含まれます。 -
scan-exclude-profilesとscan-profilesの両方が設定されている場合、scan-exclude-profilesのみ がチェックされます。 -
どちらも設定されていない場合: すべてのオペレーションが 含まれます。
クリーンアップ
生成された OpenAPI ドキュメントには、デフォルトですべてのスキーマが含まれます。これには除外されたオペレーションによって参照されているものも含まれます。次の設定により、使用されていないスキーマがすべて削除されます。
mp.openapi.extensions.smallrye.remove-unused-schemas.enable=true
設定の適用範囲
デフォルトのドキュメントとすべての名前付きドキュメントは、同じ設定をサポートしています。ただし、MicroProfile OpenAPI の設定には小さな落とし穴があります。MicroProfile 固有の設定プロパティーはすべてのドキュメントに適用されます。以下の例を参照してください。
quarkus.smallrye-openapi.servers=https://api.example.com
デフォルトドキュメント用に指定された設定プロパティーは、デフォルトドキュメント、つまり /q/openapi で提供される OpenAPI ドキュメントにのみ適用されます。
quarkus.smallrye-openapi.<document-name>.servers=https://api.example.com
特定のドキュメント用に指定された設定プロパティーは、その特定のドキュメント、つまり /q/openapi-<document-name> で提供される OpenAPI ドキュメントにのみ適用されます。
mp.openapi.servers=https://api.example.com
MicroProfile OpenAPI の設定プロパティーは すべて の OpenAPI ドキュメントに適用されます。
フィルター
デフォルトでは、OpenAPI フィルターはすべてのドキュメントに適用されます。これは @OpenApiFilter#documentNames を設定することで変更できます。
import io.quarkus.smallrye.openapi.OpenApiFilter;
import org.eclipse.microprofile.openapi.OASFilter;
@OpenApiFilter(documentNames = {OpenApiFilter.DEFAULT_DOCUMENT_NAME, "user"}) (1)
public class MyFilter implements OASFilter {
// ...
}
| 1 | このフィルターは、デフォルトの OpenAPI ドキュメントと user という名前のドキュメントにのみ適用されます。 |
開発での Swagger UI の使用
API を構築する際、開発者はそれらを素早くテストしたいと考えます。 Swagger UI は、API を可視化して対話できるようにする優れたツールです。UI は OpenAPI 仕様から自動的に生成されます。
Quarkus の smallrye-openapi エクステンションには、適切に設定された Swagger UI ページを組み込んだ swagger-ui エクステンションが付属しています。
|
デフォルトでは、Swagger UI は Quarkus が開発モードまたはテストモードで起動された場合にのみ利用可能です。 本番環境でも利用可能にしたい場合は、
これはビルド時プロパティーであり、アプリケーションのビルド後に実行時に変更することはできません。 |
デフォルトでは、Swagger UI は /q/swagger-ui でアクセス可能です。
application.properties で quarkus.swagger-ui.path プロパティーを設定することで、/swagger-ui のサブパスを更新できます。
quarkus.swagger-ui.path=my-custom-path
|
値 |
これで、アプリケーションを実行する準備が整いました。
./mvnw quarkus:dev
アプリケーションのログで Swagger UI のパスを確認できます。
00:00:00,000 INFO [io.qua.swa.run.SwaggerUiServletExtension] Swagger UI available at /q/swagger-ui
アプリケーションが起動したら、 http://localhost:8080/q/swagger-ui にアクセスして API を試すことができます。
API のオペレーションとスキーマを視覚化できます。 
また、API と対話して素早くテストすることも可能です。 
CTRL+C を押してアプリケーションを停止します。
スタイリング
独自のロゴと CSS を提供することで、Swagger UI のスタイルを変更できます。
ロゴ
独自のロゴを提供するには、logo.png という名前のファイルを src/main/resources/META-INF/branding に配置する必要があります。
これにより、(Swagger UI だけでなく) すべての UI のロゴが設定されるため、この場合は GraphQL-UI や Health-UI (含まれている場合) も同様になります。
このロゴを Swagger UI にのみ適用し、すべての UI にグローバルに適用したくない場合は、ファイル名を logo.png ではなく smallrye-open-api-ui.png にしてください。
CSS
HTML のスタイルを上書きまたは強化する独自の CSS を提供するには、style.css という名前のファイルを src/main/resources/META-INF/branding に配置する必要があります。
これにより、(Swagger UI だけでなく) すべての UI にその CSS が追加されるため、この場合は GraphQL-UI や Health-UI (含まれている場合) も同様になります。
このスタイルを Swagger UI にのみ適用し、すべての UI にグローバルに適用したくない場合は、ファイル名を style.css ではなく smallrye-open-api-ui.css にしてください。
スタイリングに関する詳細は、こちらのブログ記事を参照してください。 https://quarkus.io/blog/stylish-api/
CORS (Cross Origin Resource Sharing)
異なるドメインで実行されているシングルページアプリケーションからこのアプリケーションを利用する予定がある場合は、CORS (Cross-Origin Resource Sharing) を設定する必要があります。詳細については、「Cross-origin resource sharing」ガイドの CORS フィルター セクションを参照してください。
複数の OpenAPI ドキュメント
複数の OpenAPI ドキュメントの生成 で説明されているように、Quarkus によって生成されると、複数の OpenAPI ドキュメントが自動的に表示されます。デフォルトでは、Swagger UI はドキュメント名にちなんだ名前のエントリーを持つドロップダウンをレンダリングします。デフォルトのドキュメント、「order」ドキュメント、「user」ドキュメントが定義されていると仮定すると、次のエントリーが表示されます。
-
\<default>
-
order
-
user
要件に基づいて、これらをよりユーザーフレンドリーな名前に変更したい場合があります。例えば、ドロップダウンのオプションを「Intro」、「Order Service」、「User Service」に変更すると、次のようになります。
quarkus.swagger-ui.urls."Combined"=/q/openapi
quarkus.swagger-ui.urls."Order Service"=/q/openapi-order
quarkus.swagger-ui.urls."User Service"=/q/openapi-user
設定リファレンス
MicroProfile OpenAPI
MicroProfile OpenAPI コア設定は、 MicroProfile OpenAPI 仕様 で定義されています。MicroProfile OpenAPI アノテーションの詳細については、 MicroProfile OpenAPI API Javadoc を参照してください。
OpenAPI
ビルド時に固定される設定プロパティー - 他のすべての設定プロパティーは実行時に上書き可能です
Configuration property |
型 |
デフォルト |
|---|---|---|
If management interface is turned on the openapi schema document will be published under the management interface. This allows you to exclude OpenAPI from management by setting the value to false Environment variable: Show more |
boolean |
|
Enable the openapi endpoint. By default it’s enabled. Environment variable: Show more |
boolean |
|
The path at which to register the OpenAPI Servlet. For the default document, the default value is simply If you set a non-default value, then your custom value is used without resolving Environment variable: Show more |
string |
|
If set, the generated OpenAPI schema documents will be stored here on build. Both openapi.json and openapi.yaml will be stored here if this is set. Environment variable: Show more |
path |
|
The name of the file in case it is being stored. For the default document, the default value is simply If you set a non-default value, then your custom value is used without resolving Environment variable: Show more |
string |
|
Do not include the provided static openapi document (eg. META-INF/openapi.yaml) Environment variable: Show more |
boolean |
|
A list of local directories that should be scanned for yaml and/or json files to be included in the static model. Example: Environment variable: Show more |
list of path |
|
Add a certain SecurityScheme with config Environment variable: Show more |
|
|
Add a Security Scheme name to the generated OpenAPI document Environment variable: Show more |
string |
|
Add a description to the Security Scheme Environment variable: Show more |
string |
|
Add one or more extensions to the security scheme Environment variable: Show more |
Map<String,String> |
|
This will automatically add the security requirement to all methods/classes that has a Environment variable: Show more |
boolean |
|
This will automatically add tags to operations based on the Java class name. Environment variable: Show more |
boolean |
|
This will automatically add Bad Request (400 HTTP response) API response to operations with an input. Environment variable: Show more |
boolean |
|
This will automatically add a summary to operations based on the Java method name. Environment variable: Show more |
boolean |
|
Setting it to Environment variable: Show more |
boolean |
|
This will automatically add security based on the security extension included (if any). Environment variable: Show more |
boolean |
|
This will automatically add the OpenAPI specification document endpoint to the schema. It also adds "openapi" to the list of tags and specify an "operationId" Environment variable: Show more |
boolean |
|
Required when using Environment variable: Show more |
string |
|
Required when using Environment variable: Show more |
string |
|
Add a scheme value to the Basic HTTP Security Scheme Environment variable: Show more |
string |
|
Add a scheme value to the JWT Security Scheme Environment variable: Show more |
string |
|
Add a bearer format the JWT Security Scheme Environment variable: Show more |
string |
|
Add a scheme value to the OAuth2 opaque token Security Scheme Environment variable: Show more |
string |
|
Add a scheme value to OAuth2 opaque token Security Scheme Environment variable: Show more |
string |
|
Add a openIdConnectUrl value to the OIDC Security Scheme Environment variable: Show more |
string |
|
Add a implicit flow refreshUrl value to the OAuth2 Security Scheme Environment variable: Show more |
string |
|
Add an implicit flow authorizationUrl value to the OAuth2 Security Scheme Environment variable: Show more |
string |
|
Add an implicit flow tokenUrl value to the OAuth2 Security Scheme Environment variable: Show more |
string |
|
Override the openapi version in the Schema document Environment variable: Show more |
string |
|
Set the title in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the version in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the description in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the terms of the service in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the contact email in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the contact name in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the contact url in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the license name in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the license url in Info tag in the Schema document Environment variable: Show more |
string |
|
Set the strategy to automatically create an operation Id. The strategy may be one of the predefined values or the name of a fully-qualified class that implements the Predefined strategies:
Environment variable: Show more |
string |
|
Set this boolean value to enable or disable the merging of the deprecated Environment variable: Show more |
boolean |
|
Profiles which explicitly include operations. If set, any operation without a matching profile is excluded. Environment variable: Show more |
文字列のリスト |
|
Profiles which explicitly exclude operations. If set, any operation without a matching profile is included. Excludes are considered before inclusions. Environment variable: Show more |
文字列のリスト |
|
Specify the list of servers that provide connectivity information Environment variable: Show more |
文字列のリスト |
|
This property is deprecated since Enable the openapi endpoint. By default it’s enabled. Environment variable: Show more |
boolean |
|
This property is deprecated since Do not run the filter only at startup, but every time the document is requested (dynamic). Environment variable: Show more |
boolean |
|
Swagger UI
ビルド時に固定される設定プロパティー - 他のすべての設定プロパティーは実行時に上書き可能です
Configuration property |
タイプ |
デフォルト |
|---|---|---|
The path where Swagger UI is available. The value Environment variable: Show more |
string |
|
If this should be included every time. By default, this is only included when the application is running in dev mode. Environment variable: Show more |
ブーリアン |
|
The urls that will be included as options. By default, the OpenAPI path will be used. Here you can override that and supply multiple urls that will appear in the TopBar plugin. Environment variable: Show more |
Map<String,String> |
|
If urls option is used, this will be the name of the default selection. Environment variable: Show more |
string |
|
The html title for the page. Environment variable: Show more |
string |
|
Swagger UI theme to be used. Environment variable: Show more |
|
|
A footer for the html page. Nothing by default. Environment variable: Show more |
string |
|
If set to true, enables deep linking for tags and operations. Environment variable: Show more |
ブーリアン |
|
Controls the display of operationId in operations list. The default is false. Environment variable: Show more |
ブーリアン |
|
The default expansion depth for models (set to -1 completely hide the models). Environment variable: Show more |
int |
|
The default expansion depth for the model on the model-example section. Environment variable: Show more |
int |
|
Controls how the model is shown when the API is first rendered. Environment variable: Show more |
string |
|
Controls the display of the request duration (in milliseconds) for "Try it out" requests. Environment variable: Show more |
ブーリアン |
|
Controls the default expansion setting for the operations and tags. Environment variable: Show more |
|
|
If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. Can be Boolean to enable or disable, or a string, in which case filtering will be enabled using that string as the filter expression. Filtering is case-sensitive matching the filter expression anywhere inside the tag. Environment variable: Show more |
string |
|
If set, limits the number of tagged operations displayed to at most this many. The default is to show all operations. Environment variable: Show more |
int |
|
Apply a sort to the operation list of each API. It can be 'alpha' (sort by paths alphanumerically), 'method' (sort by HTTP method) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server unchanged. Environment variable: Show more |
string |
|
Controls the display of vendor extension (x-) fields and values for Operations, Parameters, and Schema. Environment variable: Show more |
ブーリアン |
|
Controls the display of extensions (pattern, maxLength, minLength, maximum, minimum) fields and values for Parameters. Environment variable: Show more |
ブーリアン |
|
Apply a sort to the tag list of each API. It can be 'alpha' (sort by paths alphanumerically) or a function (see Array.prototype.sort() to learn how to write a sort function). Two tag name strings are passed to the sorter for each pass. Default is the order determined by Swagger UI. Environment variable: Show more |
string |
|
Provides a mechanism to be notified when Swagger UI has finished rendering a newly provided definition. Environment variable: Show more |
string |
|
Set to Environment variable: Show more |
string |
|
OAuth redirect URL. Environment variable: Show more |
string |
|
MUST be a function. Function to intercept remote definition, "Try it out", and OAuth 2.0 requests. Accepts one argument requestInterceptor(request) and must return the modified request, or a Promise that resolves to the modified request. Environment variable: Show more |
string |
|
If set, MUST be an array of command line options available to the curl command. This can be set on the mutated request in the requestInterceptor function. Environment variable: Show more |
文字列のリスト |
|
MUST be a function. Function to intercept remote definition, "Try it out", and OAuth 2.0 responses. Accepts one argument responseInterceptor(response) and must return the modified response, or a Promise that resolves to the modified response. Environment variable: Show more |
string |
|
If set to true, uses the mutated request returned from a requestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used. Environment variable: Show more |
ブーリアン |
|
List of HTTP methods that have the "Try it out" feature enabled. An empty array disables "Try it out" for all operations. This does not filter the operations from the display. Environment variable: Show more |
list of |
|
By default, Swagger UI attempts to validate specs against swagger.io’s online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). Setting it to either none, 127.0.0.1 or localhost will disable validation. Environment variable: Show more |
string |
|
If set to true, enables passing credentials, as defined in the Fetch standard, in CORS requests that are sent by the browser. Environment variable: Show more |
ブーリアン |
|
Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable Environment variable: Show more |
string |
|
Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable Environment variable: Show more |
string |
|
If set to true, it persists authorization data and it would not be lost on browser close/refresh Environment variable: Show more |
ブーリアン |
|
The name of a component available via the plugin system to use as the top-level layout for Swagger UI. Environment variable: Show more |
string |
|
A list of plugin functions to use in Swagger UI. Environment variable: Show more |
文字列のリスト |
|
A list of external scripts (usually plugins) to use in Swagger UI. Environment variable: Show more |
文字列のリスト |
|
A list of presets to use in Swagger UI. Environment variable: Show more |
文字列のリスト |
|
OAuth default clientId - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth default clientSecret - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth1 Realm query parameter added to authorizationUrl and tokenUrl - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth application name, displayed in authorization popup - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth scope separator for passing scopes - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth Scopes, separated using the oauthScopeSeparator - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth additional query parameters added to authorizationUrl and tokenUrl - Used in the initOAuth method. Environment variable: Show more |
string |
|
OAuth only activated for the accessCode flow. During the authorization_code request to the tokenUrl, pass the Client Password using the HTTP Basic Authentication scheme - Used in the initOAuth method. Environment variable: Show more |
ブーリアン |
|
OAuth only applies to authorization code flows. Proof Key for Code Exchange brings enhanced security for OAuth public clients - Used in the initOAuth method. Environment variable: Show more |
ブーリアン |
|
Pre-authorize Basic Auth, programmatically set DefinitionKey for a Basic authorization scheme - Used in the preauthorizeBasic method. Environment variable: Show more |
string |
|
Pre-authorize Basic Auth, programmatically set Username for a Basic authorization scheme - Used in the preauthorizeBasic method. Environment variable: Show more |
string |
|
Pre-authorize Basic Auth, programmatically set Password for a Basic authorization scheme - Used in the preauthorizeBasic method. Environment variable: Show more |
string |
|
Pre-authorize ApiKey Auth, programmatically set DefinitionKey for an API key or Bearer authorization scheme - Used in the preauthorizeApiKey method. Environment variable: Show more |
string |
|
Pre-authorize ApiKey Auth, programmatically set ApiKeyValue for an API key or Bearer authorization scheme - Used in the preauthorizeApiKey method. Environment variable: Show more |
string |
|
If set to true, this allows the user to modify and test different query parameters in the API request Environment variable: Show more |
ブーリアン |
|
If try it out should be enabled by default Environment variable: Show more |
ブーリアン |
|
If Swagger UI is included, it should be enabled/disabled. By default, Swagger UI is enabled if it is included (see Environment variable: Show more |
ブーリアン |
|
This property is deprecated since If Swagger UI is included, it should be enabled/disabled. By default, Swagger UI is enabled if it is included (see Environment variable: Show more |
ブーリアン |