mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
Fixed bugs in blob handling of jquery
This commit is contained in:
parent
277e4ed49d
commit
9b8e4c27c2
@ -21,14 +21,12 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
data: body
|
||||
};
|
||||
|
||||
/**
|
||||
* Allow receiving binary data with jquery ajax
|
||||
*
|
||||
* Source: https://keyangxiang.com/2017/09/01/HTML5-XHR-download-binary-content-as-Blob/
|
||||
*/
|
||||
requestOptions.beforeSend = (jqXHR: any, settings: any) => {
|
||||
settings.xhr().responseType = "blob";
|
||||
};
|
||||
// If we want a blob, we have to set the xhrFields' responseType AND add a
|
||||
// custom converter to overwrite the default deserialization of JQuery...
|
||||
requestOptions["xhrFields"] = { responseType: 'blob' };
|
||||
requestOptions["converters"] = {}
|
||||
requestOptions["converters"]["* blob"] = (result:any) => result;
|
||||
requestOptions["dataType"] = "blob";
|
||||
|
||||
|
||||
if (request.getHeaders()['Content-Type']) {
|
||||
@ -51,6 +49,7 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
if (body && body.constructor.name == "FormData") {
|
||||
requestOptions.contentType = false;
|
||||
}
|
||||
|
||||
const sentRequest = $.ajax(requestOptions);
|
||||
|
||||
const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
|
||||
|
@ -21,14 +21,12 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
data: body
|
||||
};
|
||||
|
||||
/**
|
||||
* Allow receiving binary data with jquery ajax
|
||||
*
|
||||
* Source: https://keyangxiang.com/2017/09/01/HTML5-XHR-download-binary-content-as-Blob/
|
||||
*/
|
||||
requestOptions.beforeSend = (jqXHR: any, settings: any) => {
|
||||
settings.xhr().responseType = "blob";
|
||||
};
|
||||
// If we want a blob, we have to set the xhrFields' responseType AND add a
|
||||
// custom converter to overwrite the default deserialization of JQuery...
|
||||
requestOptions["xhrFields"] = { responseType: 'blob' };
|
||||
requestOptions["converters"] = {}
|
||||
requestOptions["converters"]["* blob"] = (result:any) => result;
|
||||
requestOptions["dataType"] = "blob";
|
||||
|
||||
|
||||
if (request.getHeaders()['Content-Type']) {
|
||||
@ -51,6 +49,7 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
if (body && body.constructor.name == "FormData") {
|
||||
requestOptions.contentType = false;
|
||||
}
|
||||
|
||||
const sentRequest = $.ajax(requestOptions);
|
||||
|
||||
const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
|
||||
|
@ -17,7 +17,7 @@ for (let libName in libs) {
|
||||
return new Promise((resolve, reject) => {
|
||||
lib.send(requestContext).toPromise().then((resp: petstore.ResponseContext) => {
|
||||
assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200");
|
||||
return resp.body.text()
|
||||
return resp.body.text();
|
||||
}).then((txtBody: string) => {
|
||||
let body = JSON.parse(txtBody);
|
||||
assert.ok(body["headers"]);
|
||||
@ -46,7 +46,7 @@ for (let libName in libs) {
|
||||
lib.send(requestContext).toPromise().then(
|
||||
(resp: petstore.ResponseContext) => {
|
||||
assert.ok(resp.httpStatusCode, 200, "Expected status code to be 200");
|
||||
return resp.body.text()
|
||||
return resp.body.text();
|
||||
}).then((txtBody: any) => {
|
||||
let body = JSON.parse(txtBody);
|
||||
assert.ok(body["headers"]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user