Skip to content

Commit dfbe985

Browse files
authored
fix(typescript-angular): enable "exactOptionalPropertyTypes" and ensure assignments align with type definition (#20451)
* fix(typescript-angular): enable "exactOptionalPropertyTypes" and ensure assignments align with type definition * fix(typescript-angular): update condition checks to explicitly compare with undefined * chore(gradle): add autogenerated properties file for OpenAPI Generator
1 parent a7159f6 commit dfbe985

File tree

71 files changed

+1251
-878
lines changed

Some content is hidden

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

71 files changed

+1251
-878
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ export class {{classname}} extends BaseService {
275275

276276
{{/isResponseFile}}
277277
let localVarPath = `{{{path}}}`;
278-
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${this.configuration.basePath}${localVarPath}`,
278+
const { basePath, withCredentials } = this.configuration;
279+
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${basePath}${localVarPath}`,
279280
{
280281
{{#httpContextInOptions}}
281282
context: localVarHttpContext,
@@ -297,7 +298,7 @@ export class {{classname}} extends BaseService {
297298
{{^isResponseFile}}
298299
responseType: <any>responseType_,
299300
{{/isResponseFile}}
300-
withCredentials: this.configuration.withCredentials,
301+
...(withCredentials ? { withCredentials } : {}),
301302
headers: localVarHeaders,
302303
observe: observe,
303304
{{#httpTransferCacheInOptions}}

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

+20-16
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 !== undefined) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password !== undefined) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken !== undefined) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath !== undefined) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials !== undefined) {
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

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

+2
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,

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ export class PetService extends BaseService {
7070
}
7171

7272
let localVarPath = `/pet/mapped`;
73-
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${this.configuration.basePath}${localVarPath}`,
73+
const { basePath, withCredentials } = this.configuration;
74+
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${basePath}${localVarPath}`,
7475
{
7576
context: localVarHttpContext,
7677
responseType: <any>responseType_,
77-
withCredentials: this.configuration.withCredentials,
78+
...(withCredentials ? { withCredentials } : {}),
7879
headers: localVarHeaders,
7980
observe: observe,
8081
transferCache: localVarTransferCache,

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

+20-16
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 !== undefined) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password !== undefined) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken !== undefined) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath !== undefined) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials !== undefined) {
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
/**

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ export class PetService extends BaseService {
7070
}
7171

7272
let localVarPath = `/pet/mapped`;
73-
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${this.configuration.basePath}${localVarPath}`,
73+
const { basePath, withCredentials } = this.configuration;
74+
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${basePath}${localVarPath}`,
7475
{
7576
context: localVarHttpContext,
7677
responseType: <any>responseType_,
77-
withCredentials: this.configuration.withCredentials,
78+
...(withCredentials ? { withCredentials } : {}),
7879
headers: localVarHeaders,
7980
observe: observe,
8081
transferCache: localVarTransferCache,

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

+20-16
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 !== undefined) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password !== undefined) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken !== undefined) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath !== undefined) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials !== undefined) {
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
/**

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ export class DefaultService extends BaseService {
6868
}
6969

7070
let localVarPath = `/`;
71-
return this.httpClient.request<Fruit>('get', `${this.configuration.basePath}${localVarPath}`,
71+
const { basePath, withCredentials } = this.configuration;
72+
return this.httpClient.request<Fruit>('get', `${basePath}${localVarPath}`,
7273
{
7374
context: localVarHttpContext,
7475
responseType: <any>responseType_,
75-
withCredentials: this.configuration.withCredentials,
76+
...(withCredentials ? { withCredentials } : {}),
7677
headers: localVarHeaders,
7778
observe: observe,
7879
reportProgress: reportProgress
@@ -122,12 +123,13 @@ export class DefaultService extends BaseService {
122123
}
123124

124125
let localVarPath = `/`;
125-
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
126+
const { basePath, withCredentials } = this.configuration;
127+
return this.httpClient.request<any>('put', `${basePath}${localVarPath}`,
126128
{
127129
context: localVarHttpContext,
128130
body: body,
129131
responseType: <any>responseType_,
130-
withCredentials: this.configuration.withCredentials,
132+
...(withCredentials ? { withCredentials } : {}),
131133
headers: localVarHeaders,
132134
observe: observe,
133135
reportProgress: reportProgress

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

+20-16
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 !== undefined) {
74+
this.username = username;
8275
}
83-
if (configurationParameters.credentials) {
84-
this.credentials = configurationParameters.credentials;
76+
if (password !== undefined) {
77+
this.password = password;
8578
}
86-
else {
87-
this.credentials = {};
79+
if (accessToken !== undefined) {
80+
this.accessToken = accessToken;
8881
}
82+
if (basePath !== undefined) {
83+
this.basePath = basePath;
84+
}
85+
if (withCredentials !== undefined) {
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)