> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI2MGIyZGE0Yi1hNGNlLTRkM2YtOGNkMy01ZjdmZDE0NDg4ZjMiLCJleHAiOjE3ODA2MjQ0NzUsImlhdCI6MTc4MDYyNDE3NX0.AMnbgCgERlRvJOKXN2rnvwxbWEEEr-e_ZfONaeD6GQc
>
> 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.

# Fern Definition 中的包

> Fern Definition 支持跨包重用 API 类型和错误名称，并可以配置 API 文档的结构。

## 什么是包？

API 定义中的每个文件夹都是一个包。

生成的 SDK 将匹配你的 API 定义的层次结构。

```ts
const client = new Client();

// 调用在 projects.yml 中定义的端点
client.projects.get();

// 调用在 roles/admin.yml 中定义的端点
client.roles.admin.get();
```

## 包配置

每个包可以有一个名为 `__package__.yml` 的特殊定义文件。与任何其他定义文件一样，它可以包含[导入](/learn/api-definitions/ferndef/imports)、[类型](/learn/api-definitions/ferndef/types)、[端点](/learn/api-definitions/ferndef/endpoints/overview)和[错误](/learn/api-definitions/ferndef/errors)。

`__package__.yml` 中的端点将出现在包的根目录。
例如，以下生成的 SDK：

```ts
const client = new Client();

client.getProjects();
```

将有一个 `fern/` 文件夹：

其中包含以下 `__package__.yml`：

```yaml
service:
  base-path: ""
  auth: false
  endpoints:
    getProjects:
      method: GET
      path: ""
      response: list<Project>
```

## 命名空间

每个包都有自己的命名空间。这意味着你可以在不同包中重用类型名称和错误名称。

这在对 API 进行版本控制时很有用。例如，当你想要增加 API 版本时，可以将现有 API 复制到新包中并开始进行更改。如果新的 API 版本重用了某些类型或错误，这是可以的，因为两个 API 存在于不同的包中。

## 导航

`__package__.yml` 还允许你配置服务的导航顺序。当你想要控制文档的显示时，这很有用。

例如，假设你有以下 `fern/` 文件夹：

你的 API 将按字母顺序排序：projects、roles，然后是 users。如果你想要控制导航，可以添加一个 `__package__.yml` 文件并配置顺序：

```yaml
navigation: 
  - users.yml
  - roles.yml
  - projects.yml
```