From e263cb27f6d9ff6e21f6dff260ee0188fffc00d0 Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Fri, 26 Nov 2021 15:51:14 -0500 Subject: [PATCH] - Fixed #892 --- src/openApi/v3/parser/getModel.ts | 2 +- test/__snapshots__/index.spec.js.snap | 19 ++++++++++++++++--- test/spec/v2.json | 17 +++++++++++++++++ test/spec/v3.json | 21 +++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/openApi/v3/parser/getModel.ts b/src/openApi/v3/parser/getModel.ts index b9075a24..30efcfac 100644 --- a/src/openApi/v3/parser/getModel.ts +++ b/src/openApi/v3/parser/getModel.ts @@ -185,7 +185,7 @@ export function getModel( model.type = definitionType.type; model.base = definitionType.base; model.template = definitionType.template; - model.isNullable = definitionType.isNullable; + model.isNullable = definitionType.isNullable || model.isNullable; model.imports.push(...definitionType.imports); model.default = getModelDefault(definition, model); return model; diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 72c2313c..c5354d43 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -2100,6 +2100,8 @@ export class DefaultsService { * @param parameterOptionalStringWithNoDefault This is a optional string with no default * @param parameterStringWithDefault This is a string with default * @param parameterStringWithEmptyDefault This is a string with empty default + * @param parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ public static callToTestOrderOfParams( @@ -2109,6 +2111,8 @@ export class DefaultsService { parameterOptionalStringWithNoDefault?: string, parameterStringWithDefault: string = 'Hello World!', parameterStringWithEmptyDefault: string = '', + parameterStringNullableWithNoDefault?: string | null, + parameterStringNullableWithDefault: string | null = null, ): CancelablePromise { return __request({ method: 'PUT', @@ -2120,6 +2124,8 @@ export class DefaultsService { 'parameterStringWithDefault': parameterStringWithDefault, 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterStringNullableWithNoDefault': parameterStringNullableWithNoDefault, + 'parameterStringNullableWithDefault': parameterStringNullableWithDefault, }, }); } @@ -4095,7 +4101,7 @@ exports[`v3 should generate: ./test/generated/v3/models/SimpleStringWithPattern. /** * This is a simple string */ -export type SimpleStringWithPattern = string;" +export type SimpleStringWithPattern = string | null;" `; exports[`v3 should generate: ./test/generated/v3/schemas/$ArrayWithArray.ts 1`] = ` @@ -4984,6 +4990,7 @@ exports[`v3 should generate: ./test/generated/v3/schemas/$SimpleStringWithPatter /* eslint-disable */ export const $SimpleStringWithPattern = { type: 'string', + isNullable: true, maxLength: 64, pattern: '^[a-zA-Z0-9_]*$', } as const;" @@ -5185,6 +5192,8 @@ export class DefaultsService { * @param parameterOptionalStringWithNoDefault This is a optional string with no default * @param parameterStringWithDefault This is a string with default * @param parameterStringWithEmptyDefault This is a string with empty default + * @param parameterStringNullableWithNoDefault This is a string that can be null with no default + * @param parameterStringNullableWithDefault This is a string that can be null with default * @throws ApiError */ public static callToTestOrderOfParams( @@ -5194,6 +5203,8 @@ export class DefaultsService { parameterOptionalStringWithNoDefault?: string, parameterStringWithDefault: string = 'Hello World!', parameterStringWithEmptyDefault: string = '', + parameterStringNullableWithNoDefault?: string | null, + parameterStringNullableWithDefault: string | null = null, ): CancelablePromise { return __request({ method: 'PUT', @@ -5205,6 +5216,8 @@ export class DefaultsService { 'parameterStringWithDefault': parameterStringWithDefault, 'parameterStringWithEmptyDefault': parameterStringWithEmptyDefault, 'parameterStringWithNoDefault': parameterStringWithNoDefault, + 'parameterStringNullableWithNoDefault': parameterStringNullableWithNoDefault, + 'parameterStringNullableWithDefault': parameterStringNullableWithDefault, }, }); } @@ -5879,8 +5892,8 @@ export class TypesService { parameterDictionary: any, parameterEnum: 'Success' | 'Warning' | 'Error' | null, parameterNumber: number = 123, - parameterString: string = 'default', - parameterBoolean: boolean = true, + parameterString: string | null = 'default', + parameterBoolean: boolean | null = true, parameterObject: any = null, id?: number, ): CancelablePromise { diff --git a/test/spec/v2.json b/test/spec/v2.json index 7bb5d3d3..6cf4a73f 100644 --- a/test/spec/v2.json +++ b/test/spec/v2.json @@ -340,6 +340,23 @@ "in": "query", "required": true, "type": "string" + }, + { + "x-nullable": true, + "description": "This is a string that can be null with no default", + "name": "parameterStringNullableWithNoDefault", + "in": "query", + "required": false, + "type": "string" + }, + { + "x-nullable": true, + "description": "This is a string that can be null with default", + "name": "parameterStringNullableWithDefault", + "in": "query", + "required": false, + "type": "string", + "default": null } ] } diff --git a/test/spec/v3.json b/test/spec/v3.json index 26ff8ec3..892687f8 100644 --- a/test/spec/v3.json +++ b/test/spec/v3.json @@ -525,6 +525,27 @@ "schema": { "type": "string" } + }, + { + "description": "This is a string that can be null with no default", + "name": "parameterStringNullableWithNoDefault", + "in": "query", + "required": false, + "schema": { + "type": "string", + "nullable": true + } + }, + { + "description": "This is a string that can be null with default", + "name": "parameterStringNullableWithDefault", + "in": "query", + "required": false, + "schema": { + "type": "string", + "nullable": true, + "default": null + } } ] }