「Test it」ボタンの設定
GitBookではいくつかのOpenAPI拡張を使用して「Test It」ボタンと付随するウィンドウを構成できます。これらの拡張は、ユーザー向けのテストスイートの改善や構成に役立ちます。
「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「Test it」リクエストをプロキシする
一部のAPIはCORSなどの理由でブラウザからのリクエストをブロックします。
ルート Test it トラフィックをGitBook経由にするには、仕様に x-enable-proxy を追加します。
参照: Using 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リクエストランナーは、配列で定義したURLをターゲットにします。1つ以上のサーバーを宣言できます。変数でパラメータ化することも可能です。 servers 配列。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最終更新
役に立ちましたか?