@@ -491,7 +491,7 @@ Operation.prototype.getHeaderParams = function (args) {
491491 return headers ;
492492} ;
493493
494- Operation . prototype . urlify = function ( args ) {
494+ Operation . prototype . urlify = function ( args , maskPasswords ) {
495495 var formParams = { } ;
496496 var requestUrl = this . path . replace ( / # .* / , '' ) ; // remove URL fragment
497497 var querystring = '' ; // grab params from the args, build the querystring along the way
@@ -500,14 +500,19 @@ Operation.prototype.urlify = function (args) {
500500 var param = this . parameters [ i ] ;
501501
502502 if ( typeof args [ param . name ] !== 'undefined' ) {
503+ var isPassword ;
504+ if ( param . type === 'string' && param . format === 'password' && maskPasswords ) {
505+ isPassword = true ;
506+ }
507+
503508 if ( param . in === 'path' ) {
504509 var reg = new RegExp ( '\{' + param . name + '\}' , 'gi' ) ;
505510 var value = args [ param . name ] ;
506511
507512 if ( Array . isArray ( value ) ) {
508- value = this . encodePathCollection ( param . collectionFormat , param . name , value ) ;
513+ value = this . encodePathCollection ( param . collectionFormat , param . name , value , isPassword ) ;
509514 } else {
510- value = this . encodePathParam ( value ) ;
515+ value = this . encodePathParam ( value , isPassword ) ;
511516 }
512517
513518 requestUrl = requestUrl . replace ( reg , value ) ;
@@ -522,12 +527,12 @@ Operation.prototype.urlify = function (args) {
522527 var qp = args [ param . name ] ;
523528
524529 if ( Array . isArray ( qp ) ) {
525- querystring += this . encodeQueryCollection ( param . collectionFormat , param . name , qp ) ;
530+ querystring += this . encodeQueryCollection ( param . collectionFormat , param . name , qp , isPassword ) ;
526531 } else {
527- querystring += this . encodeQueryKey ( param . name ) + '=' + this . encodeQueryParam ( args [ param . name ] ) ;
532+ querystring += this . encodeQueryKey ( param . name ) + '=' + this . encodeQueryParam ( args [ param . name ] , isPassword ) ;
528533 }
529534 } else {
530- querystring += this . encodeQueryKey ( param . name ) + '=' + this . encodeQueryParam ( args [ param . name ] ) ;
535+ querystring += this . encodeQueryKey ( param . name ) + '=' + this . encodeQueryParam ( args [ param . name ] , isPassword ) ;
531536 }
532537 } else if ( param . in === 'formData' ) {
533538 formParams [ param . name ] = args [ param . name ] ;
@@ -835,7 +840,7 @@ Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
835840 for ( attrname in contentTypeHeaders ) { headers [ attrname ] = contentTypeHeaders [ attrname ] ; }
836841
837842 var body = this . getBody ( contentTypeHeaders , args , opts ) ;
838- var url = this . urlify ( args ) ;
843+ var url = this . urlify ( args , opts . maskPasswords ) ;
839844
840845 if ( url . indexOf ( '.{format}' ) > 0 ) {
841846 if ( headers ) {
@@ -1017,7 +1022,7 @@ Operation.prototype.matchesAccept = function(accepts) {
10171022} ;
10181023
10191024Operation . prototype . asCurl = function ( args1 , args2 ) {
1020- var opts = { mock : true } ;
1025+ var opts = { mock : true , maskPasswords : true } ;
10211026 if ( typeof args2 === 'object' ) {
10221027 for ( var argKey in args2 ) {
10231028 opts [ argKey ] = args2 [ argKey ] ;
@@ -1084,14 +1089,14 @@ Operation.prototype.asCurl = function (args1, args2) {
10841089 if ( Array . isArray ( paramValue ) ) {
10851090 if ( parameter . collectionFormat === 'multi' ) {
10861091 for ( var v in paramValue ) {
1087- body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + paramValue [ v ] + ' ' ;
1092+ body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + mask ( paramValue [ v ] , parameter . format ) + ' ' ;
10881093 }
10891094 }
10901095 else {
1091- body += '-F ' + this . encodeQueryCollection ( parameter . collectionFormat , parameter . name , paramValue ) + ' ' ;
1096+ body += '-F ' + this . encodeQueryCollection ( parameter . collectionFormat , parameter . name , mask ( paramValue , parameter . format ) ) + ' ' ;
10921097 }
10931098 } else {
1094- body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + paramValue + ' ' ;
1099+ body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + mask ( paramValue , parameter . format ) + ' ' ;
10951100 }
10961101 }
10971102 }
@@ -1122,7 +1127,7 @@ Operation.prototype.asCurl = function (args1, args2) {
11221127 return 'curl ' + ( results . join ( ' ' ) ) + ' \'' + obj . url + '\'' ;
11231128} ;
11241129
1125- Operation . prototype . encodePathCollection = function ( type , name , value ) {
1130+ Operation . prototype . encodePathCollection = function ( type , name , value , maskPasswords ) {
11261131 var encoded = '' ;
11271132 var i ;
11281133 var separator = '' ;
@@ -1139,9 +1144,9 @@ Operation.prototype.encodePathCollection = function (type, name, value) {
11391144
11401145 for ( i = 0 ; i < value . length ; i ++ ) {
11411146 if ( i === 0 ) {
1142- encoded = this . encodeQueryParam ( value [ i ] ) ;
1147+ encoded = this . encodeQueryParam ( value [ i ] , maskPasswords ) ;
11431148 } else {
1144- encoded += separator + this . encodeQueryParam ( value [ i ] ) ;
1149+ encoded += separator + this . encodeQueryParam ( value [ i ] , maskPasswords ) ;
11451150 }
11461151 }
11471152
@@ -1199,13 +1204,23 @@ Operation.prototype.encodeQueryKey = function (arg) {
11991204 . replace ( '%5B' , '[' ) . replace ( '%5D' , ']' ) . replace ( '%24' , '$' ) ;
12001205} ;
12011206
1202- Operation . prototype . encodeQueryParam = function ( arg ) {
1207+ Operation . prototype . encodeQueryParam = function ( arg , maskPasswords ) {
1208+ if ( maskPasswords ) {
1209+ return "******" ;
1210+ }
12031211 return encodeURIComponent ( arg ) ;
12041212} ;
12051213
12061214/**
12071215 * TODO revisit, might not want to leave '/'
12081216 **/
1209- Operation . prototype . encodePathParam = function ( pathParam ) {
1210- return encodeURIComponent ( pathParam ) ;
1217+ Operation . prototype . encodePathParam = function ( pathParam , maskPasswords ) {
1218+ return encodeURIComponent ( pathParam , maskPasswords ) ;
12111219} ;
1220+
1221+ var mask = function ( value , format ) {
1222+ if ( typeof format === 'string' && format === 'password' ) {
1223+ return '******' ;
1224+ }
1225+ return value ;
1226+ }
0 commit comments