「Test it」ボタンの設定
GitBook で「Test It」ボタンと付随するウィンドウは、いくつかの OpenAPI 拡張を使って設定できます。これらの拡張は、ユーザー向けのテスト機能を改善・設定するのに役立ちます。
「Test it」ボタンを非表示にする
エンドポイントから「Test it」ボタンを非表示にするには、次の x-hideTryItPanel をエンドポイントに、または OpenAPI 仕様のルートに追加します。
openapi: '3.0'
info: ...
tags: [...]
paths:
/example:
get:
summary: Example summary
description: Example description
operationId: examplePath
responses: [...]
parameters: [...]
x-hideTryItPanel: trueテストウィンドウで認証を有効にする
リクエストランナーは、仕様で宣言されている場合にのみ認証を表示・適用できます。認証スキームを 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: Production
- url: https://staging-api.example.com
description: Stagingservers:
- url: https://{instance}.api.{region}.example.cloud
variables:
instance:
default: acme
description: Your tenant or instance slug
region:
default: eu
enum:
- eu
- us
- ap
description: Regional deploymentpaths:
/reports:
get:
summary: Get reports
servers:
- url: https://reports.api.example.com
responses:
'200':
description: OK最終更新
役に立ちましたか?