Skip to content

Commit d05c29e

Browse files
committed
Sync open source content 🐝 (from 3f48a621faa48868bd80438b763cb07f71a84bef)
1 parent 041d375 commit d05c29e

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

β€Ždocs/sdks/customize/data-model/enums.mdxβ€Ž

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,44 @@ schema:
6767
- COMPLETE
6868
```
6969

70+
## Preserve custom enum names in TypeScript
71+
72+
When `x-speakeasy-enums` provides custom names, the TypeScript generator applies PascalCase transformation by default. This can mangle names where casing carries meaning. For example, `X86_64` becomes `X8664` because the transformation strips underscores and collapses digits.
73+
74+
To preserve custom enum names exactly as written, enable the [`fixEnumNameSanitization`](/docs/speakeasy-reference/generation/ts-config#error-and-response-handling) option in `gen.yaml`:
75+
76+
```yaml
77+
typescript:
78+
fixEnumNameSanitization: true
79+
```
80+
81+
With this option enabled, custom names provided via `x-speakeasy-enums` are kept as-is, with only illegal character sanitization applied. No PascalCase or other casing transformations are performed.
82+
83+
For example, given the following OpenAPI schema and `gen.yaml` configuration:
84+
85+
```yaml
86+
# gen.yaml
87+
typescript:
88+
fixEnumNameSanitization: true
89+
```
90+
91+
```yaml
92+
# OpenAPI spec
93+
ImageArchitecture:
94+
enum: ["x86_64", "arm64"]
95+
type: string
96+
x-speakeasy-enums:
97+
x86_64: X86_64
98+
```
99+
100+
The generated enum member is `X86_64` instead of `X8664`.
101+
102+
<Callout title="Note" type="info">
103+
The `fixEnumNameSanitization` option is currently available for TypeScript only (including `mcp-typescript`). It applies exclusively to enums with `x-speakeasy-enums` overrides β€” enums without custom names are unaffected.
104+
</Callout>
105+
106+
Because this option skips all casing transformations for custom names, names are used exactly as provided. For example, a custom name like `under_review` remains `under_review` in the generated output rather than being converted to `UnderReview`.
107+
70108
## Enum class naming
71109

72110
Use the `x-speakeasy-name-override` attribute to customize enum class names:

β€Ždocs/speakeasy-reference/generation/ts-config.mdxβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ typescript:
278278
clientServerStatusCodesAsErrors: true
279279
responseFormat: "flat"
280280
enumFormat: "union"
281+
fixEnumNameSanitization: false
281282
defaultErrorName: "SDKError"
282283
baseErrorName: "HTTPError"
283284
acceptHeaderEnum: false
@@ -287,6 +288,7 @@ typescript:
287288
data={[
288289
{ property: "[responseFormat](/docs/sdks/customize/responses/responses)", description: "Defines how responses are structured. Options: `envelope`, `envelope-http`, or `flat`.", type: "string", default: "flat" },
289290
{ property: "enumFormat", description: "Determines how enums are generated. Options: `enum` (TypeScript enums) or `union` (union types).", type: "string", default: "union" },
291+
{ property: "[fixEnumNameSanitization](/docs/customize-sdks/enums#preserve-custom-enum-names-in-typescript)", description: "When `true`, custom enum names provided via `x-speakeasy-enums` are preserved exactly as written, with only illegal character sanitization applied. No PascalCase or other casing transformations are performed. Only affects enums with `x-speakeasy-enums` overrides.", type: "boolean", default: "false" },
290292
{ property: "clientServerStatusCodesAsErrors", description: "Treats `4XX` and `5XX` status codes as errors. Set to `false` to treat them as normal responses.", type: "boolean", default: "true" },
291293
{ property: "defaultErrorName", description: "The name of the fallback error class if no more specific error class is matched. Must start with a capital letter and contain only letters and numbers.", type: "string", default: "SDKError" },
292294
{ property: "baseErrorName", description: "The name of the base error class used for HTTP error responses. Must start with a capital letter and contain only letters and numbers.", type: "string", default: "HTTPError" },

0 commit comments

Comments
Β (0)