1
1
// swagger.js
2
- // version 2.0.30
2
+ // version 2.0.31
3
3
4
4
var __bind = function ( fn , me ) {
5
5
return function ( ) {
@@ -57,24 +57,24 @@ Object.keys = Object.keys || (function () {
57
57
'constructor'
58
58
] ,
59
59
DontEnumsLength = DontEnums . length ;
60
-
60
+
61
61
return function ( o ) {
62
62
if ( typeof o != "object" && typeof o != "function" || o === null )
63
63
throw new TypeError ( "Object.keys called on a non-object" ) ;
64
-
64
+
65
65
var result = [ ] ;
66
66
for ( var name in o ) {
67
67
if ( hasOwnProperty . call ( o , name ) )
68
68
result . push ( name ) ;
69
69
}
70
-
70
+
71
71
if ( hasDontEnumBug ) {
72
72
for ( var i = 0 ; i < DontEnumsLength ; i ++ ) {
73
73
if ( hasOwnProperty . call ( o , DontEnums [ i ] ) )
74
74
result . push ( DontEnums [ i ] ) ;
75
- }
75
+ }
76
76
}
77
-
77
+
78
78
return result ;
79
79
} ;
80
80
} ) ( ) ;
@@ -87,6 +87,7 @@ var SwaggerApi = function(url, options) {
87
87
this . authorizations = null ;
88
88
this . authorizationScheme = null ;
89
89
this . info = null ;
90
+ this . useJQuery = false ;
90
91
91
92
options = ( options || { } ) ;
92
93
if ( url )
@@ -103,6 +104,9 @@ var SwaggerApi = function(url, options) {
103
104
if ( options . success != null )
104
105
this . success = options . success ;
105
106
107
+ if ( typeof options . useJQuery === 'boolean' )
108
+ this . useJQuery = options . useJQuery ;
109
+
106
110
this . failure = options . failure != null ? options . failure : function ( ) { } ;
107
111
this . progress = options . progress != null ? options . progress : function ( ) { } ;
108
112
if ( options . success != null )
@@ -432,7 +436,6 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
432
436
output = [ ] ;
433
437
for ( var i = 0 ; i < ops . length ; i ++ ) {
434
438
o = ops [ i ] ;
435
-
436
439
consumes = this . consumes ;
437
440
produces = this . produces ;
438
441
if ( o . consumes != null )
@@ -479,8 +482,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
479
482
480
483
SwaggerResource . prototype . sanitize = function ( nickname ) {
481
484
var op ;
482
- op = nickname . replace ( / [ \s ! @ # $ % ^ & * ( ) _ + = \[ { \] } ; : < > | . / ? , \\ ' " " - ] / g, '_' ) ;
483
- //'
485
+ op = nickname . replace ( / [ \s ! @ # $ % ^ & * ( ) _ + = \[ { \] } ; : < > | . \/ ? , \\ ' " " - ] / g, '_' ) ;
484
486
op = op . replace ( / ( ( _ ) { 2 , } ) / g, '_' ) ;
485
487
op = op . replace ( / ^ ( _ ) * / g, '' ) ;
486
488
op = op . replace ( / ( [ _ ] ) * $ / g, '' ) ;
@@ -675,7 +677,6 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
675
677
this . resource = ( resource || errors . push ( "Resource is required" ) ) ;
676
678
this . consumes = consumes ;
677
679
this . produces = produces ;
678
-
679
680
this . authorizations = authorizations ;
680
681
this [ "do" ] = __bind ( this [ "do" ] , this ) ;
681
682
@@ -814,7 +815,7 @@ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
814
815
else
815
816
return JSON . stringify ( val , null , 2 ) ;
816
817
}
817
- else
818
+ else
818
819
return val ;
819
820
}
820
821
} ;
@@ -1075,7 +1076,7 @@ SwaggerOperation.prototype.formatXml = function(xml) {
1075
1076
var SwaggerRequest = function ( type , url , params , opts , successCallback , errorCallback , operation , execution ) {
1076
1077
var _this = this ;
1077
1078
var errors = [ ] ;
1078
- this . useJQuery = ( typeof operation . useJQuery !== 'undefined' ? operation . useJQuery : null ) ;
1079
+ this . useJQuery = ( typeof operation . resource . useJQuery !== 'undefined' ? operation . resource . useJQuery : null ) ;
1079
1080
this . type = ( type || errors . push ( "SwaggerRequest type is required (get/post/put/delete/patch/options)." ) ) ;
1080
1081
this . url = ( url || errors . push ( "SwaggerRequest url is required." ) ) ;
1081
1082
this . params = params ;
@@ -1123,6 +1124,8 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
1123
1124
else
1124
1125
requestContentType = "application/x-www-form-urlencoded" ;
1125
1126
}
1127
+ else if ( this . type == "DELETE" )
1128
+ body = "{}" ;
1126
1129
else if ( this . type != "DELETE" )
1127
1130
requestContentType = null ;
1128
1131
}
@@ -1205,7 +1208,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
1205
1208
} else {
1206
1209
e = exports ;
1207
1210
}
1208
- status = e . authorizations . apply ( obj , this . operation ) ;
1211
+ status = e . authorizations . apply ( obj , this . operation . authorizations ) ;
1209
1212
if ( opts . mock == null ) {
1210
1213
if ( status !== false ) {
1211
1214
new SwaggerHttp ( ) . execute ( obj ) ;
@@ -1261,9 +1264,16 @@ SwaggerHttp.prototype.isIE8 = function() {
1261
1264
} ;
1262
1265
1263
1266
/*
1264
- * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic
1267
+ * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic.
1268
+ * NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space.
1269
+ * Since we are using closures here we need to alias it for internal use.
1265
1270
*/
1266
- var JQueryHttpClient = function ( options ) { }
1271
+ var JQueryHttpClient = function ( options ) {
1272
+ "use strict" ;
1273
+ if ( ! jQuery ) {
1274
+ var jQuery = window . jQuery ;
1275
+ }
1276
+ }
1267
1277
1268
1278
JQueryHttpClient . prototype . execute = function ( obj ) {
1269
1279
var cb = obj . on ;
@@ -1336,9 +1346,9 @@ JQueryHttpClient.prototype.execute = function(obj) {
1336
1346
else
1337
1347
return cb . response ( out ) ;
1338
1348
} ;
1339
-
1340
- $ . support . cors = true ;
1341
- return $ . ajax ( obj ) ;
1349
+
1350
+ jQuery . support . cors = true ;
1351
+ return jQuery . ajax ( obj ) ;
1342
1352
}
1343
1353
1344
1354
/*
@@ -1453,33 +1463,32 @@ SwaggerAuthorizations.prototype.remove = function(name) {
1453
1463
return delete this . authz [ name ] ;
1454
1464
} ;
1455
1465
1456
- SwaggerAuthorizations . prototype . apply = function ( obj , operation ) {
1457
- status = null ;
1466
+ SwaggerAuthorizations . prototype . apply = function ( obj , authorizations ) {
1467
+ var status = null ;
1458
1468
var key ;
1459
- for ( key in this . authz ) {
1460
- var authorizations = ( operation || { } ) . authorizations
1461
- var applyAuth = false ;
1462
- if ( operation ) {
1463
- if ( ! operation . authorizations )
1464
- applyAuth = true ;
1465
- else if ( typeof authorizations [ key ] !== 'undefined' )
1466
- applyAuth = true ;
1467
- }
1468
- else {
1469
- applyAuth = true ;
1470
- }
1471
1469
1472
- value = this . authz [ key ] ;
1473
- if ( applyAuth ) {
1474
- console . log ( 'applying auth ' + key ) ;
1470
+ if ( typeof authorizations === 'undefined' ) {
1471
+ // apply all keys since no authorizations hash is defined
1472
+ for ( key in this . authz ) {
1473
+ value = this . authz [ key ] ;
1475
1474
result = value . apply ( obj , authorizations ) ;
1476
- if ( result === false )
1477
- status = false ;
1478
1475
if ( result === true )
1479
1476
status = true ;
1480
1477
}
1481
- else status = false ;
1482
1478
}
1479
+ else {
1480
+ for ( name in authorizations ) {
1481
+ for ( key in this . authz ) {
1482
+ if ( key == name ) {
1483
+ value = this . authz [ key ] ;
1484
+ result = value . apply ( obj , authorizations ) ;
1485
+ if ( result === true )
1486
+ status = true ;
1487
+ }
1488
+ }
1489
+ }
1490
+ }
1491
+
1483
1492
return status ;
1484
1493
} ;
1485
1494
@@ -1492,7 +1501,7 @@ var ApiKeyAuthorization = function(name, value, type) {
1492
1501
this . type = type ;
1493
1502
} ;
1494
1503
1495
- ApiKeyAuthorization . prototype . apply = function ( obj , operation ) {
1504
+ ApiKeyAuthorization . prototype . apply = function ( obj , authorizations ) {
1496
1505
if ( this . type === "query" ) {
1497
1506
if ( obj . url . indexOf ( '?' ) > 0 )
1498
1507
obj . url = obj . url + "&" + this . name + "=" + this . value ;
@@ -1509,7 +1518,7 @@ var CookieAuthorization = function(cookie) {
1509
1518
this . cookie = cookie ;
1510
1519
}
1511
1520
1512
- CookieAuthorization . prototype . apply = function ( obj , operation ) {
1521
+ CookieAuthorization . prototype . apply = function ( obj , authorizations ) {
1513
1522
obj . cookieJar = obj . cookieJar || CookieJar ( ) ;
1514
1523
obj . cookieJar . setCookie ( this . cookie ) ;
1515
1524
return true ;
@@ -1529,7 +1538,7 @@ var PasswordAuthorization = function(name, username, password) {
1529
1538
this . _btoa = require ( "btoa" ) ;
1530
1539
} ;
1531
1540
1532
- PasswordAuthorization . prototype . apply = function ( obj , operation ) {
1541
+ PasswordAuthorization . prototype . apply = function ( obj , authorizations ) {
1533
1542
var base64encoder = this . _btoa ;
1534
1543
obj . headers [ "Authorization" ] = "Basic " + base64encoder ( this . username + ":" + this . password ) ;
1535
1544
return true ;
0 commit comments