> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI1MDIzYTkyOC1lMTE1LTRhZTgtYjA1ZS1hNDBkNmNmMzJlMmYiLCJleHAiOjE3Nzg0OTMxNzcsImlhdCI6MTc3ODQ5Mjg3N30.VgsuGxSwplE24gLHBwUIcFZEhQhGaYZ6xGrRjTH6TWM
>
> 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.

# 枚举描述、名称、大小写和可用性

> 使用 `x-fern-enum` 扩展为 OpenAPI 枚举值添加描述、自定义名称、按语言的大小写覆盖和弃用状态。

OpenAPI 原生不支持为枚举值添加描述。要在 Fern 中实现此功能，您可以使用 `x-fern-enum` 扩展。

## 描述和可用性

使用 `description` 为单个枚举值添加文档，使用 `deprecated` 将值标记为已弃用而不会弃用整个枚举。这些设置会传播到生成的 SDK 和文档网站中。

```yaml title="openapi.yml" {11, 13-14, 16, 18}
components:
  schemas:
    CardSuit:
      enum:
        - clubs
        - diamonds
        - hearts
        - spades
      x-fern-enum:
        clubs:
          description: 梅花花色
        diamonds:
          description: "已弃用。请使用红心。"
          deprecated: true
        hearts:
          description: 红心花色
        spades:
          description: 黑桃花色
```

## 自定义名称

使用 `name` 字段自定义生成代码中枚举值的名称。当枚举值依赖符号字符而可能导致生成的代码无法编译时，这特别有用。

例如，以下 OpenAPI：

```yaml title="openapi.yml" {9,12}
components:
  schemas:
    Operand:
      enum:
        - '>'
        - '<'
      x-fern-enum:
        '>':
          name: GreaterThan
          description: 检查值是否大于
        '<':
          name: LessThan
          description: 检查值是否小于
```

将生成：

```typescript title="operand.ts"
export enum Operand {
  GreaterThan = ">",
  LessThan = "<"
}
```

## 自定义大小写

使用 `casing` 字段为每个目标语言的命名约定指定确切的大小写。这比仅使用 `name` 提供了更精细的控制，后者只为生成的代码设置单个默认名称。

`casing` 字段支持四个可选的子字段：

* `snake` — snake\_case 的覆盖（用于 Python 等语言）
* `camel` — camelCase 的覆盖（用于 TypeScript/Java 等语言）
* `screamingSnake` — SCREAMING\_SNAKE\_CASE 的覆盖（用于 Go 等语言）
* `pascal` — PascalCase 的覆盖（用于 C# 等语言）

```yaml title="openapi.yml" {13-17}
components:
  schemas:
    Status:
      type: string
      enum:
        - active
        - in-progress
      x-fern-enum:
        active:
          description: 项目处于活动状态
        in-progress:
          name: InProgress
          casing:
            snake: in_progress
            camel: inProgress
            screamingSnake: IN_PROGRESS
            pascal: InProgress
```

您可以将 `casing` 与 `name` 一起使用。`name` 字段设置默认生成的名称，而 `casing` 提供按语言的覆盖。如果两者都指定，`casing` 值对其各自的语言目标具有优先级。