@@ -432,6 +432,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
432
432
output = [ ] ;
433
433
for ( var i = 0 ; i < ops . length ; i ++ ) {
434
434
o = ops [ i ] ;
435
+
435
436
consumes = this . consumes ;
436
437
produces = this . produces ;
437
438
if ( o . consumes != null )
@@ -674,6 +675,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
674
675
this . resource = ( resource || errors . push ( "Resource is required" ) ) ;
675
676
this . consumes = consumes ;
676
677
this . produces = produces ;
678
+
677
679
this . authorizations = authorizations ;
678
680
this [ "do" ] = __bind ( this [ "do" ] , this ) ;
679
681
@@ -1203,7 +1205,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
1203
1205
} else {
1204
1206
e = exports ;
1205
1207
}
1206
- status = e . authorizations . apply ( obj , this . operation . authorizations ) ;
1208
+ status = e . authorizations . apply ( obj , this . operation ) ;
1207
1209
if ( opts . mock == null ) {
1208
1210
if ( status !== false ) {
1209
1211
new SwaggerHttp ( ) . execute ( obj ) ;
@@ -1440,16 +1442,32 @@ SwaggerAuthorizations.prototype.remove = function(name) {
1440
1442
return delete this . authz [ name ] ;
1441
1443
} ;
1442
1444
1443
- SwaggerAuthorizations . prototype . apply = function ( obj , authorizations ) {
1445
+ SwaggerAuthorizations . prototype . apply = function ( obj , operation ) {
1444
1446
status = null ;
1445
1447
var key ;
1446
1448
for ( key in this . authz ) {
1449
+ var authorizations = ( operation || { } ) . authorizations
1450
+ var applyAuth = false ;
1451
+ if ( operation ) {
1452
+ if ( ! operation . authorizations )
1453
+ applyAuth = true ;
1454
+ else if ( typeof authorizations [ key ] !== 'undefined' )
1455
+ applyAuth = true ;
1456
+ }
1457
+ else {
1458
+ applyAuth = true ;
1459
+ }
1460
+
1447
1461
value = this . authz [ key ] ;
1448
- result = value . apply ( obj , authorizations ) ;
1449
- if ( result === false )
1450
- status = false ;
1451
- if ( result === true )
1452
- status = true ;
1462
+ if ( applyAuth ) {
1463
+ console . log ( 'applying auth ' + key ) ;
1464
+ result = value . apply ( obj , authorizations ) ;
1465
+ if ( result === false )
1466
+ status = false ;
1467
+ if ( result === true )
1468
+ status = true ;
1469
+ }
1470
+ else status = false ;
1453
1471
}
1454
1472
return status ;
1455
1473
} ;
@@ -1463,7 +1481,7 @@ var ApiKeyAuthorization = function(name, value, type) {
1463
1481
this . type = type ;
1464
1482
} ;
1465
1483
1466
- ApiKeyAuthorization . prototype . apply = function ( obj , authorizations ) {
1484
+ ApiKeyAuthorization . prototype . apply = function ( obj , operation ) {
1467
1485
if ( this . type === "query" ) {
1468
1486
if ( obj . url . indexOf ( '?' ) > 0 )
1469
1487
obj . url = obj . url + "&" + this . name + "=" + this . value ;
@@ -1480,7 +1498,7 @@ var CookieAuthorization = function(cookie) {
1480
1498
this . cookie = cookie ;
1481
1499
}
1482
1500
1483
- CookieAuthorization . prototype . apply = function ( obj , authorizations ) {
1501
+ CookieAuthorization . prototype . apply = function ( obj , operation ) {
1484
1502
obj . cookieJar = obj . cookieJar || CookieJar ( ) ;
1485
1503
obj . cookieJar . setCookie ( this . cookie ) ;
1486
1504
return true ;
@@ -1500,7 +1518,7 @@ var PasswordAuthorization = function(name, username, password) {
1500
1518
this . _btoa = require ( "btoa" ) ;
1501
1519
} ;
1502
1520
1503
- PasswordAuthorization . prototype . apply = function ( obj , authorizations ) {
1521
+ PasswordAuthorization . prototype . apply = function ( obj , operation ) {
1504
1522
var base64encoder = this . _btoa ;
1505
1523
obj . headers [ "Authorization" ] = "Basic " + base64encoder ( this . username + ":" + this . password ) ;
1506
1524
return true ;
0 commit comments