「テストする」ボタンの設定
GitBook では、いくつかの OpenAPI 拡張を使用して、「Test It」ボタンとそれに付随するウィンドウを設定できます。これらの拡張は、ユーザー向けのテストスイートの改善と設定に役立ちます。
「Test it」ボタンを非表示にする
エンドポイントに x-hideTryItPanel を追加するか、OpenAPI 仕様のルートに追加することで、エンドポイントから「Test it」ボタンを非表示にできます。
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
x-hideTryItPanel: true「Test it」リクエストをプロキシする
一部の API は、CORS が原因でブラウザからのリクエストをブロックします。
Route Test it のトラフィックを GitBook 経由でルーティングするには、 x-enable-proxy を仕様に追加します。
参照 OpenAPI proxy の使用 例をご覧ください。
テストウィンドウで認証を有効にする
リクエストランナーが認証を表示して適用できるのは、仕様でそれが宣言されている場合のみです。スキームを components.securitySchemesの下で定義し、次に security を使ってグローバルに、または操作ごとに(グローバル設定を上書き)紐付けます。
認証スキームを宣言する
以下は一般的なパターンです。YAML ではストレートクォートを使用してください。
openapi: '3.0.3'
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWTopenapi: '3.0.3'
components:
securitySchemes:
apiKeyAuth:
type: apiKey
in: header
name: X-API-Keyスキームをグローバルまたは操作ごとに適用する
openapi: '3.0.3'
security:
- bearerAuth: []
paths: ...paths:
/reports:
get:
summary: Get reports
security:
- apiKeyAuth: []
responses:
'200':
description: OKでエンドポイント URL を制御する servers
serversリクエストランナーは、 servers 配列で定義した URL をターゲットにします。1 つ以上のサーバーを宣言でき、変数でパラメータ化することもできます。
openapi: '3.0.3'
servers:
- url: https://instance.api.region.example.cloudservers:
- url: https://api.example.com
description: 本番環境
- url: https://staging-api.example.com
description: ステージングservers:
- url: https://{instance}.api.{region}.example.cloud
variables:
instance:
default: acme
description: テナントまたはインスタンスのスラッグ
region:
default: eu
enum:
- eu
- us
- ap
description: 地域別デプロイpaths:
/reports:
get:
summary: Get reports
servers:
- url: https://reports.api.example.com
responses:
'200':
description: OK最終更新
役に立ちましたか?