From 2886ca0312a0b71600ab3bc3f019955e630a1e61 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Wed, 11 Nov 2015 11:54:42 +0100 Subject: [PATCH 1/2] Adds comments to TypeScript Generator --- .../src/main/resources/TypeScript-Angular/api.mustache | 7 ++++++- .../src/main/resources/TypeScript-node/api.mustache | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 000ed2707b3..fc787b6437f 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -33,7 +33,12 @@ namespace {{package}} { } {{#operation}} - + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}} + */ public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { const path = this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache index e2a440bb846..266dbaa412f 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -167,7 +167,12 @@ export class {{classname}} { return objA; } {{#operation}} - + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}} + */ public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { const path = this.url + this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; From 684062ccbfe613db778055b6b4e553957fbf46e0 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Wed, 11 Nov 2015 13:47:09 +0100 Subject: [PATCH 2/2] Updates samples --- .../typescript-angular/API/Client/Category.ts | 11 + .../typescript-angular/API/Client/Order.ts | 35 + .../typescript-angular/API/Client/Pet.ts | 35 + .../typescript-angular/API/Client/PetApi.ts | 146 ++ .../typescript-angular/API/Client/StoreApi.ts | 59 + .../typescript-angular/API/Client/Tag.ts | 11 + .../typescript-angular/API/Client/User.ts | 24 + .../typescript-angular/API/Client/UserApi.ts | 124 ++ .../typescript-angular/API/Client/api.d.ts | 30 +- .../client/petstore/typescript-node/api.ts | 1403 +++++++++++------ 10 files changed, 1416 insertions(+), 462 deletions(-) diff --git a/samples/client/petstore/typescript-angular/API/Client/Category.ts b/samples/client/petstore/typescript-angular/API/Client/Category.ts index a802fe4ebdf..5e0a12f2122 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Category.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Category.ts @@ -3,11 +3,22 @@ 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 1dd84e6d0ad..874efb18c7e 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Order.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Order.ts @@ -3,30 +3,65 @@ 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 60431f69c83..bf1560de85c 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Pet.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Pet.ts @@ -3,30 +3,65 @@ 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 7c89b754914..2e936fdddd1 100644 --- a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts @@ -2,9 +2,11 @@ /* 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 = {}; @@ -27,11 +29,25 @@ namespace API.Client { } + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + + */ 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, @@ -50,11 +66,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + + */ 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, @@ -73,15 +103,30 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + + */ 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, @@ -99,15 +144,30 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + + */ 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, @@ -125,16 +185,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + + */ 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, @@ -152,24 +227,49 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + + */ 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, @@ -188,18 +288,37 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + + */ 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, @@ -217,24 +336,49 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + + */ 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, @@ -252,5 +396,7 @@ 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 801a86a4a04..492ef6885fe 100644 --- a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts @@ -2,9 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ + namespace API.Client { 'use strict'; + export class StoreApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -27,11 +29,22 @@ namespace API.Client { } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + + */ 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, @@ -49,11 +62,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + + */ public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/store/order'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -72,16 +99,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + + */ public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); 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'); } + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -99,16 +141,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + + */ public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); 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'); } + + + + + + let httpRequestParams: any = { method: 'DELETE', url: path, @@ -125,5 +182,7 @@ namespace API.Client { 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 1c0284cce48..66666719d89 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Tag.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Tag.ts @@ -3,11 +3,22 @@ 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 7c2b0b78b0c..69e94835d30 100644 --- a/samples/client/petstore/typescript-angular/API/Client/User.ts +++ b/samples/client/petstore/typescript-angular/API/Client/User.ts @@ -3,26 +3,50 @@ 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 4deb8bc6ebe..036508eb69d 100644 --- a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts @@ -2,9 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ + namespace API.Client { 'use strict'; + export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -27,11 +29,25 @@ namespace API.Client { } + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + + */ 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, @@ -50,11 +66,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithArrayInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/createWithArray'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -73,11 +103,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithListInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/createWithList'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -96,19 +140,38 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + + */ public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/user/login'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + if (username !== undefined) { queryParameters['username'] = username; } + if (password !== undefined) { queryParameters['password'] = password; } + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -126,11 +189,22 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Logs out current logged in user session + * + + */ public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/logout'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -148,16 +222,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + + */ public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); 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'); } + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -175,16 +264,34 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + + */ public updateUser (username: string, body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); 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'); } + + + + + + + + let httpRequestParams: any = { method: 'PUT', url: path, @@ -203,16 +310,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + + */ public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); 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'); } + + + + + + let httpRequestParams: any = { method: 'DELETE', url: path, @@ -229,5 +351,7 @@ namespace API.Client { return this.$http(httpRequestParams); } + } } + diff --git a/samples/client/petstore/typescript-angular/API/Client/api.d.ts b/samples/client/petstore/typescript-angular/API/Client/api.d.ts index 19c60623dc9..7a4f79f38b1 100644 --- a/samples/client/petstore/typescript-angular/API/Client/api.d.ts +++ b/samples/client/petstore/typescript-angular/API/Client/api.d.ts @@ -1,9 +1,37 @@ + + /// + + + /// + + + /// + + + /// + + + /// + + + + + /// -/// + + + /// + + + +/// + + + diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts index 47026929d81..4728b6f8c14 100644 --- a/samples/client/petstore/typescript-node/api.ts +++ b/samples/client/petstore/typescript-node/api.ts @@ -8,69 +8,181 @@ 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 { + + + + +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. @@ -117,6 +229,10 @@ class VoidAuth implements Authentication { } } + + + + export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -125,13 +241,34 @@ export class UserApi { public authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), + + + + '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; } @@ -142,9 +279,20 @@ 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)){ @@ -154,6 +302,12 @@ export class UserApi { return objA; } + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + + */ public createUser (body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user'; let queryParameters: any = {}; @@ -161,8 +315,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -171,9 +328,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -199,6 +359,12 @@ export class UserApi { return deferred.promise; } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithArrayInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithArray'; let queryParameters: any = {}; @@ -206,8 +372,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -216,9 +385,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -244,6 +416,12 @@ export class UserApi { return deferred.promise; } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithListInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithList'; let queryParameters: any = {}; @@ -251,8 +429,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -261,9 +442,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -289,6 +473,13 @@ export class UserApi { return deferred.promise; } + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + + */ public loginUser (username?: string, password?: string) : Promise<{ response: http.ClientResponse; body: string; }> { const path = this.url + this.basePath + '/user/login'; let queryParameters: any = {}; @@ -296,16 +487,21 @@ 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 = { @@ -314,8 +510,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -341,6 +539,11 @@ export class UserApi { return deferred.promise; } + /** + * Logs out current logged in user session + * + + */ public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/logout'; let queryParameters: any = {}; @@ -348,8 +551,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -358,8 +564,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -385,6 +593,12 @@ export class UserApi { return deferred.promise; } + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + + */ public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -398,8 +612,11 @@ 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 = { @@ -408,8 +625,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -435,6 +654,13 @@ export class UserApi { return deferred.promise; } + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + + */ public updateUser (username: string, body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -448,8 +674,11 @@ 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 = { @@ -458,9 +687,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -486,6 +718,12 @@ export class UserApi { return deferred.promise; } + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + + */ public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -499,8 +737,11 @@ 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 = { @@ -509,8 +750,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -535,465 +778,12 @@ export class UserApi { return deferred.promise; } + } -export class PetApi { - 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 updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'PUT', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - body: body, - } - - 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; - } - - public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'POST', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - body: body, - } - - 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; - } - - public findPetsByStatus (status?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { - const path = this.url + this.basePath + '/pet/findByStatus'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - 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 = { - method: 'GET', - qs: queryParameters, - 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; - } - - public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { - const path = this.url + this.basePath + '/pet/findByTags'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - 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 = { - method: 'GET', - qs: queryParameters, - 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; - } - - public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { - const path = this.url + 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 getPetById'); - } - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); - - 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 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)); - 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'); - } - - 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 = { - method: 'POST', - qs: queryParameters, - 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; - } - - public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + 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 deletePet'); - } - - headerParams['api_key'] = apiKey; - - 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.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; - } - - 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)); - 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'); - } - - 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 = { - method: 'POST', - qs: queryParameters, - 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 = {}; @@ -1002,13 +792,34 @@ export class StoreApi { public authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), + + + + '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; } @@ -1019,9 +830,20 @@ export class StoreApi { } } + + + + + + + + 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)){ @@ -1031,6 +853,11 @@ export class StoreApi { return objA; } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + + */ public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { const path = this.url + this.basePath + '/store/inventory'; let queryParameters: any = {}; @@ -1038,8 +865,11 @@ export class StoreApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); let requestOptions: request.Options = { @@ -1048,10 +878,13 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + } + this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1077,6 +910,12 @@ export class StoreApi { return deferred.promise; } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + + */ public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { const path = this.url + this.basePath + '/store/order'; let queryParameters: any = {}; @@ -1084,8 +923,11 @@ export class StoreApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); let requestOptions: request.Options = { @@ -1094,9 +936,12 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1122,6 +967,12 @@ export class StoreApi { return deferred.promise; } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + + */ public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { const path = this.url + this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); @@ -1135,8 +986,11 @@ export class StoreApi { 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 = { @@ -1145,8 +999,10 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1172,6 +1028,12 @@ export class StoreApi { return deferred.promise; } + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + + */ public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); @@ -1185,8 +1047,11 @@ export class StoreApi { 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 = { @@ -1195,8 +1060,10 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1221,4 +1088,618 @@ export class StoreApi { return deferred.promise; } + } + + + + +export class PetApi { + 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; + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + + */ + public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'PUT', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + body: body, + + } + + + 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; + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + + */ + public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + body: body, + + } + + + 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; + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + + */ + public findPetsByStatus (status?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { + const path = this.url + this.basePath + '/pet/findByStatus'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + 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 = { + method: 'GET', + qs: queryParameters, + 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; + } + + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + + */ + public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { + const path = this.url + this.basePath + '/pet/findByTags'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + 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 = { + method: 'GET', + qs: queryParameters, + 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; + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + + */ + public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { + const path = this.url + 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 getPetById'); + } + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); + + 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; + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + + */ + 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)); + 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'); + } + + + + 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 = { + method: 'POST', + qs: queryParameters, + 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; + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + + */ + public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + 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 deletePet'); + } + + + + headerParams['api_key'] = apiKey; + + + 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.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; + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + + */ + 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)); + 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'); + } + + + + 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 = { + method: 'POST', + qs: queryParameters, + 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; + } + +} + + +