11/**
22 * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
3- * @version v2.1.7 -M1
3+ * @version v2.1.8 -M1
44 * @link http://swagger.io
55 * @license apache 2.0
66 */
@@ -346,8 +346,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
346346 if ( options . authorizations ) {
347347 this . clientAuthorizations = options . authorizations ;
348348 } else {
349- var e = ( typeof window !== 'undefined' ? window : exports ) ;
350- this . clientAuthorizations = e . authorizations ;
349+ this . clientAuthorizations = authorizations ;
351350 }
352351
353352 this . supportedSubmitMethods = options . supportedSubmitMethods || [ ] ;
@@ -407,8 +406,7 @@ SwaggerClient.prototype.build = function(mock) {
407406 setTimeout ( function ( ) { self . buildFromSpec ( self . spec ) ; } , 10 ) ;
408407 }
409408 else {
410- var e = ( typeof window !== 'undefined' ? window : exports ) ;
411- var status = e . authorizations . apply ( obj ) ;
409+ authorizations . apply ( obj ) ;
412410 if ( mock )
413411 return obj ;
414412 new SwaggerHttp ( ) . execute ( obj ) ;
@@ -833,7 +831,7 @@ Operation.prototype.help = function(dontPrint) {
833831 var out = this . nickname + ': ' + this . summary + '\n' ;
834832 for ( var i = 0 ; i < this . parameters . length ; i ++ ) {
835833 var param = this . parameters [ i ] ;
836- var typeInfo = typeFromJsonSchema ( param . type , param . format ) ;
834+ var typeInfo = param . signature ;
837835 out += '\n * ' + param . name + ' (' + typeInfo + '): ' + param . description ;
838836 }
839837 if ( typeof dontPrint === 'undefined' )
@@ -951,9 +949,8 @@ Operation.prototype.getMissingParams = function(args) {
951949 return missingParams ;
952950} ;
953951
954- Operation . prototype . getBody = function ( headers , args ) {
955- var formParams = { } ;
956- var body ;
952+ Operation . prototype . getBody = function ( headers , args , opts ) {
953+ var formParams = { } , body , key ;
957954
958955 for ( var i = 0 ; i < this . parameters . length ; i ++ ) {
959956 var param = this . parameters [ i ] ;
@@ -969,7 +966,6 @@ Operation.prototype.getBody = function(headers, args) {
969966 // handle form params
970967 if ( headers [ 'Content-Type' ] === 'application/x-www-form-urlencoded' ) {
971968 var encoded = "" ;
972- var key ;
973969 for ( key in formParams ) {
974970 value = formParams [ key ] ;
975971 if ( typeof value !== 'undefined' ) {
@@ -980,6 +976,25 @@ Operation.prototype.getBody = function(headers, args) {
980976 }
981977 body = encoded ;
982978 }
979+ else if ( headers [ 'Content-Type' ] && headers [ 'Content-Type' ] . indexOf ( 'multipart/form-data' ) >= 0 ) {
980+ if ( opts . useJQuery ) {
981+ var bodyParam = new FormData ( ) ;
982+ bodyParam . type = 'formData' ;
983+ for ( key in formParams ) {
984+ value = args [ key ] ;
985+ if ( typeof value !== 'undefined' ) {
986+ // required for jquery file upload
987+ if ( value . type === 'file' && value . value ) {
988+ delete headers [ 'Content-Type' ] ;
989+ bodyParam . append ( key , value . value ) ;
990+ }
991+ else
992+ bodyParam . append ( key , value ) ;
993+ }
994+ }
995+ body = bodyParam ;
996+ }
997+ }
983998
984999 return body ;
9851000} ;
@@ -1042,9 +1057,8 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
10421057 success = ( success || log ) ;
10431058 error = ( error || log ) ;
10441059
1045- if ( typeof opts . useJQuery === 'boolean' ) {
1060+ if ( opts . useJQuery )
10461061 this . useJQuery = opts . useJQuery ;
1047- }
10481062
10491063 var missingParams = this . getMissingParams ( args ) ;
10501064 if ( missingParams . length > 0 ) {
@@ -1059,7 +1073,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
10591073 for ( attrname in allHeaders ) { headers [ attrname ] = allHeaders [ attrname ] ; }
10601074 for ( attrname in contentTypeHeaders ) { headers [ attrname ] = contentTypeHeaders [ attrname ] ; }
10611075
1062- var body = this . getBody ( headers , args ) ;
1076+ var body = this . getBody ( headers , args , opts ) ;
10631077 var url = this . urlify ( args ) ;
10641078
10651079 var obj = {
@@ -1077,7 +1091,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
10771091 }
10781092 }
10791093 } ;
1080- var status = e . authorizations . apply ( obj , this . operation . security ) ;
1094+ var status = authorizations . apply ( obj , this . operation . security ) ;
10811095 if ( opts . mock === true )
10821096 return obj ;
10831097 else
@@ -1160,14 +1174,24 @@ Operation.prototype.setContentTypes = function(args, opts) {
11601174} ;
11611175
11621176Operation . prototype . asCurl = function ( args ) {
1177+ var obj = this . execute ( args , { mock : true } ) ;
1178+ authorizations . apply ( obj ) ;
11631179 var results = [ ] ;
1164- var headers = this . getHeaderParams ( args ) ;
1165- if ( headers ) {
1180+ results . push ( '-X ' + this . method . toUpperCase ( ) ) ;
1181+ if ( obj . headers ) {
11661182 var key ;
1167- for ( key in headers )
1168- results . push ( "--header \"" + key + ": " + headers [ key ] + "\"" ) ;
1183+ for ( key in obj . headers )
1184+ results . push ( '--header "' + key + ': ' + obj . headers [ key ] + '"' ) ;
1185+ }
1186+ if ( obj . body ) {
1187+ var body ;
1188+ if ( typeof obj . body === 'object' )
1189+ body = JSON . stringify ( obj . body ) ;
1190+ else
1191+ body = obj . body ;
1192+ results . push ( '-d "' + body . replace ( / " / g, '\\"' ) + '"' ) ;
11691193 }
1170- return " curl " + ( results . join ( " " ) ) + " " + this . urlify ( args ) ;
1194+ return ' curl ' + ( results . join ( ' ' ) ) + ' "' + obj . url + '"' ;
11711195} ;
11721196
11731197Operation . prototype . encodePathCollection = function ( type , name , value ) {
@@ -2812,7 +2836,14 @@ SwaggerHttp.prototype.execute = function(obj, opts) {
28122836 this . useJQuery = this . isIE8 ( ) ;
28132837
28142838 if ( obj && typeof obj . body === 'object' ) {
2815- obj . body = JSON . stringify ( obj . body ) ;
2839+ if ( obj . body . type && obj . body . type !== 'formData' )
2840+ obj . body = JSON . stringify ( obj . body ) ;
2841+ else {
2842+ obj . contentType = false ;
2843+ obj . processData = false ;
2844+ // delete obj.cache;
2845+ delete obj . headers [ 'Content-Type' ] ;
2846+ }
28162847 }
28172848
28182849 if ( this . useJQuery )
@@ -2853,7 +2884,9 @@ JQueryHttpClient.prototype.execute = function(obj) {
28532884
28542885 obj . type = obj . method ;
28552886 obj . cache = false ;
2887+ delete obj . useJQuery ;
28562888
2889+ /*
28572890 obj.beforeSend = function(xhr) {
28582891 var key, results;
28592892 if (obj.headers) {
@@ -2869,9 +2902,10 @@ JQueryHttpClient.prototype.execute = function(obj) {
28692902 }
28702903 return results;
28712904 }
2872- } ;
2905+ };*/
28732906
28742907 obj . data = obj . body ;
2908+ delete obj . body ;
28752909 obj . complete = function ( response , textStatus , opts ) {
28762910 var headers = { } ,
28772911 headerArray = response . getAllResponseHeaders ( ) . split ( "\n" ) ;
@@ -3045,7 +3079,7 @@ ShredHttpClient.prototype.execute = function(obj) {
30453079
30463080var e = ( typeof window !== 'undefined' ? window : exports ) ;
30473081
3048- e . authorizations = new SwaggerAuthorizations ( ) ;
3082+ e . authorizations = authorizations = new SwaggerAuthorizations ( ) ;
30493083e . ApiKeyAuthorization = ApiKeyAuthorization ;
30503084e . PasswordAuthorization = PasswordAuthorization ;
30513085e . CookieAuthorization = CookieAuthorization ;
0 commit comments