Skip to content

Commit 6a98b82

Browse files
committed
fix(enums): x-enumNames specified integers and description with new lines
Signed-off-by: Vojtech Mašek <[email protected]>
1 parent 943f7d2 commit 6a98b82

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ function defineEnum(
309309
enumSchema &&
310310
enumSchema.map((val, index) => ({
311311
name: (isNumeric
312-
? descKeys
313-
? descKeys[val.toString()]
312+
? xEnumNames.length === 0 && descKeys
313+
? descKeys[val.toString()] || ''
314314
: xEnumNames[index] || `${val}`
315315
: val.toString()
316316
).replace(/[\W\s]+/, '_'),

tests/custom/swagger.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,31 @@ paths:
7979
responses:
8080
200:
8181
description: OK
82+
# # an example of overriding parameter from RAWG API
83+
# '/games/{id}':
84+
# get:
85+
# description: ''
86+
# operationId: games_read
87+
# parameters:
88+
# - description: An ID or a slug identifying this Game.
89+
# in: path
90+
# name: id
91+
# required: true
92+
# type: string
93+
# responses:
94+
# '200':
95+
# description: ''
96+
# schema:
97+
# $ref: '#/definitions/Pet'
98+
# summary: Get details of the game.
99+
# tags:
100+
# - games
101+
# parameters:
102+
# - description: A unique integer value identifying this Game.
103+
# in: path
104+
# name: id
105+
# required: true
106+
# type: integer
82107
# patch:
83108
# requestBody:
84109
# content:

tests/with-all-tags/api/models/status-severity.enum.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/* tslint:disable */
22

3+
/**
4+
* Description text on multiple lines without any value.
5+
* This is a test to make sure x-enumNames will be parsed properly when provided.
6+
*/
37
export enum StatusSeverity {
48
Unknown = 0,
59
OK = 1,

tests/with-all-tags/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
},
338338
"StatusSeverity": {
339339
"type": "integer",
340-
"description": "",
340+
"description": "Description text on multiple lines without any value.\nThis is a test to make sure x-enumNames will be parsed properly when provided.",
341341
"x-enumNames": ["Unknown", "OK", "Warning", "Error", "Critical"],
342342
"enum": [0, 1, 2, 3, 4]
343343
},

0 commit comments

Comments
 (0)