Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[typescript][jQuery] Fix promise resolution #581

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export class {{classname}} {
* @param {{paramName}} {{description}}
{{/allParams}}
*/
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};

let queryParameters: any = {};
Expand Down Expand Up @@ -229,12 +232,15 @@ export class {{classname}} {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand Down
112 changes: 80 additions & 32 deletions samples/client/petstore/typescript-jquery/default/api/PetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class PetApi {
* @summary Add a new pet to the store
* @param body Pet object that needs to be added to the store
*/
public addPet(body: models.Pet, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body?: any; }> {
public addPet(body: models.Pet, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet';

let queryParameters: any = {};
Expand Down Expand Up @@ -107,12 +110,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: any, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -123,7 +129,10 @@ export class PetApi {
* @param petId Pet id to delete
* @param apiKey
*/
public deletePet(petId: number, apiKey?: string, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body?: any; }> {
public deletePet(petId: number, apiKey?: string, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet/{petId}'.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
Expand Down Expand Up @@ -176,12 +185,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: any, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -191,7 +203,10 @@ export class PetApi {
* @summary Finds Pets by status
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body: Array<models.Pet>; }> {
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body: Array<models.Pet>; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet/findByStatus';

let queryParameters: any = {};
Expand Down Expand Up @@ -245,12 +260,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body: Array<models.Pet>; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: Array<models.Pet>, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -260,7 +278,10 @@ export class PetApi {
* @summary Finds Pets by tags
* @param tags Tags to filter by
*/
public findPetsByTags(tags: Array<string>, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body: Array<models.Pet>; }> {
public findPetsByTags(tags: Array<string>, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body: Array<models.Pet>; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet/findByTags';

let queryParameters: any = {};
Expand Down Expand Up @@ -314,12 +335,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body: Array<models.Pet>; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: Array<models.Pet>, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -329,7 +353,10 @@ export class PetApi {
* @summary Find pet by ID
* @param petId ID of pet to return
*/
public getPetById(petId: number, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body: models.Pet; }> {
public getPetById(petId: number, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body: models.Pet; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet/{petId}'.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
Expand Down Expand Up @@ -376,12 +403,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body: models.Pet; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: models.Pet, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -391,7 +421,10 @@ export class PetApi {
* @summary Update an existing pet
* @param body Pet object that needs to be added to the store
*/
public updatePet(body: models.Pet, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body?: any; }> {
public updatePet(body: models.Pet, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet';

let queryParameters: any = {};
Expand Down Expand Up @@ -447,12 +480,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: any, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -464,7 +500,10 @@ export class PetApi {
* @param name Updated name of the pet
* @param status Updated status of the pet
*/
public updatePetWithForm(petId: number, name?: string, status?: string, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body?: any; }> {
public updatePetWithForm(petId: number, name?: string, status?: string, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet/{petId}'.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
Expand Down Expand Up @@ -533,12 +572,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body?: any; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: any, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand All @@ -550,7 +592,10 @@ export class PetApi {
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQueryPromise<{ response: JQueryXHR; body: models.ApiResponse; }> {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, extraJQueryAjaxSettings?: JQueryAjaxSettings): JQuery.Promise<
{ response: JQueryXHR; body: models.ApiResponse; },
{ response: JQueryXHR; errorThrown: string }
> {
let localVarPath = this.basePath + '/pet/{petId}/uploadImage'.replace('{' + 'petId' + '}', encodeURIComponent(String(petId)));

let queryParameters: any = {};
Expand Down Expand Up @@ -617,12 +662,15 @@ export class PetApi {
requestOptions = (<any>Object).assign(requestOptions, this.defaultExtraJQueryAjaxSettings);
}

let dfd = $.Deferred();
let dfd = $.Deferred<
{ response: JQueryXHR; body: models.ApiResponse; },
{ response: JQueryXHR; errorThrown: string }
>();
$.ajax(requestOptions).then(
(data: models.ApiResponse, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve(jqXHR, data),
dfd.resolve({response: jqXHR, body: data),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject(xhr, errorThrown)
dfd.reject({response: xhr, errorThrown: errorThrown})
);
return dfd.promise();
}
Expand Down
Loading