Skip to content

Commit c7a5510

Browse files
tanmenMikailBag
authored andcommitted
[typescript-axios][client] Allow apiKey type Promise. (OpenAPITools#5953)
* change apiKey type * recreate sample
1 parent b11fa9e commit c7a5510

File tree

16 files changed

+647
-647
lines changed

16 files changed

+647
-647
lines changed

modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
3535
* @param {*} [options] Override http request option.
3636
* @throws {RequiredError}
3737
*/
38-
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options: any = {}): RequestArgs {
38+
{{nickname}}: async ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options: any = {}): Promise<RequestArgs> => {
3939
{{#allParams}}
4040
{{#required}}
4141
// verify required parameter '{{paramName}}' is not null or undefined
@@ -62,16 +62,16 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
6262
{{#isKeyInHeader}}
6363
if (configuration && configuration.apiKey) {
6464
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
65-
? configuration.apiKey("{{keyParamName}}")
66-
: configuration.apiKey;
65+
? await configuration.apiKey("{{keyParamName}}")
66+
: await configuration.apiKey;
6767
localVarHeaderParameter["{{keyParamName}}"] = localVarApiKeyValue;
6868
}
6969
{{/isKeyInHeader}}
7070
{{#isKeyInQuery}}
7171
if (configuration && configuration.apiKey) {
7272
const localVarApiKeyValue = typeof configuration.apiKey === 'function'
73-
? configuration.apiKey("{{keyParamName}}")
74-
: configuration.apiKey;
73+
? await configuration.apiKey("{{keyParamName}}")
74+
: await configuration.apiKey;
7575
localVarQueryParameter["{{keyParamName}}"] = localVarApiKeyValue;
7676
}
7777
{{/isKeyInQuery}}
@@ -228,8 +228,8 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
228228
* @param {*} [options] Override http request option.
229229
* @throws {RequiredError}
230230
*/
231-
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
232-
const localVarAxiosArgs = {{classname}}AxiosParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
231+
async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
232+
const localVarAxiosArgs = await {{classname}}AxiosParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
233233
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
234234
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
235235
return axios.request(axiosRequestArgs);
@@ -259,7 +259,7 @@ export const {{classname}}Factory = function (configuration?: Configuration, bas
259259
* @throws {RequiredError}
260260
*/
261261
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
262-
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(axios, basePath);
262+
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options).then((request) => request(axios, basePath));
263263
},
264264
{{/operation}}
265265
};
@@ -319,7 +319,7 @@ export class {{classname}} extends BaseAPI {
319319
* @memberof {{classname}}
320320
*/
321321
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
322-
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(this.axios, this.basePath);
322+
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options).then((request) => request(this.axios, this.basePath));
323323
}
324324
325325
{{/operation}}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{>licenseInfo}}
33

44
export interface ConfigurationParameters {
5-
apiKey?: string | ((name: string) => string);
5+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
66
username?: string;
77
password?: string;
88
accessToken?: string | ((name?: string, scopes?: string[]) => string);
@@ -16,7 +16,7 @@ export class Configuration {
1616
* @param name security name
1717
* @memberof Configuration
1818
*/
19-
apiKey?: string | ((name: string) => string);
19+
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
2020
/**
2121
* parameter for basic security
2222
*

0 commit comments

Comments
 (0)