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