# 拡張機能リファレンス

拡張機能を使用して OpenAPI 仕様を強化できます。拡張機能とは、次の文字で始まるカスタムフィールドです。 `x-` という接頭辞です。これらの拡張機能を使うと、追加情報を加えたり、さまざまなニーズに合わせて API ドキュメントを調整したりできます。

GitBook では、OpenAPI スペックに追加できるさまざまな拡張機能を通じて、公開サイト上で API の見た目や動作を調整できます。

こちらの [ガイドセクション](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/ja-gitbook-documentation/api-references/guides) へ進み、OpenAPI 拡張機能を使ってドキュメントを設定する方法の詳細をご覧ください。

<details>

<summary><code>x-page-title | x-displayName</code></summary>

ナビゲーションとページタイトルで使用されるタグの表示名を変更します。

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

```yaml
openapi: '3.0'
info: ...
tags:
  - name: users
    x-page-title: Users
```

{% endcode %}

</details>

<details>

<summary><code>x-page-description</code></summary>

ページに説明を追加します。

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

```yaml
openapi: '3.0'
info: ...
tags:
  - name: "users"
    x-page-title: "Users"
    x-page-description: "ユーザーアカウントとプロフィールを管理します。"
```

{% endcode %}

</details>

<details>

<summary><code>x-page-icon</code></summary>

ページに Font Awesome のアイコンを追加します。使用可能なアイコンを参照してください [を使用して特定のユーザーに一致させることができます。演算子の詳細については](https://fontawesome.com/search).

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

```yaml
openapi: '3.0'
info: ...
tags:
  - name: "users"
    x-page-title: "Users"
    x-page-description: "ユーザーアカウントとプロフィールを管理します。"
    x-page-icon: "user"
```

{% endcode %}

</details>

<details>

<summary><code>parent | x-parent</code></summary>

GitBook でページを整理するために、タグに階層構造を追加します。

{% hint style="warning" %}
`parent` は OpenAPI 3.2+ における正式なプロパティ名です。OpenAPI 3.2 より前のバージョン（3.0.x、3.1.x）を使用している場合は、 `x-parent` の使用を検討してください。
{% endhint %}

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

```yaml
openapi: '3.2'
info: ...
tags:
  - name: organization
  - name: admin
    parent: organization
  - name: user
    parent: organization    
```

{% endcode %}

</details>

<details>

<summary><code>x-hideTryItPanel</code></summary>

OpenAPI ブロックの「Test it」ボタンを表示または非表示にします。

{% 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 %}

</details>

<details>

<summary><code>x-enable-proxy</code></summary>

GitBook の OpenAPI プロキシを経由して「Test it」リクエストをルーティングします。

ルートに追加するとすべての操作に適用されます。操作に追加するとそのエンドポイントだけに適用されます。操作はルートの値を上書きします。

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

```yaml
openapi: '3.0.3'
info: ...

# すべての操作でプロキシを有効化
x-enable-proxy: true

paths:
  /health:
    get:
      summary: ヘルスチェック
      # 単一の操作を対象外にする
      x-enable-proxy: false
      responses:
        '200':
          description: OK
```

{% endcode %}

詳しくは [OpenAPI proxy の使用](https://app.gitbook.com/s/NkEGS7hzeqa35sMXQZ4X/api-references/guides/using-openapi-proxy).

</details>

<details>

<summary><code>x-codeSamples</code></summary>

OpenAPI ブロックのカスタムコードサンプルを表示、非表示、または含めます。

#### フィールド

<table><thead><tr><th width="103.625">フィールド名</th><th width="88.07421875" align="center">入力</th><th>説明</th></tr></thead><tbody><tr><td><code>lang</code></td><td align="center">string</td><td>コードサンプルの言語。値は次のいずれかである必要があります <a href="https://github.com/github/linguist/blob/master/lib/linguist/popular.yml">リスト</a></td></tr><tr><td><code>label</code></td><td align="center">string</td><td>コードサンプルのラベル。たとえば <code>Node</code> または <code>Python2.7</code>, <em>オプション</em>, <code>lang</code> がデフォルトで使用されます</td></tr><tr><td><code>source</code></td><td align="center">string</td><td>コードサンプルのソースコード</td></tr></tbody></table>

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

```yaml
openapi: '3.0'
info: ...
tags: [...]
paths:
  /example:
    get:
      summary: Example summary
      description: Example description
      operationId: examplePath
      responses: [...]
      parameters: [...]
      x-codeSamples:
        - lang: 'cURL'
          label: 'CLI'
          source: |
            curl -L \
            -H 'Authorization: Bearer <token>' \
            'https://api.gitbook.com/v1/user'
```

{% endcode %}

</details>

<details>

<summary><code>x-enumDescriptions</code></summary>

スキーマ内の各 `enum` 値に個別の説明を追加します。

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

```yaml
openapi: '3.0'
info: ...
components:
  schemas:
    project_status:
      type: string
      enum:
        - LIVE
        - PENDING
        - REJECTED
      x-enumDescriptions:
        LIVE: プロジェクトは公開中です。
        PENDING: プロジェクトは承認待ちです。
        REJECTED: プロジェクトは却下されました。
```

{% endcode %}

</details>

<details>

<summary><code>x-internal | x-gitbook-ignore</code></summary>

API リファレンスからエンドポイントを非表示にします。

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

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

{% endcode %}

</details>

<details>

<summary><code>x-stability</code></summary>

不安定または進行中のエンドポイントにマークを付けます。

サポートされる値: `experimental`, `alpha`, `beta`.

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

```yaml
openapi: '3.0'
info: ...
tags: [...]
paths:
  /example:
    get:
      summary: Example summary
      description: Example description
      operationId: examplePath
      x-stability: experimental
```

{% endcode %}

</details>

<details>

<summary><code>deprecated</code></summary>

エンドポイントが非推奨かどうかをマークします。非推奨のエンドポイントは、公開サイトで非推奨の警告を表示します。

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

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

{% endcode %}

</details>

<details>

<summary><code>x-deprecated-sunset</code></summary>

非推奨の操作にサンセット日を追加します。

サポートされる値: **ISO 8601** 形式 (YYYY-MM-DD)

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

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

{% endcode %}

</details>
