Skip to content

Commit

Permalink
fix: enum string escape can be nullable (orval-labs#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
dipsaus9 authored Nov 29, 2023
1 parent e1eff52 commit ceb18bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export const getNumberWord = (num: number) => {
return arrayOfNumber.reduce((acc, n) => acc + NUMBERS[n], '');
};

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

/**
* Escape all characters not included in SingleStringCharacters and
Expand Down
1 change: 1 addition & 0 deletions tests/configs/default.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default defineConfig({
'null-type-v-3-0': {
input: '../specifications/null-type-v3-0.yaml',
output: {
mock: true,
schemas: '../generated/default/null-type-v3-0/model',
target: '../generated/default/null-type-v3-0/endpoints.ts',
},
Expand Down
13 changes: 13 additions & 0 deletions tests/specifications/null-type-v3-0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/NullableAnyObject'
/nullable-string-enum:
get:
tags:
- nullables
summary: Nullable string enums
operationId: fetchNullableEnums
responses:
200:
description: Successful Operation
content:
application/json:
schema:
$ref: '#/components/schemas/NullableStringEnum'
components:
schemas:
ObjectWithNullableItems:
Expand Down

0 comments on commit ceb18bf

Please sign in to comment.