[JavaScript] Avoid undefined headers with skipDefaultUserAgent enabled (#20792)

Prior to this commit, a JS client generated with skipDefaultUserAgent
enabled results in a src/ApiClient.js file that doesn't define
this.defaultHeaders. This breaks because this.defaultHeaders is later
directly passed to a superagent request which expects an object and not
undefined.

Fixes #20791.
This commit is contained in:
Jakob Warkotsch 2025-03-05 10:36:07 +01:00 committed by GitHub
parent 0f13dfedb9
commit efc53f5d47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -56,7 +56,6 @@ class ApiClient {
}
<={{ }}=>
{{^skipDefaultUserAgent}}
{{#emitJSDoc}}
/**
* The default HTTP headers to be included for all API calls.
@ -65,10 +64,11 @@ class ApiClient {
*/
{{/emitJSDoc}}
this.defaultHeaders = {
{{^skipDefaultUserAgent}}
'User-Agent': '{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{projectVersion}}/Javascript{{/httpUserAgent}}'
{{/skipDefaultUserAgent}}
};
{{/skipDefaultUserAgent}}
/**
* The default HTTP timeout for all API calls.
* @type {Number}

View File

@ -52,6 +52,14 @@ class ApiClient {
'bearer_test': {type: 'bearer'}, // JWT
}
/**
* The default HTTP headers to be included for all API calls.
* @type {Array.<String>}
* @default {}
*/
this.defaultHeaders = {
};
/**
* The default HTTP timeout for all API calls.
* @type {Number}