diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java index 38c0c5307ba..a8d66491851 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -6,6 +6,8 @@ import io.swagger.models.properties.*; import java.util.*; import java.io.File; +import org.apache.commons.lang.StringUtils; + public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public CodegenType getTag() { @@ -15,14 +17,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp public AbstractTypeScriptClientCodegen() { super(); supportsInheritance = true; - reservedWords = new HashSet(Arrays.asList("abstract", - "continue", "for", "new", "switch", "assert", "default", "if", - "package", "synchronized", "do", "goto", "private", - "this", "break", "double", "implements", "protected", "throw", - "byte", "else", "import", "public", "throws", "case", "enum", - "instanceof", "return", "transient", "catch", "extends", "int", - "short", "try", "char", "final", "interface", "static", "void", - "class", "finally", "const", "super", "while")); + reservedWords = new HashSet(Arrays.asList("abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield")); languageSpecificPrimitives = new HashSet(Arrays.asList( "String", @@ -79,7 +74,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp return name; // camelize the variable name - // pet_id => PetId + // pet_id => petId name = camelize(name, true); // for reserved word or word starting with number, append _ @@ -141,4 +136,20 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp type = swaggerType; return type; } + + @Override + public String toOperationId(String operationId) { + // throw exception if method name is empty + if (StringUtils.isEmpty(operationId)) { + throw new RuntimeException("Empty method name (operationId) not allowed"); + } + + // method name cannot use reserved keyword, e.g. return + // append _ at the beginning, e.g. _return + if (reservedWords.contains(operationId)) { + return escapeReservedWord(camelize(sanitizeName(operationId), true)); + } + + return camelize(sanitizeName(operationId), true); + } } diff --git a/samples/client/petstore/typescript-angular/API/Client/Category.ts b/samples/client/petstore/typescript-angular/API/Client/Category.ts index 532d9bb0856..ad34870b31a 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Category.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Category.ts @@ -3,22 +3,11 @@ namespace API.Client { 'use strict'; - - - export interface Category { - - id: number; - - name: string; - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/Order.ts b/samples/client/petstore/typescript-angular/API/Client/Order.ts index 11a0fafe293..dfffcd3d828 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Order.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Order.ts @@ -3,65 +3,30 @@ namespace API.Client { 'use strict'; - - - export interface 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', } - - - - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/Pet.ts b/samples/client/petstore/typescript-angular/API/Client/Pet.ts index acbb6bcb6c2..fa86c457fcf 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Pet.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Pet.ts @@ -3,65 +3,30 @@ namespace API.Client { 'use strict'; - - - export interface 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', } - - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts index 6e7dd50c6aa..7c89b754914 100644 --- a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts @@ -2,11 +2,9 @@ /* tslint:disable:no-unused-variable member-ordering */ - namespace API.Client { 'use strict'; - export class PetApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -29,20 +27,11 @@ namespace API.Client { } - public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'PUT', url: path, @@ -61,20 +50,11 @@ namespace API.Client { return this.$http(httpRequestParams); } - public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - - - - let httpRequestParams: any = { method: 'POST', url: path, @@ -93,25 +73,15 @@ namespace API.Client { return this.$http(httpRequestParams); } - public findPetsByStatus (status?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { const path = this.basePath + '/pet/findByStatus'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - if (status !== undefined) { queryParameters['status'] = status; } - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -129,25 +99,15 @@ namespace API.Client { return this.$http(httpRequestParams); } - public findPetsByTags (tags?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { const path = this.basePath + '/pet/findByTags'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - - - if (tags !== undefined) { queryParameters['tags'] = tags; } - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -165,26 +125,16 @@ namespace API.Client { return this.$http(httpRequestParams); } - public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling getPetById'); } - - - - - - let httpRequestParams: any = { method: 'GET', url: path, @@ -202,42 +152,24 @@ namespace API.Client { return this.$http(httpRequestParams); } - public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling updatePetWithForm'); } - - - - - - - - - headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - - formParams['name'] = name; - formParams['status'] = status; - let httpRequestParams: any = { method: 'POST', url: path, @@ -256,31 +188,18 @@ namespace API.Client { return this.$http(httpRequestParams); } - public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling deletePet'); } - - - - - - headerParams['api_key'] = apiKey; - - - let httpRequestParams: any = { method: 'DELETE', url: path, @@ -298,42 +217,24 @@ namespace API.Client { return this.$http(httpRequestParams); } - public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling uploadFile'); } - - - - - - - - - headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - - formParams['additionalMetadata'] = additionalMetadata; - formParams['file'] = file; - let httpRequestParams: any = { method: 'POST', url: path, @@ -351,7 +252,5 @@ namespace API.Client { return this.$http(httpRequestParams); } - } } - diff --git a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts index 739f6039e6c..801a86a4a04 100644 --- a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts @@ -2,26 +2,37 @@ /* tslint:disable:no-unused-variable member-ordering */ -module API.Client { +namespace API.Client { 'use strict'; export class StoreApi { - private basePath = 'http://petstore.swagger.io/v2'; + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders : any = {}; static $inject: string[] = ['$http', '$httpParamSerializer']; - constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) { + constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) { if (basePath) { this.basePath = basePath; } } - public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> { - var path = this.basePath + '/store/inventory'; + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } - var queryParameters: any = {}; - var headerParams: any = {}; - var httpRequestParams: any = { + + public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> { + const path = this.basePath + '/store/inventory'; + + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let httpRequestParams: any = { method: 'GET', url: path, json: true, @@ -32,22 +43,18 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise { - var path = this.basePath + '/store/order'; + const path = this.basePath + '/store/order'; - var queryParameters: any = {}; - var headerParams: any = {}; - var httpRequestParams: any = { + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let httpRequestParams: any = { method: 'POST', url: path, json: true, @@ -59,29 +66,23 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { - var path = this.basePath + '/store/order/{orderId}'; + const path = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); - path = path.replace('{' + 'orderId' + '}', String(orderId)); - - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); // verify required parameter 'orderId' is set if (!orderId) { throw new Error('Missing required parameter orderId when calling getOrderById'); } - - var httpRequestParams: any = { + let httpRequestParams: any = { method: 'GET', url: path, json: true, @@ -92,29 +93,23 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/store/order/{orderId}'; + const path = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); - path = path.replace('{' + 'orderId' + '}', String(orderId)); - - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); // verify required parameter 'orderId' is set if (!orderId) { throw new Error('Missing required parameter orderId when calling deleteOrder'); } - - var httpRequestParams: any = { + let httpRequestParams: any = { method: 'DELETE', url: path, json: true, @@ -125,11 +120,7 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); diff --git a/samples/client/petstore/typescript-angular/API/Client/Tag.ts b/samples/client/petstore/typescript-angular/API/Client/Tag.ts index 525d5ff8ab1..d206559a0ef 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Tag.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Tag.ts @@ -3,22 +3,11 @@ namespace API.Client { 'use strict'; - - - export interface Tag { - - id: number; - - name: string; - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/User.ts b/samples/client/petstore/typescript-angular/API/Client/User.ts index 274b2e866e3..e60f84bb6c6 100644 --- a/samples/client/petstore/typescript-angular/API/Client/User.ts +++ b/samples/client/petstore/typescript-angular/API/Client/User.ts @@ -3,50 +3,26 @@ namespace API.Client { 'use strict'; - - - export interface User { - - id: number; - - username: string; - - firstName: string; - - lastName: string; - - email: string; - - password: string; - - phone: string; - - /** * User Status */ - userStatus: number; - } - - - } diff --git a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts index 26ebd693db9..4deb8bc6ebe 100644 --- a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts @@ -2,26 +2,37 @@ /* tslint:disable:no-unused-variable member-ordering */ -module API.Client { +namespace API.Client { 'use strict'; export class UserApi { - private basePath = 'http://petstore.swagger.io/v2'; + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders : any = {}; static $inject: string[] = ['$http', '$httpParamSerializer']; - constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) { + constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) { if (basePath) { this.basePath = basePath; } } - public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/user'; + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } - var queryParameters: any = {}; - var headerParams: any = {}; - var httpRequestParams: any = { + + public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { + const path = this.basePath + '/user'; + + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let httpRequestParams: any = { method: 'POST', url: path, json: true, @@ -33,22 +44,18 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public createUsersWithArrayInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/user/createWithArray'; + const path = this.basePath + '/user/createWithArray'; - var queryParameters: any = {}; - var headerParams: any = {}; - var httpRequestParams: any = { + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let httpRequestParams: any = { method: 'POST', url: path, json: true, @@ -60,22 +67,18 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public createUsersWithListInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/user/createWithList'; + const path = this.basePath + '/user/createWithList'; - var queryParameters: any = {}; - var headerParams: any = {}; - var httpRequestParams: any = { + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let httpRequestParams: any = { method: 'POST', url: path, json: true, @@ -87,21 +90,17 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { - var path = this.basePath + '/user/login'; + const path = this.basePath + '/user/login'; - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); if (username !== undefined) { queryParameters['username'] = username; } @@ -110,7 +109,7 @@ module API.Client { queryParameters['password'] = password; } - var httpRequestParams: any = { + let httpRequestParams: any = { method: 'GET', url: path, json: true, @@ -121,22 +120,18 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/user/logout'; + const path = this.basePath + '/user/logout'; - var queryParameters: any = {}; - var headerParams: any = {}; - var httpRequestParams: any = { + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let httpRequestParams: any = { method: 'GET', url: path, json: true, @@ -147,29 +142,23 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { - var path = this.basePath + '/user/{username}'; + const path = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); - path = path.replace('{' + 'username' + '}', String(username)); - - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling getUserByName'); } - - var httpRequestParams: any = { + let httpRequestParams: any = { method: 'GET', url: path, json: true, @@ -180,29 +169,23 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public updateUser (username: string, body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/user/{username}'; + const path = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); - path = path.replace('{' + 'username' + '}', String(username)); - - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling updateUser'); } - - var httpRequestParams: any = { + let httpRequestParams: any = { method: 'PUT', url: path, json: true, @@ -214,29 +197,23 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); } public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { - var path = this.basePath + '/user/{username}'; + const path = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); - path = path.replace('{' + 'username' + '}', String(username)); - - var queryParameters: any = {}; - var headerParams: any = {}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling deleteUser'); } - - var httpRequestParams: any = { + let httpRequestParams: any = { method: 'DELETE', url: path, json: true, @@ -247,11 +224,7 @@ module API.Client { }; if (extraHttpRequestParams) { - for (var k in extraHttpRequestParams) { - if (extraHttpRequestParams.hasOwnProperty(k)) { - httpRequestParams[k] = extraHttpRequestParams[k]; - } - } + httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams); } return this.$http(httpRequestParams); 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; + } } - - -