11// swagger.js
2- // version 2.0.30
2+ // version 2.0.31
33
44var __bind = function ( fn , me ) {
55 return function ( ) {
@@ -57,24 +57,24 @@ Object.keys = Object.keys || (function () {
5757 'constructor'
5858 ] ,
5959 DontEnumsLength = DontEnums . length ;
60-
60+
6161 return function ( o ) {
6262 if ( typeof o != "object" && typeof o != "function" || o === null )
6363 throw new TypeError ( "Object.keys called on a non-object" ) ;
64-
64+
6565 var result = [ ] ;
6666 for ( var name in o ) {
6767 if ( hasOwnProperty . call ( o , name ) )
6868 result . push ( name ) ;
6969 }
70-
70+
7171 if ( hasDontEnumBug ) {
7272 for ( var i = 0 ; i < DontEnumsLength ; i ++ ) {
7373 if ( hasOwnProperty . call ( o , DontEnums [ i ] ) )
7474 result . push ( DontEnums [ i ] ) ;
75- }
75+ }
7676 }
77-
77+
7878 return result ;
7979 } ;
8080} ) ( ) ;
@@ -87,6 +87,7 @@ var SwaggerApi = function(url, options) {
8787 this . authorizations = null ;
8888 this . authorizationScheme = null ;
8989 this . info = null ;
90+ this . useJQuery = false ;
9091
9192 options = ( options || { } ) ;
9293 if ( url )
@@ -103,6 +104,9 @@ var SwaggerApi = function(url, options) {
103104 if ( options . success != null )
104105 this . success = options . success ;
105106
107+ if ( typeof options . useJQuery === 'boolean' )
108+ this . useJQuery = options . useJQuery ;
109+
106110 this . failure = options . failure != null ? options . failure : function ( ) { } ;
107111 this . progress = options . progress != null ? options . progress : function ( ) { } ;
108112 if ( options . success != null )
@@ -432,7 +436,6 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
432436 output = [ ] ;
433437 for ( var i = 0 ; i < ops . length ; i ++ ) {
434438 o = ops [ i ] ;
435-
436439 consumes = this . consumes ;
437440 produces = this . produces ;
438441 if ( o . consumes != null )
@@ -479,8 +482,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
479482
480483SwaggerResource . prototype . sanitize = function ( nickname ) {
481484 var op ;
482- op = nickname . replace ( / [ \s ! @ # $ % ^ & * ( ) _ + = \[ { \] } ; : < > | . / ? , \\ ' " " - ] / g, '_' ) ;
483- //'
485+ op = nickname . replace ( / [ \s ! @ # $ % ^ & * ( ) _ + = \[ { \] } ; : < > | . \/ ? , \\ ' " " - ] / g, '_' ) ;
484486 op = op . replace ( / ( ( _ ) { 2 , } ) / g, '_' ) ;
485487 op = op . replace ( / ^ ( _ ) * / g, '' ) ;
486488 op = op . replace ( / ( [ _ ] ) * $ / g, '' ) ;
@@ -675,7 +677,6 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
675677 this . resource = ( resource || errors . push ( "Resource is required" ) ) ;
676678 this . consumes = consumes ;
677679 this . produces = produces ;
678-
679680 this . authorizations = authorizations ;
680681 this [ "do" ] = __bind ( this [ "do" ] , this ) ;
681682
@@ -814,7 +815,7 @@ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
814815 else
815816 return JSON . stringify ( val , null , 2 ) ;
816817 }
817- else
818+ else
818819 return val ;
819820 }
820821} ;
@@ -1075,7 +1076,7 @@ SwaggerOperation.prototype.formatXml = function(xml) {
10751076var SwaggerRequest = function ( type , url , params , opts , successCallback , errorCallback , operation , execution ) {
10761077 var _this = this ;
10771078 var errors = [ ] ;
1078- this . useJQuery = ( typeof operation . useJQuery !== 'undefined' ? operation . useJQuery : null ) ;
1079+ this . useJQuery = ( typeof operation . resource . useJQuery !== 'undefined' ? operation . resource . useJQuery : null ) ;
10791080 this . type = ( type || errors . push ( "SwaggerRequest type is required (get/post/put/delete/patch/options)." ) ) ;
10801081 this . url = ( url || errors . push ( "SwaggerRequest url is required." ) ) ;
10811082 this . params = params ;
@@ -1123,6 +1124,8 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
11231124 else
11241125 requestContentType = "application/x-www-form-urlencoded" ;
11251126 }
1127+ else if ( this . type == "DELETE" )
1128+ body = "{}" ;
11261129 else if ( this . type != "DELETE" )
11271130 requestContentType = null ;
11281131 }
@@ -1205,7 +1208,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
12051208 } else {
12061209 e = exports ;
12071210 }
1208- status = e . authorizations . apply ( obj , this . operation ) ;
1211+ status = e . authorizations . apply ( obj , this . operation . authorizations ) ;
12091212 if ( opts . mock == null ) {
12101213 if ( status !== false ) {
12111214 new SwaggerHttp ( ) . execute ( obj ) ;
@@ -1261,9 +1264,16 @@ SwaggerHttp.prototype.isIE8 = function() {
12611264} ;
12621265
12631266/*
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.
12651270 */
1266- var JQueryHttpClient = function ( options ) { }
1271+ var JQueryHttpClient = function ( options ) {
1272+ "use strict" ;
1273+ if ( ! jQuery ) {
1274+ var jQuery = window . jQuery ;
1275+ }
1276+ }
12671277
12681278JQueryHttpClient . prototype . execute = function ( obj ) {
12691279 var cb = obj . on ;
@@ -1336,9 +1346,9 @@ JQueryHttpClient.prototype.execute = function(obj) {
13361346 else
13371347 return cb . response ( out ) ;
13381348 } ;
1339-
1340- $ . support . cors = true ;
1341- return $ . ajax ( obj ) ;
1349+
1350+ jQuery . support . cors = true ;
1351+ return jQuery . ajax ( obj ) ;
13421352}
13431353
13441354/*
@@ -1453,33 +1463,32 @@ SwaggerAuthorizations.prototype.remove = function(name) {
14531463 return delete this . authz [ name ] ;
14541464} ;
14551465
1456- SwaggerAuthorizations . prototype . apply = function ( obj , operation ) {
1457- status = null ;
1466+ SwaggerAuthorizations . prototype . apply = function ( obj , authorizations ) {
1467+ var status = null ;
14581468 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- }
14711469
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 ] ;
14751474 result = value . apply ( obj , authorizations ) ;
1476- if ( result === false )
1477- status = false ;
14781475 if ( result === true )
14791476 status = true ;
14801477 }
1481- else status = false ;
14821478 }
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+
14831492 return status ;
14841493} ;
14851494
@@ -1492,7 +1501,7 @@ var ApiKeyAuthorization = function(name, value, type) {
14921501 this . type = type ;
14931502} ;
14941503
1495- ApiKeyAuthorization . prototype . apply = function ( obj , operation ) {
1504+ ApiKeyAuthorization . prototype . apply = function ( obj , authorizations ) {
14961505 if ( this . type === "query" ) {
14971506 if ( obj . url . indexOf ( '?' ) > 0 )
14981507 obj . url = obj . url + "&" + this . name + "=" + this . value ;
@@ -1509,7 +1518,7 @@ var CookieAuthorization = function(cookie) {
15091518 this . cookie = cookie ;
15101519}
15111520
1512- CookieAuthorization . prototype . apply = function ( obj , operation ) {
1521+ CookieAuthorization . prototype . apply = function ( obj , authorizations ) {
15131522 obj . cookieJar = obj . cookieJar || CookieJar ( ) ;
15141523 obj . cookieJar . setCookie ( this . cookie ) ;
15151524 return true ;
@@ -1529,7 +1538,7 @@ var PasswordAuthorization = function(name, username, password) {
15291538 this . _btoa = require ( "btoa" ) ;
15301539} ;
15311540
1532- PasswordAuthorization . prototype . apply = function ( obj , operation ) {
1541+ PasswordAuthorization . prototype . apply = function ( obj , authorizations ) {
15331542 var base64encoder = this . _btoa ;
15341543 obj . headers [ "Authorization" ] = "Basic " + base64encoder ( this . username + ":" + this . password ) ;
15351544 return true ;
0 commit comments