11// swagger.js
2- // version 2.0.34
2+ // version 2.0.36
33
44var __bind = function ( fn , me ) {
55 return function ( ) {
@@ -1104,27 +1104,47 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
11041104 var body = params . body ;
11051105
11061106 // encode the body for form submits
1107- if ( headers [ "Accept" ] && headers [ "Accept" ] . indexOf ( "application/x-www-form-urlencoded" ) === 0 ) {
1108- var fields = { } ;
1109- var possibleParams = { } ;
1107+ if ( headers [ "Content-Type" ] ) {
11101108 var values = { } ;
1111- var key ;
1112- for ( key in formParams ) {
1113- var param = formParams [ key ] ;
1114- values [ param . name ] = param ;
1109+ var i ;
1110+ var operationParams = this . operation . parameters ;
1111+ for ( i = 0 ; i < operationParams . length ; i ++ ) {
1112+ var param = operationParams [ i ] ;
1113+ if ( param . paramType === "form" )
1114+ values [ param . name ] = param ;
11151115 }
11161116
1117- var encoded = "" ;
1118- var key ;
1119- for ( key in values ) {
1120- value = this . params [ key ] ;
1121- if ( typeof value !== 'undefined' ) {
1122- if ( encoded !== "" )
1123- encoded += "&" ;
1124- encoded += encodeURIComponent ( key ) + '=' + encodeURIComponent ( value ) ;
1117+ if ( headers [ "Content-Type" ] . indexOf ( "application/x-www-form-urlencoded" ) === 0 ) {
1118+ var encoded = "" ;
1119+ var key ;
1120+ for ( key in values ) {
1121+ value = this . params [ key ] ;
1122+ if ( typeof value !== 'undefined' ) {
1123+ if ( encoded !== "" )
1124+ encoded += "&" ;
1125+ encoded += encodeURIComponent ( key ) + '=' + encodeURIComponent ( value ) ;
1126+ }
1127+ }
1128+ body = encoded ;
1129+ }
1130+ else if ( headers [ "Content-Type" ] . indexOf ( "multipart/form-data" ) === 0 ) {
1131+ // encode the body for form submits
1132+ var data = "" ;
1133+ var boundary = "----SwaggerFormBoundary" + Date . now ( ) ;
1134+ var key ;
1135+ for ( key in values ) {
1136+ value = this . params [ key ] ;
1137+ if ( typeof value !== 'undefined' ) {
1138+ data += '--' + boundary + '\n' ;
1139+ data += 'Content-Disposition: form-data; name="' + key + '"' ;
1140+ data += '\n\n' ;
1141+ data += value + "\n" ;
1142+ }
11251143 }
1144+ data += "--" + boundary + "--\n" ;
1145+ headers [ "Content-Type" ] = "multipart/form-data; boundary=" + boundary ;
1146+ body = data ;
11261147 }
1127- body = encoded ;
11281148 }
11291149
11301150 if ( ! ( ( this . headers != null ) && ( this . headers . mock != null ) ) ) {
@@ -1203,20 +1223,20 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
12031223 // if any form params, content type must be set
12041224 if ( definedFormParams . length > 0 ) {
12051225 if ( definedFileParams . length > 0 )
1206- accepts = "multipart/form-data" ;
1226+ consumes = "multipart/form-data" ;
12071227 else
1208- accepts = "application/x-www-form-urlencoded" ;
1228+ consumes = "application/x-www-form-urlencoded" ;
12091229 }
12101230 else if ( this . type == "DELETE" )
12111231 body = "{}" ;
12121232 else if ( this . type != "DELETE" )
12131233 accepts = null ;
12141234 }
12151235
1216- if ( contentType && this . operation . consumes ) {
1217- if ( this . operation . consumes . indexOf ( contentType ) === - 1 ) {
1218- log ( "server doesn't consume " + contentType + ", try " + JSON . stringify ( this . operation . consumes ) ) ;
1219- contentType = this . operation . consumes [ 0 ] ;
1236+ if ( consumes && this . operation . consumes ) {
1237+ if ( this . operation . consumes . indexOf ( consumes ) === - 1 ) {
1238+ log ( "server doesn't consume " + consumes + ", try " + JSON . stringify ( this . operation . consumes ) ) ;
1239+ consumes = this . operation . consumes [ 0 ] ;
12201240 }
12211241 }
12221242
@@ -1231,33 +1251,11 @@ SwaggerRequest.prototype.setHeaders = function(params, operation) {
12311251 accepts = this . operation . produces [ 0 ] ;
12321252 }
12331253 }
1234- if ( contentType && contentType . indexOf ( "application/x-www-form-urlencoded" ) === 0 ) {
1235- var fields = { } ;
1236- var possibleParams = { } ;
1237- var values = { } ;
1238- var key ;
1239- for ( key in formParams ) {
1240- var param = formParams [ key ] ;
1241- values [ param . name ] = param ;
1242- }
12431254
1244- var encoded = "" ;
1245- var key ;
1246- for ( key in values ) {
1247- value = this . params [ key ] ;
1248- if ( typeof value !== 'undefined' ) {
1249- if ( encoded !== "" )
1250- encoded += "&" ;
1251- encoded += encodeURIComponent ( key ) + '=' + encodeURIComponent ( value ) ;
1252- }
1253- }
1254- body = encoded ;
1255- }
1256- if ( ( contentType && body !== "" ) || ( contentType === "application/x-www-form-urlencoded" ) )
1257- headers [ "Content-Type" ] = contentType ;
1255+ if ( ( consumes && body !== "" ) || ( consumes === "application/x-www-form-urlencoded" ) )
1256+ headers [ "Content-Type" ] = consumes ;
12581257 if ( accepts )
12591258 headers [ "Accept" ] = accepts ;
1260-
12611259 return headers ;
12621260}
12631261
0 commit comments