Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ export class {{classname}} {

{{/isResponseFile}}
let localVarPath = `{{{path}}}`;
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${this.configuration.basePath}${localVarPath}`,
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${basePath}${localVarPath}`,
{
{{#httpContextInOptions}}
context: localVarHttpContext,
Expand All @@ -400,7 +401,7 @@ export class {{classname}} {
{{^isResponseFile}}
responseType: <any>responseType_,
{{/isResponseFile}}
withCredentials: this.configuration.withCredentials,
...(withCredentials ? { withCredentials } : {}),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ?? Or || ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstand the suggestion to use the nullish coalescing operator, but if I use it I would have to specify a default value for withCredentials.

withCredentials is type of boolean and is optional, see here. With exactOptionalPropertyTypes an assignment of undefined wouldn't be allowed.

withCredentials: withCredentials ?? false seemed more like a breaking change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I would be fine to go this route. I had a rough look at the Angular code and it seems that no distinction is made between undefined and false.

headers: localVarHeaders,
observe: observe,
{{#httpTransferCacheInOptions}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,30 @@ export class {{configurationClassName}} {
*/
credentials: {[ key: string ]: string | (() => string | undefined)};

constructor(configurationParameters: {{configurationParametersInterfaceName}} = {}) {
this.apiKeys = configurationParameters.apiKeys;
this.username = configurationParameters.username;
this.password = configurationParameters.password;
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.encoder = configurationParameters.encoder;
if (configurationParameters.encodeParam) {
this.encodeParam = configurationParameters.encodeParam;
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: {{configurationParametersInterfaceName}} = {}) {
if (apiKeys) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all guarded now, but beforehand they weren't, if the containing object was truthy all of them would have been set, no matter if truthy or not. Do we need to look into it in more detail on whether that behavior changes are fully backwards compatible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is absolutely correct. I have adapted it by explicitly checking for undefined. The only exceptions are encoder and apiKeys, as both can only be of data type truthy or undefined.

this.apiKeys = apiKeys;
}
else {
this.encodeParam = param => this.defaultEncodeParam(param);
if (username) {
this.username = username;
}
if (configurationParameters.credentials) {
this.credentials = configurationParameters.credentials;
if (password) {
this.password = password;
}
else {
this.credentials = {};
if (accessToken) {
this.accessToken = accessToken;
}
if (basePath) {
this.basePath = basePath;
}
if (withCredentials) {
this.withCredentials = withCredentials;
}
if (encoder) {
this.encoder = encoder;
}
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
this.credentials = credentials ?? {};
{{#authMethods}}

// init default {{name}} credential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
"moduleResolution": "node",
"removeComments": true,
"strictNullChecks": true,
"exactOptionalPropertyTypes": true,
"sourceMap": true,
"outDir": "./dist",
"noLib": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ export class PetService {
}

let localVarPath = `/pet/mapped`;
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${this.configuration.basePath}${localVarPath}`,
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
...(withCredentials ? { withCredentials } : {}),
headers: localVarHeaders,
observe: observe,
transferCache: localVarTransferCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,30 @@ export class Configuration {
*/
credentials: {[ key: string ]: string | (() => string | undefined)};

constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
this.username = configurationParameters.username;
this.password = configurationParameters.password;
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.encoder = configurationParameters.encoder;
if (configurationParameters.encodeParam) {
this.encodeParam = configurationParameters.encodeParam;
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) {
if (apiKeys) {
this.apiKeys = apiKeys;
}
else {
this.encodeParam = param => this.defaultEncodeParam(param);
if (username) {
this.username = username;
}
if (configurationParameters.credentials) {
this.credentials = configurationParameters.credentials;
if (password) {
this.password = password;
}
else {
this.credentials = {};
if (accessToken) {
this.accessToken = accessToken;
}
if (basePath) {
this.basePath = basePath;
}
if (withCredentials) {
this.withCredentials = withCredentials;
}
if (encoder) {
this.encoder = encoder;
}
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
this.credentials = credentials ?? {};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ export class PetService {
}

let localVarPath = `/pet/mapped`;
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${this.configuration.basePath}${localVarPath}`,
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request<Array<PetWithMappedDiscriminatorModel>>('get', `${basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
...(withCredentials ? { withCredentials } : {}),
headers: localVarHeaders,
observe: observe,
transferCache: localVarTransferCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,30 @@ export class Configuration {
*/
credentials: {[ key: string ]: string | (() => string | undefined)};

constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
this.username = configurationParameters.username;
this.password = configurationParameters.password;
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.encoder = configurationParameters.encoder;
if (configurationParameters.encodeParam) {
this.encodeParam = configurationParameters.encodeParam;
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) {
if (apiKeys) {
this.apiKeys = apiKeys;
}
else {
this.encodeParam = param => this.defaultEncodeParam(param);
if (username) {
this.username = username;
}
if (configurationParameters.credentials) {
this.credentials = configurationParameters.credentials;
if (password) {
this.password = password;
}
else {
this.credentials = {};
if (accessToken) {
this.accessToken = accessToken;
}
if (basePath) {
this.basePath = basePath;
}
if (withCredentials) {
this.withCredentials = withCredentials;
}
if (encoder) {
this.encoder = encoder;
}
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
this.credentials = credentials ?? {};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ export class DefaultService {
}

let localVarPath = `/`;
return this.httpClient.request<Fruit>('get', `${this.configuration.basePath}${localVarPath}`,
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request<Fruit>('get', `${basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
...(withCredentials ? { withCredentials } : {}),
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
Expand Down Expand Up @@ -193,12 +194,13 @@ export class DefaultService {
}

let localVarPath = `/`;
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request<any>('put', `${basePath}${localVarPath}`,
{
context: localVarHttpContext,
body: body,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
...(withCredentials ? { withCredentials } : {}),
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,30 @@ export class Configuration {
*/
credentials: {[ key: string ]: string | (() => string | undefined)};

constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
this.username = configurationParameters.username;
this.password = configurationParameters.password;
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.encoder = configurationParameters.encoder;
if (configurationParameters.encodeParam) {
this.encodeParam = configurationParameters.encodeParam;
constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder, password, username, withCredentials }: ConfigurationParameters = {}) {
if (apiKeys) {
this.apiKeys = apiKeys;
}
else {
this.encodeParam = param => this.defaultEncodeParam(param);
if (username) {
this.username = username;
}
if (configurationParameters.credentials) {
this.credentials = configurationParameters.credentials;
if (password) {
this.password = password;
}
else {
this.credentials = {};
if (accessToken) {
this.accessToken = accessToken;
}
if (basePath) {
this.basePath = basePath;
}
if (withCredentials) {
this.withCredentials = withCredentials;
}
if (encoder) {
this.encoder = encoder;
}
this.encodeParam = encodeParam ?? (param => this.defaultEncodeParam(param));
this.credentials = credentials ?? {};
}

/**
Expand Down
Loading