From 0bc979ebdc5a757504ab9d43dd27968538f45712 Mon Sep 17 00:00:00 2001 From: swcm-mnestler <88091858+swcm-mnestler@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:16:29 +0100 Subject: [PATCH] [typescript-nestjs] Compatability with tsc 'strict' flag (#17672) * [typescript-nestjs] Compatability with tsc 'strict' flag * Update samples / docs --- .../typescript-nestjs/api.module.mustache | 20 +++++++++---------- .../typescript-nestjs/api.service.mustache | 8 ++++---- .../builds/default/api.module.ts | 20 +++++++++---------- .../builds/default/api/pet.service.ts | 12 +++++------ .../builds/default/api.module.ts | 20 +++++++++---------- .../builds/default/api/pet.service.ts | 12 +++++------ 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache index 1b4b5804ed48..0aeeaa782550 100644 --- a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.module.mustache @@ -47,16 +47,16 @@ export class ApiModule { } private static createAsyncProviders(options: AsyncConfiguration): Provider[] { - if (options.useExisting || options.useFactory) { - return [this.createAsyncConfigurationProvider(options)]; + if (options.useClass) { + return [ + this.createAsyncConfigurationProvider(options), + { + provide: options.useClass, + useClass: options.useClass, + }, + ]; } - return [ - this.createAsyncConfigurationProvider(options), - { - provide: options.useClass, - useClass: options.useClass, - }, - ]; + return [this.createAsyncConfigurationProvider(options)]; } private static createAsyncConfigurationProvider( @@ -73,7 +73,7 @@ export class ApiModule { provide: Configuration, useFactory: async (optionsFactory: ConfigurationFactory) => await optionsFactory.createConfiguration(), - inject: [options.useExisting || options.useClass], + inject: (options.useExisting && [options.useExisting]) || (options.useClass && [options.useClass]) || [], }; } diff --git a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache index d5dfcc0a10d3..064978b97537 100644 --- a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache @@ -208,24 +208,24 @@ export class {{classname}} { if ({{paramName}}) { {{#isCollectionFormatMulti}} {{paramName}}.forEach((element) => { - formParams.append('{{baseName}}', element); + formParams!.append('{{baseName}}', element); }) {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} - formParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + formParams!.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); {{/isCollectionFormatMulti}} } {{/isArray}} {{^isArray}} if ({{paramName}} !== undefined) { - formParams.append('{{baseName}}', {{paramName}}); + formParams!.append('{{baseName}}', {{paramName}}); } {{/isArray}} {{/formParams}} {{/hasFormParams}} return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.basePath}{{{path}}}`,{{#isBodyAllowed}} - {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}} + {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}convertFormParamsToString ? formParams!.toString() : formParams!{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}} { {{#hasQueryParams}} params: queryParameters, diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts index 514febba9d7d..39681eb809d8 100644 --- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts +++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api.module.ts @@ -41,16 +41,16 @@ export class ApiModule { } private static createAsyncProviders(options: AsyncConfiguration): Provider[] { - if (options.useExisting || options.useFactory) { - return [this.createAsyncConfigurationProvider(options)]; + if (options.useClass) { + return [ + this.createAsyncConfigurationProvider(options), + { + provide: options.useClass, + useClass: options.useClass, + }, + ]; } - return [ - this.createAsyncConfigurationProvider(options), - { - provide: options.useClass, - useClass: options.useClass, - }, - ]; + return [this.createAsyncConfigurationProvider(options)]; } private static createAsyncConfigurationProvider( @@ -67,7 +67,7 @@ export class ApiModule { provide: Configuration, useFactory: async (optionsFactory: ConfigurationFactory) => await optionsFactory.createConfiguration(), - inject: [options.useExisting || options.useClass], + inject: (options.useExisting && [options.useExisting]) || (options.useClass && [options.useClass]) || [], }; } diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts index a28b44fc641e..32b236cddb2c 100644 --- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts @@ -383,15 +383,15 @@ export class PetService { } if (name !== undefined) { - formParams.append('name', name); + formParams!.append('name', name); } if (status !== undefined) { - formParams.append('status', status); + formParams!.append('status', status); } return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - convertFormParamsToString ? formParams.toString() : formParams, + convertFormParamsToString ? formParams!.toString() : formParams!, { withCredentials: this.configuration.withCredentials, headers: headers @@ -456,15 +456,15 @@ export class PetService { } if (additionalMetadata !== undefined) { - formParams.append('additionalMetadata', additionalMetadata); + formParams!.append('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.append('file', file); + formParams!.append('file', file); } return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, - convertFormParamsToString ? formParams.toString() : formParams, + convertFormParamsToString ? formParams!.toString() : formParams!, { withCredentials: this.configuration.withCredentials, headers: headers diff --git a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api.module.ts b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api.module.ts index e70c901e9d09..c2f7aae75f5f 100644 --- a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api.module.ts +++ b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api.module.ts @@ -42,16 +42,16 @@ export class ApiModule { } private static createAsyncProviders(options: AsyncConfiguration): Provider[] { - if (options.useExisting || options.useFactory) { - return [this.createAsyncConfigurationProvider(options)]; + if (options.useClass) { + return [ + this.createAsyncConfigurationProvider(options), + { + provide: options.useClass, + useClass: options.useClass, + }, + ]; } - return [ - this.createAsyncConfigurationProvider(options), - { - provide: options.useClass, - useClass: options.useClass, - }, - ]; + return [this.createAsyncConfigurationProvider(options)]; } private static createAsyncConfigurationProvider( @@ -68,7 +68,7 @@ export class ApiModule { provide: Configuration, useFactory: async (optionsFactory: ConfigurationFactory) => await optionsFactory.createConfiguration(), - inject: [options.useExisting || options.useClass], + inject: (options.useExisting && [options.useExisting]) || (options.useClass && [options.useClass]) || [], }; } diff --git a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts index 3a8c5f4125d3..8a3d572777d3 100644 --- a/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/api/pet.service.ts @@ -384,15 +384,15 @@ export class PetService { } if (name !== undefined) { - formParams.append('name', name); + formParams!.append('name', name); } if (status !== undefined) { - formParams.append('status', status); + formParams!.append('status', status); } return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, - convertFormParamsToString ? formParams.toString() : formParams, + convertFormParamsToString ? formParams!.toString() : formParams!, { withCredentials: this.configuration.withCredentials, headers: headers @@ -457,15 +457,15 @@ export class PetService { } if (additionalMetadata !== undefined) { - formParams.append('additionalMetadata', additionalMetadata); + formParams!.append('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.append('file', file); + formParams!.append('file', file); } return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, - convertFormParamsToString ? formParams.toString() : formParams, + convertFormParamsToString ? formParams!.toString() : formParams!, { withCredentials: this.configuration.withCredentials, headers: headers