updated swagger-js

This commit is contained in:
Tony Tam
2014-08-02 15:24:51 -07:00
parent 0a52e344e7
commit 4ea20859c7
4 changed files with 85 additions and 90 deletions

View File

@@ -1,5 +1,5 @@
// swagger.js
// version 2.0.35
// version 2.0.36
var __bind = function(fn, me){
return function(){
@@ -1104,27 +1104,47 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
var body = params.body;
// encode the body for form submits
if (headers["Accept"] && headers["Accept"].indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
if (headers["Content-Type"]) {
var values = {};
var key;
for(key in formParams){
var param = formParams[key];
values[param.name] = param;
var i;
var operationParams = this.operation.parameters;
for(i = 0; i < operationParams.length; i++) {
var param = operationParams[i];
if(param.paramType === "form")
values[param.name] = param;
}
var encoded = "";
var key;
for(key in values) {
value = this.params[key];
if(typeof value !== 'undefined'){
if(encoded !== "")
encoded += "&";
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
if(headers["Content-Type"].indexOf("application/x-www-form-urlencoded") === 0) {
var encoded = "";
var key;
for(key in values) {
value = this.params[key];
if(typeof value !== 'undefined'){
if(encoded !== "")
encoded += "&";
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
}
body = encoded;
}
else if (headers["Content-Type"].indexOf("multipart/form-data") === 0) {
// encode the body for form submits
var data = "";
var boundary = "----SwaggerFormBoundary" + Date.now();
var key;
for(key in values) {
value = this.params[key];
if(typeof value !== 'undefined') {
data += '--' + boundary + '\n';
data += 'Content-Disposition: form-data; name="' + key + '"';
data += '\n\n';
data += value + "\n";
}
}
data += "--" + boundary + "--\n";
headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
body = data;
}
body = encoded;
}
if (!((this.headers != null) && (this.headers.mock != null))) {
@@ -1231,33 +1251,11 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
accepts = this.operation.produces[0];
}
}
if (consumes && consumes.indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
var values = {};
var key;
for(key in definedFormParams){
var param = definedFormParams[key];
values[param.name] = param;
}
var encoded = "";
var key;
for(key in values) {
value = this.params[key];
if(typeof value !== 'undefined'){
if(encoded !== "")
encoded += "&";
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
}
body = encoded;
}
if ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded"))
headers["Content-Type"] = consumes;
if (accepts)
headers["Accept"] = accepts;
return headers;
}
@@ -1603,4 +1601,3 @@ e.SwaggerModel = SwaggerModel;
e.SwaggerModelProperty = SwaggerModelProperty;
e.SwaggerResource = SwaggerResource;
e.SwaggerApi = SwaggerApi;