Skip to content

Commit e263cb2

Browse files
committed
1 parent 6d822eb commit e263cb2

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

src/openApi/v3/parser/getModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function getModel(
185185
model.type = definitionType.type;
186186
model.base = definitionType.base;
187187
model.template = definitionType.template;
188-
model.isNullable = definitionType.isNullable;
188+
model.isNullable = definitionType.isNullable || model.isNullable;
189189
model.imports.push(...definitionType.imports);
190190
model.default = getModelDefault(definition, model);
191191
return model;

test/__snapshots__/index.spec.js.snap

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,6 +2100,8 @@ export class DefaultsService {
21002100
* @param parameterOptionalStringWithNoDefault This is a optional string with no default
21012101
* @param parameterStringWithDefault This is a string with default
21022102
* @param parameterStringWithEmptyDefault This is a string with empty default
2103+
* @param parameterStringNullableWithNoDefault This is a string that can be null with no default
2104+
* @param parameterStringNullableWithDefault This is a string that can be null with default
21032105
* @throws ApiError
21042106
*/
21052107
public static callToTestOrderOfParams(
@@ -2109,6 +2111,8 @@ export class DefaultsService {
21092111
parameterOptionalStringWithNoDefault?: string,
21102112
parameterStringWithDefault: string = 'Hello World!',
21112113
parameterStringWithEmptyDefault: string = '',
2114+
parameterStringNullableWithNoDefault?: string | null,
2115+
parameterStringNullableWithDefault: string | null = null,
21122116
): CancelablePromise<void> {
21132117
return __request({
21142118
method: 'PUT',
@@ -2120,6 +2124,8 @@ export class DefaultsService {
21202124
'parameterStringWithDefault': parameterStringWithDefault,
21212125
'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault,
21222126
'parameterStringWithNoDefault': parameterStringWithNoDefault,
2127+
'parameterStringNullableWithNoDefault': parameterStringNullableWithNoDefault,
2128+
'parameterStringNullableWithDefault': parameterStringNullableWithDefault,
21232129
},
21242130
});
21252131
}
@@ -4095,7 +4101,7 @@ exports[`v3 should generate: ./test/generated/v3/models/SimpleStringWithPattern.
40954101
/**
40964102
* This is a simple string
40974103
*/
4098-
export type SimpleStringWithPattern = string;"
4104+
export type SimpleStringWithPattern = string | null;"
40994105
`;
41004106

41014107
exports[`v3 should generate: ./test/generated/v3/schemas/$ArrayWithArray.ts 1`] = `
@@ -4984,6 +4990,7 @@ exports[`v3 should generate: ./test/generated/v3/schemas/$SimpleStringWithPatter
49844990
/* eslint-disable */
49854991
export const $SimpleStringWithPattern = {
49864992
type: 'string',
4993+
isNullable: true,
49874994
maxLength: 64,
49884995
pattern: '^[a-zA-Z0-9_]*$',
49894996
} as const;"
@@ -5185,6 +5192,8 @@ export class DefaultsService {
51855192
* @param parameterOptionalStringWithNoDefault This is a optional string with no default
51865193
* @param parameterStringWithDefault This is a string with default
51875194
* @param parameterStringWithEmptyDefault This is a string with empty default
5195+
* @param parameterStringNullableWithNoDefault This is a string that can be null with no default
5196+
* @param parameterStringNullableWithDefault This is a string that can be null with default
51885197
* @throws ApiError
51895198
*/
51905199
public static callToTestOrderOfParams(
@@ -5194,6 +5203,8 @@ export class DefaultsService {
51945203
parameterOptionalStringWithNoDefault?: string,
51955204
parameterStringWithDefault: string = 'Hello World!',
51965205
parameterStringWithEmptyDefault: string = '',
5206+
parameterStringNullableWithNoDefault?: string | null,
5207+
parameterStringNullableWithDefault: string | null = null,
51975208
): CancelablePromise<void> {
51985209
return __request({
51995210
method: 'PUT',
@@ -5205,6 +5216,8 @@ export class DefaultsService {
52055216
'parameterStringWithDefault': parameterStringWithDefault,
52065217
'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault,
52075218
'parameterStringWithNoDefault': parameterStringWithNoDefault,
5219+
'parameterStringNullableWithNoDefault': parameterStringNullableWithNoDefault,
5220+
'parameterStringNullableWithDefault': parameterStringNullableWithDefault,
52085221
},
52095222
});
52105223
}
@@ -5879,8 +5892,8 @@ export class TypesService {
58795892
parameterDictionary: any,
58805893
parameterEnum: 'Success' | 'Warning' | 'Error' | null,
58815894
parameterNumber: number = 123,
5882-
parameterString: string = 'default',
5883-
parameterBoolean: boolean = true,
5895+
parameterString: string | null = 'default',
5896+
parameterBoolean: boolean | null = true,
58845897
parameterObject: any = null,
58855898
id?: number,
58865899
): CancelablePromise<number | string | boolean | any> {

test/spec/v2.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,23 @@
340340
"in": "query",
341341
"required": true,
342342
"type": "string"
343+
},
344+
{
345+
"x-nullable": true,
346+
"description": "This is a string that can be null with no default",
347+
"name": "parameterStringNullableWithNoDefault",
348+
"in": "query",
349+
"required": false,
350+
"type": "string"
351+
},
352+
{
353+
"x-nullable": true,
354+
"description": "This is a string that can be null with default",
355+
"name": "parameterStringNullableWithDefault",
356+
"in": "query",
357+
"required": false,
358+
"type": "string",
359+
"default": null
343360
}
344361
]
345362
}

test/spec/v3.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,27 @@
525525
"schema": {
526526
"type": "string"
527527
}
528+
},
529+
{
530+
"description": "This is a string that can be null with no default",
531+
"name": "parameterStringNullableWithNoDefault",
532+
"in": "query",
533+
"required": false,
534+
"schema": {
535+
"type": "string",
536+
"nullable": true
537+
}
538+
},
539+
{
540+
"description": "This is a string that can be null with default",
541+
"name": "parameterStringNullableWithDefault",
542+
"in": "query",
543+
"required": false,
544+
"schema": {
545+
"type": "string",
546+
"nullable": true,
547+
"default": null
548+
}
528549
}
529550
]
530551
}

0 commit comments

Comments
 (0)