Skip to content

Commit 3c66608

Browse files
ashphymelloware
andauthored
docs: add x-enum-descriptions documentation to enums guide (#2968)
* docs: add x-enum-descriptions documentation to enums guide * Add type export for MyEnum in enums guide --------- Co-authored-by: Melloware <mellowaredev@gmail.com>
1 parent 6a67a50 commit 3c66608

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

docs/content/docs/guides/enums.mdx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
2-
title: Enum Names
3-
description: Generate named enums from OpenAPI extensions
2+
title: Enum Extensions
3+
description: Generate enums with custom names and descriptions from OpenAPI extensions
44
---
55

6-
Use OpenAPI extensions to generate enums with meaningful names instead of numeric values.
6+
Use OpenAPI extensions to generate enums with meaningful names and descriptions.
77

88
## OpenAPI Schema
99

10+
Use `x-enumNames` to assign meaningful names to enum members, and `x-enumDescriptions` to add JSDoc comments that appear in IDE tooltips.
11+
1012
```yaml
1113
openapi: '3.1.0'
1214
info:
@@ -29,23 +31,46 @@ components:
2931
- Two
3032
- Three
3133
- Four
34+
x-enumDescriptions:
35+
- Represents the first value
36+
- Represents the second value
37+
- Represents the third value
38+
- Represents the fourth value
3239
```
3340
3441
## Generated Output
3542
3643
```ts
3744
export const MyEnum = {
45+
/** Represents the first value */
3846
One: 1,
47+
/** Represents the second value */
3948
Two: 2,
49+
/** Represents the third value */
4050
Three: 3,
51+
/** Represents the fourth value */
4152
Four: 4,
4253
} as const;
54+
55+
export type MyEnum = typeof MyEnum[keyof typeof MyEnum];
4356
```
4457

4558
## Supported Extensions
4659

47-
Orval recognizes these extensions for enum names:
60+
Orval recognizes the following extensions:
61+
62+
**Enum names:**
4863

4964
- `x-enumNames`
5065
- `x-enumnames`
5166
- `x-enum-varnames`
67+
68+
**Enum descriptions:**
69+
70+
- `x-enumDescriptions`
71+
- `x-enumdescriptions`
72+
- `x-enum-descriptions`
73+
74+
<Callout type="info">
75+
Enum descriptions are only supported when [`enumGenerationType`](/docs/reference/configuration/output#enumgenerationtype) is set to `const` (default). They are not applied when using `enum` or `union`.
76+
</Callout>

0 commit comments

Comments
 (0)