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

2
dist/lib/swagger.js vendored
View File

@@ -904,6 +904,7 @@ SwaggerOperation.prototype.pathXml = function() {
SwaggerOperation.prototype.encodePathParam = function(pathParam) {
var encParts, part, parts, _i, _len;
pathParam = pathParam.toString();
if (pathParam.indexOf("/") === -1) {
return encodeURIComponent(pathParam);
} else {
@@ -1524,4 +1525,3 @@ e.SwaggerModel = SwaggerModel;
e.SwaggerModelProperty = SwaggerModelProperty;
e.SwaggerResource = SwaggerResource;
e.SwaggerApi = SwaggerApi;

11
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];
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;
};

File diff suppressed because one or more lines are too long

View File

@@ -904,6 +904,7 @@ SwaggerOperation.prototype.pathXml = function() {
SwaggerOperation.prototype.encodePathParam = function(pathParam) {
var encParts, part, parts, _i, _len;
pathParam = pathParam.toString();
if (pathParam.indexOf("/") === -1) {
return encodeURIComponent(pathParam);
} else {
@@ -1524,4 +1525,3 @@ e.SwaggerModel = SwaggerModel;
e.SwaggerModelProperty = SwaggerModelProperty;
e.SwaggerResource = SwaggerResource;
e.SwaggerApi = SwaggerApi;

View File

@@ -151,13 +151,13 @@ class OperationView extends Backbone.View
parent.showCompleteStatus response
handleFileUpload: (map, form) ->
log "it's a file upload"
for o in form.serializeArray()
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = o.value
# requires HTML5 compatible browser
bodyParam = new FormData()
params = 0
# add params
for param in @model.parameters
@@ -175,7 +175,9 @@ class OperationView extends Backbone.View
# add files
for el in form.find('input[type~="file"]')
if typeof el.files[0] isnt 'undefined'
bodyParam.append($(el).attr('name'), el.files[0])
params += 1
log(bodyParam)
@@ -207,6 +209,9 @@ class OperationView extends Backbone.View
if window.authorizations
window.authorizations.apply obj
if params is 0
obj.data.append("fake", "true");
jQuery.ajax(obj)
false
# end of file-upload nastiness