Skip to content

Commit

Permalink
[typescript-nestjs] Compatability with tsc 'strict' flag (OpenAPITool…
Browse files Browse the repository at this point in the history
…s#17672)

* [typescript-nestjs] Compatability with tsc 'strict' flag

* Update samples / docs
  • Loading branch information
swcm-mnestler authored Mar 9, 2024
1 parent 9500284 commit 0bc979e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]) || [],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,24 @@ export class {{classname}} {
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
formParams.append('{{baseName}}', <any>element);
formParams!.append('{{baseName}}', <any>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}}', <any>{{paramName}});
formParams!.append('{{baseName}}', <any>{{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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]) || [],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,15 @@ export class PetService {
}

if (name !== undefined) {
formParams.append('name', <any>name);
formParams!.append('name', <any>name);
}

if (status !== undefined) {
formParams.append('status', <any>status);
formParams!.append('status', <any>status);
}

return this.httpClient.post<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
convertFormParamsToString ? formParams.toString() : formParams,
convertFormParamsToString ? formParams!.toString() : formParams!,
{
withCredentials: this.configuration.withCredentials,
headers: headers
Expand Down Expand Up @@ -456,15 +456,15 @@ export class PetService {
}

if (additionalMetadata !== undefined) {
formParams.append('additionalMetadata', <any>additionalMetadata);
formParams!.append('additionalMetadata', <any>additionalMetadata);
}

if (file !== undefined) {
formParams.append('file', <any>file);
formParams!.append('file', <any>file);
}

return this.httpClient.post<ApiResponse>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`,
convertFormParamsToString ? formParams.toString() : formParams,
convertFormParamsToString ? formParams!.toString() : formParams!,
{
withCredentials: this.configuration.withCredentials,
headers: headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]) || [],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ export class PetService {
}

if (name !== undefined) {
formParams.append('name', <any>name);
formParams!.append('name', <any>name);
}

if (status !== undefined) {
formParams.append('status', <any>status);
formParams!.append('status', <any>status);
}

return this.httpClient.post<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
convertFormParamsToString ? formParams.toString() : formParams,
convertFormParamsToString ? formParams!.toString() : formParams!,
{
withCredentials: this.configuration.withCredentials,
headers: headers
Expand Down Expand Up @@ -457,15 +457,15 @@ export class PetService {
}

if (additionalMetadata !== undefined) {
formParams.append('additionalMetadata', <any>additionalMetadata);
formParams!.append('additionalMetadata', <any>additionalMetadata);
}

if (file !== undefined) {
formParams.append('file', <any>file);
formParams!.append('file', <any>file);
}

return this.httpClient.post<ApiResponse>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`,
convertFormParamsToString ? formParams.toString() : formParams,
convertFormParamsToString ? formParams!.toString() : formParams!,
{
withCredentials: this.configuration.withCredentials,
headers: headers
Expand Down

0 comments on commit 0bc979e

Please sign in to comment.