diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts index 7ee27e06dd1..47026929d81 100644 --- a/samples/client/petstore/typescript-node/api.ts +++ b/samples/client/petstore/typescript-node/api.ts @@ -8,181 +8,69 @@ import http = require('http'); /* tslint:disable:no-unused-variable */ - - - export class User { - - id: number; - - username: string; - - firstName: string; - - lastName: string; - - email: string; - - password: string; - - phone: string; - - /** * User Status */ - userStatus: number; - } - - - - - export class Category { - - id: number; - - name: string; - } - - - - - export class Pet { - - id: number; - - category: Category; - - name: string; - - photoUrls: Array; - - tags: Array; - - /** * pet status in the store */ - status: Pet.StatusEnum; - } - export namespace Pet { - - - - - - - - - - - - export enum StatusEnum { available = 'available', pending = 'pending', sold = 'sold', } - - } - - - - - export class Tag { - - id: number; - - name: string; - } - - - - - export class Order { - - id: number; - - petId: number; - - quantity: number; - - shipDate: Date; - - /** * Order Status */ - status: Order.StatusEnum; - - complete: boolean; - } - export namespace Order { - - - - - - - - - - export enum StatusEnum { placed = 'placed', approved = 'approved', delivered = 'delivered', } - - - - } - - - interface Authentication { /** * Apply authentication settings to header and query params. @@ -229,10 +117,6 @@ class VoidAuth implements Authentication { } } - - - - export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -241,34 +125,13 @@ export class UserApi { public authentications = { 'default': new VoidAuth(), - - - - - 'petstore_auth': new OAuth(), - - - - 'api_key': new ApiKeyAuth('header', 'api_key'), - - - + 'petstore_auth': new OAuth(), } constructor(url: string, basePath?: string); - - - - - constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { if (password) { - - - - - if (basePath) { this.basePath = basePath; } @@ -279,20 +142,9 @@ export class UserApi { } } - - - - - - - - set apiKey(key: string) { this.authentications.api_key.apiKey = key; } - - - private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -302,7 +154,6 @@ export class UserApi { return objA; } - public createUser (body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user'; let queryParameters: any = {}; @@ -310,11 +161,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -323,12 +171,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -354,7 +199,6 @@ export class UserApi { return deferred.promise; } - public createUsersWithArrayInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithArray'; let queryParameters: any = {}; @@ -362,11 +206,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -375,12 +216,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -406,7 +244,6 @@ export class UserApi { return deferred.promise; } - public createUsersWithListInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithList'; let queryParameters: any = {}; @@ -414,11 +251,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -427,12 +261,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -458,7 +289,6 @@ export class UserApi { return deferred.promise; } - public loginUser (username?: string, password?: string) : Promise<{ response: http.ClientResponse; body: string; }> { const path = this.url + this.basePath + '/user/login'; let queryParameters: any = {}; @@ -466,21 +296,16 @@ export class UserApi { let formParams: any = {}; - if (username !== undefined) { queryParameters['username'] = username; } - if (password !== undefined) { queryParameters['password'] = password; } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); let requestOptions: request.Options = { @@ -489,10 +314,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -518,7 +341,6 @@ export class UserApi { return deferred.promise; } - public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/logout'; let queryParameters: any = {}; @@ -526,11 +348,8 @@ export class UserApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -539,10 +358,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -568,7 +385,6 @@ export class UserApi { return deferred.promise; } - public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -582,11 +398,8 @@ export class UserApi { throw new Error('Missing required parameter username when calling getUserByName'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); let requestOptions: request.Options = { @@ -595,10 +408,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -624,7 +435,6 @@ export class UserApi { return deferred.promise; } - public updateUser (username: string, body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -638,11 +448,8 @@ export class UserApi { throw new Error('Missing required parameter username when calling updateUser'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -651,12 +458,9 @@ export class UserApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -682,7 +486,6 @@ export class UserApi { return deferred.promise; } - public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -696,11 +499,8 @@ export class UserApi { throw new Error('Missing required parameter username when calling deleteUser'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -709,10 +509,8 @@ export class UserApi { headers: headerParams, uri: path, json: true, - } - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -737,303 +535,7 @@ export class UserApi { return deferred.promise; } - } - - - - -export class StoreApi { - protected basePath = 'http://petstore.swagger.io/v2'; - protected defaultHeaders : any = {}; - - - - public authentications = { - 'default': new VoidAuth(), - - - - - 'petstore_auth': new OAuth(), - - - - - 'api_key': new ApiKeyAuth('header', 'api_key'), - - - - } - - constructor(url: string, basePath?: string); - - - - - - constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { - if (password) { - - - - - - if (basePath) { - this.basePath = basePath; - } - } else { - if (basePathOrUsername) { - this.basePath = basePathOrUsername - } - } - } - - - - - - - - - - set apiKey(key: string) { - this.authentications.api_key.apiKey = key; - } - - - - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - objA[key] = objB[key]; - } - } - return objA; - } - - - public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { - const path = this.url + this.basePath + '/store/inventory'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); - - let requestOptions: request.Options = { - method: 'GET', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - - } - - - this.authentications.api_key.applyToRequest(requestOptions); - - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - - public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { - const path = this.url + this.basePath + '/store/order'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); - - let requestOptions: request.Options = { - method: 'POST', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - - body: body, - - } - - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - - public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { - const path = this.url + this.basePath + '/store/order/{orderId}' - .replace('{' + 'orderId' + '}', String(orderId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'orderId' is set - if (!orderId) { - throw new Error('Missing required parameter orderId when calling getOrderById'); - } - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); - - let requestOptions: request.Options = { - method: 'GET', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - - } - - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - - public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/store/order/{orderId}' - .replace('{' + 'orderId' + '}', String(orderId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'orderId' is set - if (!orderId) { - throw new Error('Missing required parameter orderId when calling deleteOrder'); - } - - - - let useFormData = false; - - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'DELETE', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - - } - - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - -} - - - - export class PetApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -1042,34 +544,13 @@ export class PetApi { public authentications = { 'default': new VoidAuth(), - - - - - 'petstore_auth': new OAuth(), - - - - 'api_key': new ApiKeyAuth('header', 'api_key'), - - - + 'petstore_auth': new OAuth(), } constructor(url: string, basePath?: string); - - - - - constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { if (password) { - - - - - if (basePath) { this.basePath = basePath; } @@ -1080,20 +561,9 @@ export class PetApi { } } - - - - - - - - set apiKey(key: string) { this.authentications.api_key.apiKey = key; } - - - private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -1103,7 +573,6 @@ export class PetApi { return objA; } - public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet'; let queryParameters: any = {}; @@ -1111,11 +580,8 @@ export class PetApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1124,15 +590,11 @@ export class PetApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1158,7 +620,6 @@ export class PetApi { return deferred.promise; } - public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet'; let queryParameters: any = {}; @@ -1166,11 +627,8 @@ export class PetApi { let formParams: any = {}; - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1179,15 +637,11 @@ export class PetApi { headers: headerParams, uri: path, json: true, - body: body, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1213,7 +667,6 @@ export class PetApi { return deferred.promise; } - public findPetsByStatus (status?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { const path = this.url + this.basePath + '/pet/findByStatus'; let queryParameters: any = {}; @@ -1221,16 +674,12 @@ export class PetApi { let formParams: any = {}; - if (status !== undefined) { queryParameters['status'] = status; } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); let requestOptions: request.Options = { @@ -1239,13 +688,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1271,7 +717,6 @@ export class PetApi { return deferred.promise; } - public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { const path = this.url + this.basePath + '/pet/findByTags'; let queryParameters: any = {}; @@ -1279,16 +724,12 @@ export class PetApi { let formParams: any = {}; - if (tags !== undefined) { queryParameters['tags'] = tags; } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); let requestOptions: request.Options = { @@ -1297,13 +738,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1329,7 +767,6 @@ export class PetApi { return deferred.promise; } - public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { const path = this.url + this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); @@ -1343,11 +780,8 @@ export class PetApi { throw new Error('Missing required parameter petId when calling getPetById'); } - - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); let requestOptions: request.Options = { @@ -1356,13 +790,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.api_key.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1388,7 +819,6 @@ export class PetApi { return deferred.promise; } - public updatePetWithForm (petId: string, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); @@ -1402,23 +832,16 @@ export class PetApi { throw new Error('Missing required parameter petId when calling updatePetWithForm'); } - - let useFormData = false; - if (name !== undefined) { formParams['name'] = name; } - - if (status !== undefined) { formParams['status'] = status; } - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1427,13 +850,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1459,7 +879,6 @@ export class PetApi { return deferred.promise; } - public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); @@ -1473,14 +892,10 @@ export class PetApi { throw new Error('Missing required parameter petId when calling deletePet'); } - - headerParams['api_key'] = apiKey; - let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1489,13 +904,10 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); - this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1521,7 +933,6 @@ export class PetApi { return deferred.promise; } - public uploadFile (petId: number, additionalMetadata?: string, file?: any) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', String(petId)); @@ -1535,25 +946,17 @@ export class PetApi { throw new Error('Missing required parameter petId when calling uploadFile'); } - - let useFormData = false; - if (additionalMetadata !== undefined) { formParams['additionalMetadata'] = additionalMetadata; } - - if (file !== undefined) { formParams['file'] = file; } - useFormData = true; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1562,12 +965,92 @@ export class PetApi { headers: headerParams, uri: path, json: true, - } - this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } +} +export class StoreApi { + protected basePath = 'http://petstore.swagger.io/v2'; + protected defaultHeaders : any = {}; + + + + public authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(url: string, basePath?: string); + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; + } + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { + const path = this.url + this.basePath + '/store/inventory'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); + + let requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.api_key.applyToRequest(requestOptions); this.authentications.default.applyToRequest(requestOptions); @@ -1594,7 +1077,148 @@ export class PetApi { return deferred.promise; } + public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { + const path = this.url + this.basePath + '/store/order'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + let requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + body: body, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { + const path = this.url + this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling getOrderById'); + } + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + let requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling deleteOrder'); + } + + let useFormData = false; + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'DELETE', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + } + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } } - - -