Skip to content

Commit ceb18bf

Browse files
authoredNov 29, 2023
fix: enum string escape can be nullable (#1081)
1 parent e1eff52 commit ceb18bf

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
 

‎packages/core/src/utils/string.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ export const getNumberWord = (num: number) => {
137137
return arrayOfNumber.reduce((acc, n) => acc + NUMBERS[n], '');
138138
};
139139

140-
export const escape = (str: string, char: string = "'") =>
141-
str.replace(char, `\\${char}`);
140+
export const escape = (str: string | null, char: string = "'") =>
141+
str?.replace(char, `\\${char}`);
142142

143143
/**
144144
* Escape all characters not included in SingleStringCharacters and

‎tests/configs/default.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default defineConfig({
6060
'null-type-v-3-0': {
6161
input: '../specifications/null-type-v3-0.yaml',
6262
output: {
63+
mock: true,
6364
schemas: '../generated/default/null-type-v3-0/model',
6465
target: '../generated/default/null-type-v3-0/endpoints.ts',
6566
},

‎tests/specifications/null-type-v3-0.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ paths:
4949
application/json:
5050
schema:
5151
$ref: '#/components/schemas/NullableAnyObject'
52+
/nullable-string-enum:
53+
get:
54+
tags:
55+
- nullables
56+
summary: Nullable string enums
57+
operationId: fetchNullableEnums
58+
responses:
59+
200:
60+
description: Successful Operation
61+
content:
62+
application/json:
63+
schema:
64+
$ref: '#/components/schemas/NullableStringEnum'
5265
components:
5366
schemas:
5467
ObjectWithNullableItems:

0 commit comments

Comments
 (0)
Please sign in to comment.