You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/guides/enums.mdx
+29-4Lines changed: 29 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
---
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
4
4
---
5
5
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.
7
7
8
8
## OpenAPI Schema
9
9
10
+
Use `x-enumNames` to assign meaningful names to enum members, and `x-enumDescriptions` to add JSDoc comments that appear in IDE tooltips.
11
+
10
12
```yaml
11
13
openapi: '3.1.0'
12
14
info:
@@ -29,23 +31,46 @@ components:
29
31
- Two
30
32
- Three
31
33
- Four
34
+
x-enumDescriptions:
35
+
- Represents the first value
36
+
- Represents the second value
37
+
- Represents the third value
38
+
- Represents the fourth value
32
39
```
33
40
34
41
## Generated Output
35
42
36
43
```ts
37
44
export const MyEnum = {
45
+
/** Represents the first value */
38
46
One: 1,
47
+
/** Represents the second value */
39
48
Two: 2,
49
+
/** Represents the third value */
40
50
Three: 3,
51
+
/** Represents the fourth value */
41
52
Four: 4,
42
53
} as const;
54
+
55
+
export type MyEnum = typeof MyEnum[keyof typeof MyEnum];
43
56
```
44
57
45
58
## Supported Extensions
46
59
47
-
Orval recognizes these extensions for enum names:
60
+
Orval recognizes the following extensions:
61
+
62
+
**Enum names:**
48
63
49
64
-`x-enumNames`
50
65
-`x-enumnames`
51
66
-`x-enum-varnames`
67
+
68
+
**Enum descriptions:**
69
+
70
+
-`x-enumDescriptions`
71
+
-`x-enumdescriptions`
72
+
-`x-enum-descriptions`
73
+
74
+
<Callouttype="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`.
0 commit comments