fix for upload with no files

This commit is contained in:
Tony Tam
2014-05-14 09:45:18 -04:00
parent f7694d8525
commit 05588bb669
5 changed files with 20 additions and 8 deletions

13
dist/swagger-ui.js vendored
View File

@@ -1,4 +1,5 @@
// swagger-ui.js
$(function() {
// Helper function for vertically aligning DOM elements
@@ -1731,9 +1732,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
};
OperationView.prototype.handleFileUpload = function(map, form) {
var bodyParam, el, headerParams, o, obj, param, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8,
var bodyParam, el, headerParams, o, obj, param, params, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8,
_this = this;
log("it's a file upload");
_ref5 = form.serializeArray();
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
o = _ref5[_i];
@@ -1742,6 +1742,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
}
}
bodyParam = new FormData();
params = 0;
_ref6 = this.model.parameters;
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
param = _ref6[_j];
@@ -1763,7 +1764,10 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
_ref8 = form.find('input[type~="file"]');
for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) {
el = _ref8[_l];
bodyParam.append($(el).attr('name'), el.files[0]);
if (typeof el.files[0] !== 'undefined') {
bodyParam.append($(el).attr('name'), el.files[0]);
params += 1;
}
}
log(bodyParam);
this.invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), this.model.urlify(map, false)) : this.model.urlify(map, true);
@@ -1789,6 +1793,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
if (window.authorizations) {
window.authorizations.apply(obj);
}
if (params === 0) {
obj.data.append("fake", "true");
}
jQuery.ajax(obj);
return false;
};