> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJkNzYxZjRiYS1mYTE2LTQ0NWUtOWE3ZC0yNzFiMTNhOTY5ZmYiLCJleHAiOjE3NzgzMTAzNTYsImlhdCI6MTc3ODMxMDA1Nn0.KyqpWiq7F01D2bGwKnb_dpi8WU6gKFdx9rwHm9O7QVg
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 生成 WebSocket 参考文档

> 使用 Fern Docs 从 AsyncAPI 规范或 Fern Definition 生成 WebSocket 参考文档。

Fern 从 [AsyncAPI 规范](/learn/api-definitions/asyncapi/overview) 或 [Fern Definition](/learn/api-definitions/ferndef/websockets) 生成 WebSocket 参考文档。

<Frame caption={<a href="https://developers.deepgram.com/reference/text-to-speech/speak-streaming">WebSocket API 参考文档在 Fern 中的渲染示例</a>}>
  <img src="file:d38ed7b7-1762-4f64-a915-b664357bff7d" alt="WebSocket API Reference Example" />
</Frame>

## 配置

<Steps>
  <Step title="设置项目结构">
    对于 **AsyncAPI**：将规范文件添加到 `/fern` 目录中，并创建一个引用它的 `generators.yml`：

    ```yaml generators.yml
    api:
      path: asyncapi.yml
      origin: https://github.com/your-org/your-repo/blob/main/asyncapi.yml # 可选
    ```

    对于 **Fern Definition**：将 WebSocket 定义文件添加到 `definition/` 目录中（Fern 会自动检测）。
  </Step>

  <Step title="将 WebSocket 参考文档添加到导航">
    在 `docs.yml` 的导航中添加 `- api: API Reference`：

    ```yml docs.yml
    navigation:
      - api: API Reference
    ```
  </Step>

  <Step title="自定义布局">
    有关配置选项和布局自定义的完整列表，请参阅 [自定义 API 参考文档布局](/learn/docs/api-references/customize-api-reference-layout)。
  </Step>
</Steps>

### 包含多个 WebSocket 参考文档

要在文档中包含多个 WebSocket 定义，请使用 `api-name` 属性。`api-name` 对应包含 WebSocket 定义的文件夹名称。

<Files>
  <Folder name="fern" defaultOpen>
    <File name="fern.config.json" />

    <File name="docs.yml" />

    <Folder name="streaming-api" defaultOpen>
      <File name="asyncapi.yml" comment="流式 WebSocket AsyncAPI 规范" />

      <File name="generators.yml" />
    </Folder>

    <Folder name="realtime-api" defaultOpen>
      <File name="asyncapi.yml" comment="实时 WebSocket AsyncAPI 规范" />

      <File name="generators.yml" />
    </Folder>
  </Folder>
</Files>

```yaml title="docs.yml"
navigation:
  - api: Streaming API
    api-name: streaming-api
  - api: Realtime API
    api-name: realtime-api
```