Skip to content

Commit

Permalink
updated swagger-js
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Aug 2, 2014
1 parent 0a52e34 commit 4ea2085
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 90 deletions.
92 changes: 45 additions & 47 deletions dist/lib/swagger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swagger.js
// version 2.0.34
// version 2.0.36

var __bind = function(fn, me){
return function(){
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -1203,20 +1223,20 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
// if any form params, content type must be set
if(definedFormParams.length > 0) {
if(definedFileParams.length > 0)
accepts = "multipart/form-data";
consumes = "multipart/form-data";
else
accepts = "application/x-www-form-urlencoded";
consumes = "application/x-www-form-urlencoded";
}
else if (this.type == "DELETE")
body = "{}";
else if (this.type != "DELETE")
accepts = null;
}

if (contentType && this.operation.consumes) {
if (this.operation.consumes.indexOf(contentType) === -1) {
log("server doesn't consume " + contentType + ", try " + JSON.stringify(this.operation.consumes));
contentType = this.operation.consumes[0];
if (consumes && this.operation.consumes) {
if (this.operation.consumes.indexOf(consumes) === -1) {
log("server doesn't consume " + consumes + ", try " + JSON.stringify(this.operation.consumes));
consumes = this.operation.consumes[0];
}
}

Expand All @@ -1231,33 +1251,11 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
accepts = this.operation.produces[0];
}
}
if (contentType && contentType.indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
var values = {};
var key;
for(key in formParams){
var param = formParams[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 ((contentType && body !== "") || (contentType === "application/x-www-form-urlencoded"))
headers["Content-Type"] = contentType;
if ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded"))
headers["Content-Type"] = consumes;
if (accepts)
headers["Accept"] = accepts;

return headers;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/swagger-ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swagger-ui.js
// version 2.0.20
// version 2.0.21
$(function() {

// Helper function for vertically aligning DOM elements
Expand Down
77 changes: 37 additions & 40 deletions lib/swagger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swagger.js
// version 2.0.35
// version 2.0.36

var __bind = function(fn, me){
return function(){
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1603,4 +1601,3 @@ e.SwaggerModel = SwaggerModel;
e.SwaggerModelProperty = SwaggerModelProperty;
e.SwaggerResource = SwaggerResource;
e.SwaggerApi = SwaggerApi;

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-ui",
"version": "2.0.20",
"version": "2.0.21",
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"scripts": {
"build": "PATH=$PATH:./node_modules/.bin cake dist",
Expand All @@ -19,7 +19,7 @@
"readmeFilename": "README.md",
"dependencies": {
"coffee-script": "~1.6.3",
"swagger-client": "2.0.35",
"swagger-client": "2.0.36",
"handlebars": "~1.0.10",
"less": "~1.4.2"
}
Expand Down

0 comments on commit 4ea2085

Please sign in to comment.