> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiIxZjU0NjkyMS02OWVjLTQxNTgtYTRmOS0yMDdhYjRkNjk4NGYiLCJleHAiOjE3Nzg0ODg3MTUsImlhdCI6MTc3ODQ4ODQxNX0.sd1kb0zjOV6TPiaF3nBvacb-BPXZwna1Dwga1AKjFBI
>
> 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.

# 什么是 AsyncAPI 规范？

> AsyncAPI 是用于文档化事件驱动 API 的标准

<Note>
  Fern 支持为 TypeScript、Python、Java 和 C# 生成 AsyncAPI SDK。[提交 issue](https://github.com/fern-api/fern/issues) 来请求支持其他语言。
</Note>

AsyncAPI 规范是开发人员用来文档化事件驱动 API 的框架。该规范使用 JSON 或 YAML 编写，包含您的所有通道、消息、模式和身份验证方案。Fern 与 AsyncAPI 规范 [v2.6.0](https://www.asyncapi.com/docs/reference/specification/v2.6.0) 和 [v3.0.0](https://www.asyncapi.com/docs/reference/specification/v3.0.0) 兼容。

以下是一个 AsyncAPI 文件的示例：

```yaml asyncapi.yml 
asyncapi: 3.0.0
info:
  title: User Notification Service
  version: 1.0.0
  description: |
    Service that handles user notifications through various channels
    including email, SMS, and push notifications.
channels:
  user/signup:
    address: user/signup
    messages:
      UserSignedUp:
        $ref: '#/components/messages/UserSignedUp'
  notification/send:
    address: notification/send
    messages:
      SendNotification:
        $ref: '#/components/messages/SendNotification'
operations:
  onUserSignup:
    action: receive
    channel:
      $ref: '#/channels/user~1signup'
    summary: User signup event
    description: Triggered when a user signs up for the service
  sendNotification:
    action: send
    channel:
      $ref: '#/channels/notification~1send'
    summary: Send notification
    description: Send a notification to a user
components:
  messages:
    UserSignedUp:
      name: UserSignedUp
      title: User Signed Up
      summary: User has signed up for the service
      contentType: application/json
      payload:
        $ref: '#/components/schemas/User'
    SendNotification:
      name: SendNotification
      title: Send Notification
      summary: Send a notification to a user
      contentType: application/json
      payload:
        $ref: '#/components/schemas/Notification'
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier for the user
        email:
          type: string
          format: email
          description: User's email address
        name:
          type: string
          description: User's full name
        createdAt:
          type: string
          format: date-time
          description: When the user was created
      required:
        - id
        - email
        - name
    Notification:
      type: object
      properties:
        userId:
          type: string
          format: uuid
          description: ID of the user to notify
        type:
          type: string
          enum: [email, sms, push]
          description: Type of notification to send
        message:
          type: string
          description: Message content
        priority:
          type: string
          enum: [low, medium, high, urgent]
          default: medium
          description: Priority level of the notification
      required:
        - userId
        - type
        - message
```

## 设置您的 fern 文件夹

<Info>
  正在考虑生成 AsyncAPI 规范的选项？在[这里](https://fern-community.slack.com/join/shared_invite/zt-2dpftfmif-MuAegl8AfP_PK8s2tx350Q%EF%BB%BF#/shared-invite/email)获得实时支持
</Info>

<Steps>
  <Step title="创建您的 fern 目录">
    在您的项目根目录中创建一个 `fern/` 文件夹。

    <Files>
      <Folder name="fern" />
    </Files>
  </Step>

  <Step title="添加您的 AsyncAPI 规范">
    将您的 AsyncAPI 规范添加到 fern 目录中。您可以将其放在名为 `asyncapi` 的子文件夹中，或直接放在 fern 目录中。

    <Files>
      <Folder name="fern" defaultOpen>
        <Folder name="asyncapi" defaultOpen>
          <File name="asyncapi.yml" />
        </Folder>
      </Folder>
    </Files>
  </Step>

  <Step title="创建 `fern.config.json` 文件">
    在您的 fern 目录中添加一个 `fern.config.json` 文件，其中列出您的组织和当前版本的 Fern CLI：

    ```json title="fern.config.json"
    {
        "organization": "your-organization",
        "version": "5.7.5"
    }
    ```

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

        <Folder name="asyncapi" defaultOpen>
          <File name="asyncapi.yml" />
        </Folder>
      </Folder>
    </Files>
  </Step>

  <Step title="创建 `generators.yml` 文件">
    在您的 fern 目录中创建一个 `generators.yml` 文件，并添加对您的 AsyncAPI 规范的引用：

    ```yaml title="generators.yml"
    # Your API definition
    api: 
      specs: 
        - asyncapi: ./asyncapi/asyncapi.yml

    groups:
      external:
        generators:
          # Your generator configurations here
    ```

    您的最终目录结构：

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

        <File name="generators.yml" />

        <Folder name="asyncapi" defaultOpen>
          <File name="asyncapi.yml" />
        </Folder>
      </Folder>
    </Files>
  </Step>
</Steps>