---
title: 字段
description: 使用 ParamField 和 ResponseField 组件记录 API 参数与响应字段，支持类型、默认值和嵌套对象。
---

> **For AI agents:** the complete documentation index is at [llms.txt](/docs/llms.txt). Append `.md` to any page URL for its markdown version.

字段可帮助你以清晰、一致的格式记录 API 参数和响应字段。

## 用法

```mdx
<ParamField query="limit" type="number" default={10}>
  Maximum number of results to return.
</ParamField>
```

## ParamField

使用 `ParamField` 记录 API 请求参数。使用 `body`、`query`、`path` 或 `header` 之一指定参数位置。

<ParamField body="user_id" type="string" required>
  用户的唯一标识符。
</ParamField>

<ParamField query="limit" type="number" default={10}>
  要返回的最大结果数。
</ParamField>

<ParamField header="Authorization" type="string" required>
  用于身份验证的 Bearer 令牌。
</ParamField>

```mdx
<ParamField body="user_id" type="string" required>
  The unique identifier for the user.
</ParamField>

<ParamField query="limit" type="number" default={10}>
  Maximum number of results to return.
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication.
</ParamField>
```

### 路径参数

<ParamField path="id" type="string" required>
  URL 路径中的资源标识符。
</ParamField>

```mdx
<ParamField path="id" type="string" required>
  Resource identifier in the URL path.
</ParamField>
```

### ParamField 属性

<ParamField name="body" type="string">
  body 参数的参数名称。
</ParamField>

<ParamField name="query" type="string">
  查询字符串参数的参数名称。
</ParamField>

<ParamField name="path" type="string">
  URL 路径参数的参数名称。
</ParamField>

<ParamField name="header" type="string">
  header 参数的参数名称。
</ParamField>

<ParamField name="type" type="string">
  数据类型（string、number、boolean、array、object）。
</ParamField>

<ParamField name="required" type="boolean">
  显示“required”标记。
</ParamField>

<ParamField name="default" type="string | number | boolean">
  未提供值时使用的默认值。
</ParamField>

## ResponseField

使用 `ResponseField` 记录 API 响应属性。

<ResponseField name="id" type="string" required>
  资源的唯一标识符。
</ResponseField>

<ResponseField name="created_at" type="string">
  资源创建时间的 ISO 8601 时间戳。
</ResponseField>

<ResponseField name="status" type="string" default="pending">
  请求的当前状态。
</ResponseField>

```mdx
<ResponseField name="id" type="string" required>
  Unique identifier for the resource.
</ResponseField>

<ResponseField name="created_at" type="string">
  ISO 8601 timestamp of when the resource was created.
</ResponseField>

<ResponseField name="status" type="string" default="pending">
  Current status of the request.
</ResponseField>
```

### 弃用字段

将字段标记为弃用，以表明它们将在未来版本中移除：

<ResponseField name="legacy_id" type="number" deprecated>
  请改用 `id`。此字段将在 v2 中移除。
</ResponseField>

```mdx
<ResponseField name="legacy_id" type="number" deprecated>
  Use `id` instead. This field will be removed in v2.
</ResponseField>
```

### 标签

使用 `pre` 和 `post` 标签添加上下文：

<ResponseField name="webhook_url" type="string" pre={["optional"]} post={["v2.1+"]}>
  用于接收 Webhook 通知的 URL。
</ResponseField>

```mdx
<ResponseField name="webhook_url" type="string" pre={["optional"]} post={["v2.1+"]}>
  URL to receive webhook notifications.
</ResponseField>
```

### 嵌套对象

结合 `Expandable` 记录嵌套对象属性：

<ResponseField name="user" type="object">
  创建资源的用户。
  <Expandable title="用户属性">
    <ResponseField name="id" type="string" required>
      用户的唯一标识符。
    </ResponseField>
    <ResponseField name="email" type="string" required>
      用户的电子邮件地址。
    </ResponseField>
    <ResponseField name="name" type="string">
      用户的显示名称。
    </ResponseField>
  </Expandable>
</ResponseField>

```mdx
<ResponseField name="user" type="object">
  The user who created the resource.
  <Expandable title="user properties">
    <ResponseField name="id" type="string" required>
      User's unique identifier.
    </ResponseField>
    <ResponseField name="email" type="string" required>
      User's email address.
    </ResponseField>
    <ResponseField name="name" type="string">
      User's display name.
    </ResponseField>
  </Expandable>
</ResponseField>
```

### ResponseField 属性

<ParamField name="name" type="string" required>
  字段名称。
</ParamField>

<ParamField name="type" type="string">
  数据类型。
</ParamField>

<ParamField name="required" type="boolean">
  显示“required”标记。
</ParamField>

<ParamField name="deprecated" type="boolean">
  以删除线标记字段为弃用。
</ParamField>

<ParamField name="default" type="string | number | boolean">
  默认值。
</ParamField>

<ParamField name="pre" type="string[]">
  显示在字段名称前的标签。
</ParamField>

<ParamField name="post" type="string[]">
  显示在字段名称后的标签。
</ParamField>

## 接下来做什么？

<Columns cols={2}>
  <Card title="组件概览" icon="puzzle-piece" href="/cn/components/overview">
    浏览所有可用组件
  </Card>
  <Card title="MDX 基础" icon="file-code" href="/cn/content/mdx-basics">
    了解如何在 MDX 中使用组件
  </Card>
</Columns>