From 76fecf744b0f88b400efe04cceb31f3e88f5e387 Mon Sep 17 00:00:00 2001 From: Silas Boyd-Wickizer Date: Mon, 22 Jul 2019 01:54:48 -0700 Subject: [PATCH] [typescript-node] Promise-based Authentication interface (#3408) --- .../typescript-node/api-single.mustache | 46 +-- .../resources/typescript-node/models.mustache | 2 +- .../typescript-node/default/api/petApi.ts | 328 +++++++++--------- .../typescript-node/default/api/storeApi.ts | 160 +++++---- .../typescript-node/default/api/userApi.ts | 308 ++++++++-------- .../typescript-node/default/model/models.ts | 2 +- .../typescript-node/npm/api/petApi.ts | 328 +++++++++--------- .../typescript-node/npm/api/storeApi.ts | 160 +++++---- .../typescript-node/npm/api/userApi.ts | 308 ++++++++-------- .../typescript-node/npm/model/models.ts | 2 +- 10 files changed, 863 insertions(+), 781 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache index c4227e75de..91b263cb5d 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache @@ -197,33 +197,35 @@ export class {{classname}} { {{/bodyParam}} }; + let authenticationPromise = Promise.resolve(); {{#authMethods}} - this.authentications.{{name}}.applyToRequest(localVarRequestOptions); + authenticationPromise = authenticationPromise.then(() => this.authentications.{{name}}.applyToRequest(localVarRequestOptions)); {{/authMethods}} - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - {{#returnType}} - body = ObjectSerializer.deserialize(body, "{{{returnType}}}"); - {{/returnType}} - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.{{#supportsES6}}IncomingMessage{{/supportsES6}}{{^supportsES6}}ClientResponse{{/supportsES6}}; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + {{#returnType}} + body = ObjectSerializer.deserialize(body, "{{{returnType}}}"); + {{/returnType}} + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/modules/openapi-generator/src/main/resources/typescript-node/models.mustache b/modules/openapi-generator/src/main/resources/typescript-node/models.mustache index 39c7da727e..0bd709c2dd 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/models.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/models.mustache @@ -166,7 +166,7 @@ export interface Authentication { /** * Apply authentication settings to header and query params. */ - applyToRequest(requestOptions: localVarRequest.Options): void; + applyToRequest(requestOptions: localVarRequest.Options): Promise | void; } export class HttpBasicAuth implements Authentication { diff --git a/samples/client/petstore/typescript-node/default/api/petApi.ts b/samples/client/petstore/typescript-node/default/api/petApi.ts index c37458099c..2566d2b935 100644 --- a/samples/client/petstore/typescript-node/default/api/petApi.ts +++ b/samples/client/petstore/typescript-node/default/api/petApi.ts @@ -109,28 +109,30 @@ export class PetApi { body: ObjectSerializer.serialize(body, "Pet") }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -166,28 +168,30 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -224,29 +228,31 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Array"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Array"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -283,29 +289,31 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Array"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Array"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -339,29 +347,31 @@ export class PetApi { json: true, }; - this.authentications.api_key.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Pet; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Pet"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Pet; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Pet"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -395,28 +405,30 @@ export class PetApi { body: ObjectSerializer.serialize(body, "Pet") }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -460,28 +472,30 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -526,29 +540,31 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: ApiResponse; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "ApiResponse"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: ApiResponse; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "ApiResponse"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/samples/client/petstore/typescript-node/default/api/storeApi.ts b/samples/client/petstore/typescript-node/default/api/storeApi.ts index 23f0fb73bf..cf3b545a3d 100644 --- a/samples/client/petstore/typescript-node/default/api/storeApi.ts +++ b/samples/client/petstore/typescript-node/default/api/storeApi.ts @@ -102,26 +102,28 @@ export class StoreApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -148,29 +150,31 @@ export class StoreApi { json: true, }; - this.authentications.api_key.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "{ [key: string]: number; }"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "{ [key: string]: number; }"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -204,27 +208,29 @@ export class StoreApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Order"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Order"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -258,27 +264,29 @@ export class StoreApi { body: ObjectSerializer.serialize(body, "Order") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Order"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Order"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/samples/client/petstore/typescript-node/default/api/userApi.ts b/samples/client/petstore/typescript-node/default/api/userApi.ts index 5a7a179f04..374daf1f1b 100644 --- a/samples/client/petstore/typescript-node/default/api/userApi.ts +++ b/samples/client/petstore/typescript-node/default/api/userApi.ts @@ -99,26 +99,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "User") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -152,26 +154,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "Array") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -205,26 +209,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "Array") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -258,26 +264,28 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -311,27 +319,29 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: User; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "User"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: User; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "User"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -378,27 +388,29 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: string; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "string"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: string; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "string"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -425,26 +437,28 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -485,26 +499,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "User") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/samples/client/petstore/typescript-node/default/model/models.ts b/samples/client/petstore/typescript-node/default/model/models.ts index 7b0dc89cbf..73d5122442 100644 --- a/samples/client/petstore/typescript-node/default/model/models.ts +++ b/samples/client/petstore/typescript-node/default/model/models.ts @@ -155,7 +155,7 @@ export interface Authentication { /** * Apply authentication settings to header and query params. */ - applyToRequest(requestOptions: localVarRequest.Options): void; + applyToRequest(requestOptions: localVarRequest.Options): Promise | void; } export class HttpBasicAuth implements Authentication { diff --git a/samples/client/petstore/typescript-node/npm/api/petApi.ts b/samples/client/petstore/typescript-node/npm/api/petApi.ts index c37458099c..2566d2b935 100644 --- a/samples/client/petstore/typescript-node/npm/api/petApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/petApi.ts @@ -109,28 +109,30 @@ export class PetApi { body: ObjectSerializer.serialize(body, "Pet") }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -166,28 +168,30 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -224,29 +228,31 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Array"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Array"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -283,29 +289,31 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Array"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Array; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Array"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -339,29 +347,31 @@ export class PetApi { json: true, }; - this.authentications.api_key.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Pet; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Pet"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Pet; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Pet"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -395,28 +405,30 @@ export class PetApi { body: ObjectSerializer.serialize(body, "Pet") }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -460,28 +472,30 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -526,29 +540,31 @@ export class PetApi { json: true, }; - this.authentications.petstore_auth.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.petstore_auth.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: ApiResponse; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "ApiResponse"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: ApiResponse; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "ApiResponse"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/samples/client/petstore/typescript-node/npm/api/storeApi.ts b/samples/client/petstore/typescript-node/npm/api/storeApi.ts index 23f0fb73bf..cf3b545a3d 100644 --- a/samples/client/petstore/typescript-node/npm/api/storeApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/storeApi.ts @@ -102,26 +102,28 @@ export class StoreApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -148,29 +150,31 @@ export class StoreApi { json: true, }; - this.authentications.api_key.applyToRequest(localVarRequestOptions); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.api_key.applyToRequest(localVarRequestOptions)); - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "{ [key: string]: number; }"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "{ [key: string]: number; }"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -204,27 +208,29 @@ export class StoreApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Order"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Order"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -258,27 +264,29 @@ export class StoreApi { body: ObjectSerializer.serialize(body, "Order") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "Order"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: Order; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "Order"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/samples/client/petstore/typescript-node/npm/api/userApi.ts b/samples/client/petstore/typescript-node/npm/api/userApi.ts index 5a7a179f04..374daf1f1b 100644 --- a/samples/client/petstore/typescript-node/npm/api/userApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/userApi.ts @@ -99,26 +99,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "User") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -152,26 +154,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "Array") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -205,26 +209,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "Array") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -258,26 +264,28 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -311,27 +319,29 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: User; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "User"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: User; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "User"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -378,27 +388,29 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body: string; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - body = ObjectSerializer.deserialize(body, "string"); - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body: string; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + body = ObjectSerializer.deserialize(body, "string"); + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -425,26 +437,28 @@ export class UserApi { json: true, }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } @@ -485,26 +499,28 @@ export class UserApi { body: ObjectSerializer.serialize(body, "User") }; - this.authentications.default.applyToRequest(localVarRequestOptions); - - if (Object.keys(localVarFormParams).length) { - if (localVarUseFormData) { - (localVarRequestOptions).formData = localVarFormParams; - } else { - localVarRequestOptions.form = localVarFormParams; - } - } - return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { - localVarRequest(localVarRequestOptions, (error, response, body) => { - if (error) { - reject(error); + let authenticationPromise = Promise.resolve(); + authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions)); + return authenticationPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; } else { - if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { - resolve({ response: response, body: body }); - } else { - reject({ response: response, body: body }); - } + localVarRequestOptions.form = localVarFormParams; } + } + return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { + resolve({ response: response, body: body }); + } else { + reject({ response: response, body: body }); + } + } + }); }); }); } diff --git a/samples/client/petstore/typescript-node/npm/model/models.ts b/samples/client/petstore/typescript-node/npm/model/models.ts index 7b0dc89cbf..73d5122442 100644 --- a/samples/client/petstore/typescript-node/npm/model/models.ts +++ b/samples/client/petstore/typescript-node/npm/model/models.ts @@ -155,7 +155,7 @@ export interface Authentication { /** * Apply authentication settings to header and query params. */ - applyToRequest(requestOptions: localVarRequest.Options): void; + applyToRequest(requestOptions: localVarRequest.Options): Promise | void; } export class HttpBasicAuth implements Authentication {