> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJhYmUxMDdlYy0wZjBiLTRlNzQtODNkZC1lNWNlZTA2ZWMzNDIiLCJleHAiOjE3Nzg0OTM2OTUsImlhdCI6MTc3ODQ5MzM5NX0.PLangdd7wL8G0QXPlmi2c_xNZ081m9B3mMA58lyXskc
>
> 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.

# Schema 代码片段

> 了解如何在 Fern 中使用 SchemaSnippet 组件在文档中将 API 类型定义显示为 JSON 代码块。

`<SchemaSnippet>` 组件将 API 参考中的类型定义显示为 JSON 代码块。您可以单独使用它来显示 JSON 表示，或将其与 [`<Schema>`](/learn/docs/writing-content/components/schema) 组件配对使用，同时显示逐字段分解和 JSON。

<Note>
  该组件仅发现由端点引用的类型。专门由 websocket 或 webhook 使用的类型将不可用。如果多个 API 具有相同的类型名称，该组件会返回第一个匹配项。
</Note>

## 用法

该组件与[已在 `docs.yml` 中配置的 API 参考](/learn/docs/api-references/overview)一起使用。此示例将 `AIChatConfig` 类型显示为 JSON 代码块：

<div>
  <div>
    <SchemaSnippet type="AIChatConfig" title="AIChatConfig 对象" />
  </div>
</div>

```jsx Markdown
<SchemaSnippet type="AIChatConfig" title="AIChatConfig 对象" />
```

## 与 Schema 组件结合使用

将 `<SchemaSnippet>` 与 `<Schema>` 一起使用，可同时显示 JSON 表示和详细的字段分解：

<div>
  <div>
    <SchemaSnippet type="AIChatConfig" title="AIChatConfig 对象" />

    <Schema type="AIChatConfig" />
  </div>
</div>

```jsx Markdown
<SchemaSnippet type="AIChatConfig" title="AIChatConfig 对象" />

<Schema type="AIChatConfig" />
```

## 属性

<ParamField path="type" type="string" required={true}>
  要显示的类型名称。该组件在您的 API 定义中的所有端点中搜索此类型。
</ParamField>

<ParamField path="title" type="string" required={false}>
  显示在 JSON 代码块上方的可选标题。
</ParamField>

<ParamField path="className" type="string" required={false}>
  用于自定义样式的可选 CSS 类名。
</ParamField>

<ParamField path="highlight" type="number | number[]" required={false}>
  要在代码片段中高亮显示的行号。接受单个数字、数字数组或范围（例如，`{[1-3, 5]}`）。
</ParamField>