From b5e2f5702d033adf5ef7ab0d9adffbd157116240 Mon Sep 17 00:00:00 2001 From: Georgy Ushakov Date: Wed, 2 Jun 2021 21:29:44 +0200 Subject: [PATCH] Added support for async accessToken in typescript-fetch --- .../resources/typescript-fetch/apis.mustache | 8 +--- .../typescript-fetch/runtime.mustache | 6 +-- .../builds/default-v3.0/apis/FakeApi.ts | 2 +- .../builds/default-v3.0/apis/PetApi.ts | 48 ++++--------------- .../builds/default-v3.0/runtime.ts | 6 +-- .../builds/default/apis/PetApi.ts | 42 +++------------- .../builds/default/runtime.ts | 6 +-- .../typescript-fetch/builds/enum/runtime.ts | 6 +-- .../builds/es6-target/src/apis/PetApi.ts | 42 +++------------- .../builds/es6-target/src/runtime.ts | 6 +-- .../builds/multiple-parameters/apis/PetApi.ts | 42 +++------------- .../builds/multiple-parameters/runtime.ts | 6 +-- .../src/apis/PetApi.ts | 42 +++------------- .../src/runtime.ts | 6 +-- .../typescript-three-plus/src/apis/PetApi.ts | 42 +++------------- .../typescript-three-plus/src/runtime.ts | 6 +-- .../builds/with-interfaces/apis/PetApi.ts | 42 +++------------- .../builds/with-interfaces/runtime.ts | 6 +-- .../with-npm-version/src/apis/PetApi.ts | 42 +++------------- .../builds/with-npm-version/src/runtime.ts | 6 +-- .../without-runtime-checks/src/apis/PetApi.ts | 42 +++------------- .../without-runtime-checks/src/runtime.ts | 6 +-- 22 files changed, 100 insertions(+), 360 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index 8466deb2853e..851b9ce3831e 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -167,7 +167,7 @@ export class {{classname}} extends runtime.BaseAPI { {{#isBasicBearer}} if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; - const tokenString = typeof token === 'function' ? token("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]) : token; + const tokenString = await token("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; @@ -192,11 +192,7 @@ export class {{classname}} extends runtime.BaseAPI { {{#isOAuth}} if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]); } {{/isOAuth}} diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index d0c29b93a755..e0498e0e316a 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -124,7 +124,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -164,10 +164,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts index 5985139ab238..31f05a52858a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts @@ -732,7 +732,7 @@ export class FakeApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; - const tokenString = typeof token === 'function' ? token("bearer_test", []) : token; + const tokenString = await token("bearer_test", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/PetApi.ts index 854c14d7dcd3..198794ce8b0b 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/PetApi.ts @@ -87,11 +87,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -130,11 +126,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -173,11 +165,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -218,11 +206,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -296,11 +280,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -335,11 +315,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -396,11 +372,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -464,11 +436,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts index cb001046c5b2..be992e2dac88 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/default/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/default/apis/PetApi.ts index a219f15f7e2c..3bf150e489b6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/apis/PetApi.ts @@ -81,11 +81,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -124,11 +120,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -167,11 +159,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -212,11 +200,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -290,11 +274,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -329,11 +309,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -390,11 +366,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts index ccb0370bdc4a..d558d0ad7dee 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/apis/PetApi.ts index a219f15f7e2c..3bf150e489b6 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/apis/PetApi.ts @@ -81,11 +81,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -124,11 +120,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -167,11 +159,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -212,11 +200,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -290,11 +274,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -329,11 +309,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -390,11 +366,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/apis/PetApi.ts index 4c47ea2e1f10..db5971d0ad5f 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/apis/PetApi.ts @@ -81,11 +81,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -124,11 +120,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -167,11 +159,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -212,11 +200,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -290,11 +274,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -329,11 +309,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -390,11 +366,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/apis/PetApi.ts index b98247c01daf..e2fd699fd73b 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/apis/PetApi.ts @@ -81,11 +81,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -124,11 +120,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -167,11 +159,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -212,11 +200,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -290,11 +274,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -329,11 +309,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -390,11 +366,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/apis/PetApi.ts index a219f15f7e2c..3bf150e489b6 100644 --- a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/apis/PetApi.ts @@ -81,11 +81,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -124,11 +120,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -167,11 +159,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -212,11 +200,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -290,11 +274,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -329,11 +309,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -390,11 +366,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts index da5d9059bad3..95601f9e3076 100644 --- a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts index d7f8f8a62fe8..f8224fdb55f1 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/apis/PetApi.ts @@ -218,11 +218,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -261,11 +257,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -304,11 +296,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -349,11 +337,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -427,11 +411,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -466,11 +446,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -527,11 +503,7 @@ export class PetApi extends runtime.BaseAPI implements PetApiInterface { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/apis/PetApi.ts index a219f15f7e2c..3bf150e489b6 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/apis/PetApi.ts @@ -81,11 +81,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -124,11 +120,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -167,11 +159,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -212,11 +200,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -290,11 +274,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -329,11 +309,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -390,11 +366,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; } diff --git a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/apis/PetApi.ts b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/apis/PetApi.ts index dd0a9026b019..063d760e6ca5 100644 --- a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/apis/PetApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/apis/PetApi.ts @@ -77,11 +77,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -120,11 +116,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -163,11 +155,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -208,11 +196,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -286,11 +270,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const response = await this.request({ @@ -325,11 +305,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ @@ -386,11 +362,7 @@ export class PetApi extends runtime.BaseAPI { if (this.configuration && this.configuration.accessToken) { // oauth required - if (typeof this.configuration.accessToken === 'function') { - headerParameters["Authorization"] = this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); - } else { - headerParameters["Authorization"] = this.configuration.accessToken; - } + headerParameters["Authorization"] = await this.configuration.accessToken("petstore_auth", ["write:pets", "read:pets"]); } const consumes: runtime.Consume[] = [ diff --git a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts index f7a51f623ff2..20374a38659d 100644 --- a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts @@ -135,7 +135,7 @@ export interface ConfigurationParameters { username?: string; // parameter for basic security password?: string; // parameter for basic security apiKey?: string | ((name: string) => string); // parameter for apiKey security - accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security headers?: HTTPHeaders; //header params we want to use on every request credentials?: RequestCredentials; //value for the credentials param we want to use on each request } @@ -175,10 +175,10 @@ export class Configuration { return undefined; } - get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { const accessToken = this.configuration.accessToken; if (accessToken) { - return typeof accessToken === 'function' ? accessToken : () => accessToken; + return typeof accessToken === 'function' ? accessToken : async () => accessToken; } return undefined; }