> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI2ZWU3N2QyZi1iYmU0LTRhODUtOWRkYi01MGIwYmU5MzExY2IiLCJleHAiOjE3NzgyNjQxNzYsImlhdCI6MTc3ODI2Mzg3Nn0.0edfEot0cV9_H0MWtFUfLFw_2HIo0qBS7Pt4jPDQMo4
>
> 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

> 显示API参考中任何类型定义的组件

`<Schema>` 组件可以在您的文档中的任何位置显示API参考中的类型定义。使用它来在API参考页面之外引用数据模型、请求对象或响应类型。

与 [`<EndpointSchemaSnippet>`](/learn/docs/writing-content/components/endpoint-schema-snippet) 类似，但接受任何类型名称，而不仅限于端点特定的模式。可以与 [`<SchemaSnippet>`](/learn/docs/writing-content/components/schema-snippet) 配对使用，在字段分解旁边显示JSON表示。

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

## 使用方法

该组件与[已在您的 `docs.yml` 中配置的API参考](/learn/docs/api-references/overview)配合使用。此示例显示来自 `docs-yml` API的 `AIChatConfig` 类型：

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

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

### 过滤字段

使用 `include` 只显示特定字段，或使用 `exclude` 隐藏某些字段：

```jsx Markdown
{/* 只显示这两个字段 */}
<Schema type="AIChatConfig" include={["model", "provider"]} />

{/* 显示除这些字段之外的所有字段 */}
<Schema type="AIChatConfig" exclude={["model"]} />
```

## 属性

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

<ParamField path="api" type="string" required={false}>
  要从中获取类型的API名称。如果未指定，将从包含该类型的第一个API中获取类型。
</ParamField>

<ParamField path="description" type="boolean" required={false}>
  如果为 `true`，在模式字段上方包含类型定义的描述。这对于显示与类型关联的注释（如Protobuf消息注释）很有用。
</ParamField>

<ParamField path="include" type="string[]" required={false}>
  要包含在渲染模式中的字段名称列表。当指定时，只会显示列出的字段。这在您想要明确控制显示哪些字段时很有用，避免了每当底层类型获得新字段时需要更新 `exclude` 列表的情况。
</ParamField>

<ParamField path="exclude" type="string[]" required={false}>
  要从渲染模式中排除的字段名称列表。
</ParamField>

<ParamField path="excludeDeprecated" type="boolean" required={false}>
  如果为 `true`，从渲染模式中隐藏已弃用的字段。
</ParamField>

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