# 「テストする」ボタンの設定

GitBook では、いくつかの OpenAPI 拡張を使って「Test It」ボタンとそれに付随するウィンドウを設定できます。これらの拡張は、ユーザー向けのテストスイートの改善と設定に役立ちます。

### 「Test it」ボタンを非表示にする

エンドポイントに次のものを追加することで、エンドポイントから「Test it」ボタンを非表示にできます。 `x-hideTryItPanel` 、または OpenAPI スペックのルートに追加します。

{% code title="openapi.yaml" %}

```yaml
openapi: '3.0'
info: ...
tags: [...]
paths:
  /example:
    get:
      summary: Example summary
      description: Example description
      operationId: examplePath
      responses: [...]
      parameters: [...]
      x-hideTryItPanel: true
```

{% endcode %}

### 「Test it」リクエストをプロキシする

一部の API は、CORS が原因でブラウザからのリクエストをブロックします。

ルート **Test it** トラフィックを GitBook 経由でルーティングするには、次を追加します。 `x-enable-proxy` を spec に追加します。

参照 [OpenAPI プロキシの使用](/docs/documentation/ja-gitbook-documentation/api-references/guides/using-openapi-proxy.md) 例についてはこちら。

### テストウィンドウで認証を有効にする

リクエストランナーは、spec に認証が宣言されている場合にのみ、それを表示して適用できます。認証スキームを `components.securitySchemes`の下に定義し、その後 `security` を使ってグローバルに、または各オペレーションごとに関連付けます（グローバル設定を上書きします）。

#### 認証スキームを宣言する

以下に一般的なパターンを示します。YAML ではストレートクォートを使用してください。

{% tabs %}
{% tab title="HTTP Bearer（例: JWT）" %}

```yaml
openapi: '3.0.3'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
```

{% endtab %}

{% tab title="ヘッダー内の API キー" %}

```yaml
openapi: '3.0.3'
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
```

{% endtab %}

{% tab title="OAuth2（authorizationCode）" %}

```yaml
openapi: '3.0.3'
components:
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: 'https://auth.example.com/oauth/authorize'
          tokenUrl: 'https://auth.example.com/oauth/token'
          scopes:
            read:items: 'アイテムを読み取る'
            write:items: 'アイテムを書き込む'
```

{% endtab %}
{% endtabs %}

#### スキームをグローバルまたは各オペレーションごとに適用する

{% tabs %}
{% tab title="グローバル" %}

```yaml
openapi: '3.0.3'
security:
  - bearerAuth: []
paths: ...
```

{% endtab %}

{% tab title="オペレーションごと" %}

```yaml
paths:
  /reports:
    get:
      summary: レポートを取得する
      security:
        - apiKeyAuth: []
      responses:
        '200':
          description: OK
```

{% endtab %}
{% endtabs %}

### 次を使ってエンドポイント URL を制御する `servers`

リクエストランナーは、次の中で定義した URL に対して処理を行います。 `servers` 配列。1つ以上の server を定義できます。変数を使ってパラメータ化することもできます。

{% tabs %}
{% tab title="単一の server" %}

```yaml
openapi: '3.0.3'
servers:
  - url: https://instance.api.region.example.cloud
```

{% endtab %}

{% tab title="複数の server" %}

```yaml
servers:
  - url: https://api.example.com
    description: 本番環境
  - url: https://staging-api.example.com
    description: ステージング
```

{% endtab %}

{% tab title="server 変数" %}

```yaml
servers:
  - url: https://{instance}.api.{region}.example.cloud
    variables:
      instance:
        default: acme
        description: テナントまたはインスタンスのスラッグ
      region:
        default: eu
        enum:
          - eu
          - us
          - ap
        description: 地域展開
```

{% endtab %}

{% tab title="オペレーションごとの server" %}

<pre class="language-yaml"><code class="lang-yaml"><strong>paths:
</strong>  /reports:
    get:
      summary: レポートを取得する
      servers:
        - url: https://reports.api.example.com
      responses:
        '200':
          description: OK
</code></pre>

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/api-references/guides/configuring-the-test-it-button.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
