1
1
/**
2
2
* 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
4
4
* @link http://swagger.io
5
5
* @license apache 2.0
6
6
*/
@@ -346,8 +346,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
346
346
if ( options . authorizations ) {
347
347
this . clientAuthorizations = options . authorizations ;
348
348
} else {
349
- var e = ( typeof window !== 'undefined' ? window : exports ) ;
350
- this . clientAuthorizations = e . authorizations ;
349
+ this . clientAuthorizations = authorizations ;
351
350
}
352
351
353
352
this . supportedSubmitMethods = options . supportedSubmitMethods || [ ] ;
@@ -407,8 +406,7 @@ SwaggerClient.prototype.build = function(mock) {
407
406
setTimeout ( function ( ) { self . buildFromSpec ( self . spec ) ; } , 10 ) ;
408
407
}
409
408
else {
410
- var e = ( typeof window !== 'undefined' ? window : exports ) ;
411
- var status = e . authorizations . apply ( obj ) ;
409
+ authorizations . apply ( obj ) ;
412
410
if ( mock )
413
411
return obj ;
414
412
new SwaggerHttp ( ) . execute ( obj ) ;
@@ -833,7 +831,7 @@ Operation.prototype.help = function(dontPrint) {
833
831
var out = this . nickname + ': ' + this . summary + '\n' ;
834
832
for ( var i = 0 ; i < this . parameters . length ; i ++ ) {
835
833
var param = this . parameters [ i ] ;
836
- var typeInfo = typeFromJsonSchema ( param . type , param . format ) ;
834
+ var typeInfo = param . signature ;
837
835
out += '\n * ' + param . name + ' (' + typeInfo + '): ' + param . description ;
838
836
}
839
837
if ( typeof dontPrint === 'undefined' )
@@ -951,9 +949,8 @@ Operation.prototype.getMissingParams = function(args) {
951
949
return missingParams ;
952
950
} ;
953
951
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 ;
957
954
958
955
for ( var i = 0 ; i < this . parameters . length ; i ++ ) {
959
956
var param = this . parameters [ i ] ;
@@ -969,7 +966,6 @@ Operation.prototype.getBody = function(headers, args) {
969
966
// handle form params
970
967
if ( headers [ 'Content-Type' ] === 'application/x-www-form-urlencoded' ) {
971
968
var encoded = "" ;
972
- var key ;
973
969
for ( key in formParams ) {
974
970
value = formParams [ key ] ;
975
971
if ( typeof value !== 'undefined' ) {
@@ -980,6 +976,25 @@ Operation.prototype.getBody = function(headers, args) {
980
976
}
981
977
body = encoded ;
982
978
}
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
+ }
983
998
984
999
return body ;
985
1000
} ;
@@ -1042,9 +1057,8 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
1042
1057
success = ( success || log ) ;
1043
1058
error = ( error || log ) ;
1044
1059
1045
- if ( typeof opts . useJQuery === 'boolean' ) {
1060
+ if ( opts . useJQuery )
1046
1061
this . useJQuery = opts . useJQuery ;
1047
- }
1048
1062
1049
1063
var missingParams = this . getMissingParams ( args ) ;
1050
1064
if ( missingParams . length > 0 ) {
@@ -1059,7 +1073,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
1059
1073
for ( attrname in allHeaders ) { headers [ attrname ] = allHeaders [ attrname ] ; }
1060
1074
for ( attrname in contentTypeHeaders ) { headers [ attrname ] = contentTypeHeaders [ attrname ] ; }
1061
1075
1062
- var body = this . getBody ( headers , args ) ;
1076
+ var body = this . getBody ( headers , args , opts ) ;
1063
1077
var url = this . urlify ( args ) ;
1064
1078
1065
1079
var obj = {
@@ -1077,7 +1091,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
1077
1091
}
1078
1092
}
1079
1093
} ;
1080
- var status = e . authorizations . apply ( obj , this . operation . security ) ;
1094
+ var status = authorizations . apply ( obj , this . operation . security ) ;
1081
1095
if ( opts . mock === true )
1082
1096
return obj ;
1083
1097
else
@@ -1160,14 +1174,24 @@ Operation.prototype.setContentTypes = function(args, opts) {
1160
1174
} ;
1161
1175
1162
1176
Operation . prototype . asCurl = function ( args ) {
1177
+ var obj = this . execute ( args , { mock : true } ) ;
1178
+ authorizations . apply ( obj ) ;
1163
1179
var results = [ ] ;
1164
- var headers = this . getHeaderParams ( args ) ;
1165
- if ( headers ) {
1180
+ results . push ( '-X ' + this . method . toUpperCase ( ) ) ;
1181
+ if ( obj . headers ) {
1166
1182
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, '\\"' ) + '"' ) ;
1169
1193
}
1170
- return " curl " + ( results . join ( " " ) ) + " " + this . urlify ( args ) ;
1194
+ return ' curl ' + ( results . join ( ' ' ) ) + ' "' + obj . url + '"' ;
1171
1195
} ;
1172
1196
1173
1197
Operation . prototype . encodePathCollection = function ( type , name , value ) {
@@ -2812,7 +2836,14 @@ SwaggerHttp.prototype.execute = function(obj, opts) {
2812
2836
this . useJQuery = this . isIE8 ( ) ;
2813
2837
2814
2838
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
+ }
2816
2847
}
2817
2848
2818
2849
if ( this . useJQuery )
@@ -2853,7 +2884,9 @@ JQueryHttpClient.prototype.execute = function(obj) {
2853
2884
2854
2885
obj . type = obj . method ;
2855
2886
obj . cache = false ;
2887
+ delete obj . useJQuery ;
2856
2888
2889
+ /*
2857
2890
obj.beforeSend = function(xhr) {
2858
2891
var key, results;
2859
2892
if (obj.headers) {
@@ -2869,9 +2902,10 @@ JQueryHttpClient.prototype.execute = function(obj) {
2869
2902
}
2870
2903
return results;
2871
2904
}
2872
- } ;
2905
+ };*/
2873
2906
2874
2907
obj . data = obj . body ;
2908
+ delete obj . body ;
2875
2909
obj . complete = function ( response , textStatus , opts ) {
2876
2910
var headers = { } ,
2877
2911
headerArray = response . getAllResponseHeaders ( ) . split ( "\n" ) ;
@@ -3045,7 +3079,7 @@ ShredHttpClient.prototype.execute = function(obj) {
3045
3079
3046
3080
var e = ( typeof window !== 'undefined' ? window : exports ) ;
3047
3081
3048
- e . authorizations = new SwaggerAuthorizations ( ) ;
3082
+ e . authorizations = authorizations = new SwaggerAuthorizations ( ) ;
3049
3083
e . ApiKeyAuthorization = ApiKeyAuthorization ;
3050
3084
e . PasswordAuthorization = PasswordAuthorization ;
3051
3085
e . CookieAuthorization = CookieAuthorization ;
0 commit comments