Skip to content

Commit 70943ad

Browse files
committed
fix(typescript-angular): enable "exactOptionalPropertyTypes" and ensure assignments align with type definition
1 parent 1bc5eae commit 70943ad

71 files changed

Lines changed: 1251 additions & 878 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ export class {{classname}} {
378378

379379
{{/isResponseFile}}
380380
let localVarPath = `{{{path}}}`;
381-
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${this.configuration.basePath}${localVarPath}`,
381+
const { basePath, withCredentials } = this.configuration;
382+
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${basePath}${localVarPath}`,
382383
{
383384
{{#httpContextInOptions}}
384385
context: localVarHttpContext,
@@ -400,7 +401,7 @@ export class {{classname}} {
400401
{{^isResponseFile}}
401402
responseType: <any>responseType_,
402403
{{/isResponseFile}}
403-
withCredentials: this.configuration.withCredentials,
404+
...(withCredentials ? { withCredentials } : {}),
404405
headers: localVarHeaders,
405406
observe: observe,
406407
{{#httpTransferCacheInOptions}}

modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,30 @@ export class {{configurationClassName}} {
6666
*/
6767
credentials: {[ key: string ]: string | (() => string | undefined)};
6868

69-
constructor(configurationParameters: {{configurationParametersInterfaceName}} = {}) {
70-
this.apiKeys = configurationParameters.apiKeys;
71-
this.username = configurationParameters.username;
72-
this.password = configurationParameters.password;
73-
this.accessToken = configurationParameters.accessToken;
74-
this.basePath = configurationParameters.basePath;
75-
this.withCredentials = configurationParameters.withCredentials;
76-
this.encoder = configurationParameters.encoder;
77-
if (configurationParameters.encodeParam) {
78-
this.encodeParam = configurationParameters.encodeParam;
69+
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: {{configurationParametersInterfaceName}} = {}) {
70+
if (apiKeys) {
71+
this.apiKeys = apiKeys;
7972
}
80-
else {
81-
this.encodeParam = param => this.defaultEncodeParam(param);
73+
if (username) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials) {
86+
this.withCredentials = withCredentials;
87+
}
88+
if (encoder) {
89+
this.encoder = encoder;
90+
}
91+
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
92+
this.credentials = credentials ?? {};
8993
{{#authMethods}}
9094

9195
// init default {{name}} credential

modules/openapi-generator/src/main/resources/typescript-angular/tsconfig.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
88
"moduleResolution": "node",
99
"removeComments": true,
10+
"strictNullChecks": true,
11+
"exactOptionalPropertyTypes": true,
1012
"sourceMap": true,
1113
"outDir": "./dist",
1214
"noLib": false,

samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/api/pet.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ export class PetService {
136136
}
137137

138138
let localVarPath = `/pet/mapped`;
139-
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${this.configuration.basePath}${localVarPath}`,
139+
const { basePath, withCredentials } = this.configuration;
140+
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${basePath}${localVarPath}`,
140141
{
141142
context: localVarHttpContext,
142143
responseType: <any>responseType_,
143-
withCredentials: this.configuration.withCredentials,
144+
...(withCredentials ? { withCredentials } : {}),
144145
headers: localVarHeaders,
145146
observe: observe,
146147
transferCache: localVarTransferCache,

samples/client/others/typescript-angular/builds/composed-schemas-tagged-unions/configuration.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,30 @@ export class Configuration {
6666
*/
6767
credentials: {[ key: string ]: string | (() => string | undefined)};
6868

69-
constructor(configurationParameters: ConfigurationParameters = {}) {
70-
this.apiKeys = configurationParameters.apiKeys;
71-
this.username = configurationParameters.username;
72-
this.password = configurationParameters.password;
73-
this.accessToken = configurationParameters.accessToken;
74-
this.basePath = configurationParameters.basePath;
75-
this.withCredentials = configurationParameters.withCredentials;
76-
this.encoder = configurationParameters.encoder;
77-
if (configurationParameters.encodeParam) {
78-
this.encodeParam = configurationParameters.encodeParam;
69+
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) {
70+
if (apiKeys) {
71+
this.apiKeys = apiKeys;
7972
}
80-
else {
81-
this.encodeParam = param => this.defaultEncodeParam(param);
73+
if (username) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials) {
86+
this.withCredentials = withCredentials;
87+
}
88+
if (encoder) {
89+
this.encoder = encoder;
90+
}
91+
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
92+
this.credentials = credentials ?? {};
8993
}
9094

9195
/**

samples/client/others/typescript-angular/builds/composed-schemas/api/pet.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ export class PetService {
136136
}
137137

138138
let localVarPath = `/pet/mapped`;
139-
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${this.configuration.basePath}${localVarPath}`,
139+
const { basePath, withCredentials } = this.configuration;
140+
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${basePath}${localVarPath}`,
140141
{
141142
context: localVarHttpContext,
142143
responseType: <any>responseType_,
143-
withCredentials: this.configuration.withCredentials,
144+
...(withCredentials ? { withCredentials } : {}),
144145
headers: localVarHeaders,
145146
observe: observe,
146147
transferCache: localVarTransferCache,

samples/client/others/typescript-angular/builds/composed-schemas/configuration.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,30 @@ export class Configuration {
6666
*/
6767
credentials: {[ key: string ]: string | (() => string | undefined)};
6868

69-
constructor(configurationParameters: ConfigurationParameters = {}) {
70-
this.apiKeys = configurationParameters.apiKeys;
71-
this.username = configurationParameters.username;
72-
this.password = configurationParameters.password;
73-
this.accessToken = configurationParameters.accessToken;
74-
this.basePath = configurationParameters.basePath;
75-
this.withCredentials = configurationParameters.withCredentials;
76-
this.encoder = configurationParameters.encoder;
77-
if (configurationParameters.encodeParam) {
78-
this.encodeParam = configurationParameters.encodeParam;
69+
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) {
70+
if (apiKeys) {
71+
this.apiKeys = apiKeys;
7972
}
80-
else {
81-
this.encodeParam = param => this.defaultEncodeParam(param);
73+
if (username) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials) {
86+
this.withCredentials = withCredentials;
87+
}
88+
if (encoder) {
89+
this.encoder = encoder;
90+
}
91+
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
92+
this.credentials = credentials ?? {};
8993
}
9094

9195
/**

samples/client/petstore/typescript-angular-v12-oneOf/builds/default/api/default.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ export class DefaultService {
131131
}
132132

133133
let localVarPath = `/`;
134-
return this.httpClient.request<Fruit>('get', `${this.configuration.basePath}${localVarPath}`,
134+
const { basePath, withCredentials } = this.configuration;
135+
return this.httpClient.request<Fruit>('get', `${basePath}${localVarPath}`,
135136
{
136137
context: localVarHttpContext,
137138
responseType: <any>responseType_,
138-
withCredentials: this.configuration.withCredentials,
139+
...(withCredentials ? { withCredentials } : {}),
139140
headers: localVarHeaders,
140141
observe: observe,
141142
reportProgress: reportProgress
@@ -193,12 +194,13 @@ export class DefaultService {
193194
}
194195

195196
let localVarPath = `/`;
196-
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
197+
const { basePath, withCredentials } = this.configuration;
198+
return this.httpClient.request<any>('put', `${basePath}${localVarPath}`,
197199
{
198200
context: localVarHttpContext,
199201
body: body,
200202
responseType: <any>responseType_,
201-
withCredentials: this.configuration.withCredentials,
203+
...(withCredentials ? { withCredentials } : {}),
202204
headers: localVarHeaders,
203205
observe: observe,
204206
reportProgress: reportProgress

samples/client/petstore/typescript-angular-v12-oneOf/builds/default/configuration.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,30 @@ export class Configuration {
6666
*/
6767
credentials: {[ key: string ]: string | (() => string | undefined)};
6868

69-
constructor(configurationParameters: ConfigurationParameters = {}) {
70-
this.apiKeys = configurationParameters.apiKeys;
71-
this.username = configurationParameters.username;
72-
this.password = configurationParameters.password;
73-
this.accessToken = configurationParameters.accessToken;
74-
this.basePath = configurationParameters.basePath;
75-
this.withCredentials = configurationParameters.withCredentials;
76-
this.encoder = configurationParameters.encoder;
77-
if (configurationParameters.encodeParam) {
78-
this.encodeParam = configurationParameters.encodeParam;
69+
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) {
70+
if (apiKeys) {
71+
this.apiKeys = apiKeys;
7972
}
80-
else {
81-
this.encodeParam = param => this.defaultEncodeParam(param);
73+
if (username) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials) {
86+
this.withCredentials = withCredentials;
87+
}
88+
if (encoder) {
89+
this.encoder = encoder;
90+
}
91+
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
92+
this.credentials = credentials ?? {};
8993
}
9094

9195
/**

0 commit comments

Comments
 (0)