@@ -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 ) {
@@ -1015,7 +1020,7 @@ Operation.prototype.matchesAccept = function(accepts) {
10151020} ;
10161021
10171022Operation . prototype . asCurl = function ( args1 , args2 ) {
1018- var opts = { mock : true } ;
1023+ var opts = { mock : true , maskPasswords : true } ;
10191024 if ( typeof args2 === 'object' ) {
10201025 for ( var argKey in args2 ) {
10211026 opts [ argKey ] = args2 [ argKey ] ;
@@ -1082,14 +1087,14 @@ Operation.prototype.asCurl = function (args1, args2) {
10821087 if ( Array . isArray ( paramValue ) ) {
10831088 if ( parameter . collectionFormat === 'multi' ) {
10841089 for ( var v in paramValue ) {
1085- body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + paramValue [ v ] + ' ' ;
1090+ body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + mask ( paramValue [ v ] , parameter . format ) + ' ' ;
10861091 }
10871092 }
10881093 else {
1089- body += '-F ' + this . encodeQueryCollection ( parameter . collectionFormat , parameter . name , paramValue ) + ' ' ;
1094+ body += '-F ' + this . encodeQueryCollection ( parameter . collectionFormat , parameter . name , mask ( paramValue , parameter . format ) ) + ' ' ;
10901095 }
10911096 } else {
1092- body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + paramValue + ' ' ;
1097+ body += '-F ' + this . encodeQueryKey ( parameter . name ) + '=' + mask ( paramValue , parameter . format ) + ' ' ;
10931098 }
10941099 }
10951100 }
@@ -1120,7 +1125,7 @@ Operation.prototype.asCurl = function (args1, args2) {
11201125 return 'curl ' + ( results . join ( ' ' ) ) + ' \'' + obj . url + '\'' ;
11211126} ;
11221127
1123- Operation . prototype . encodePathCollection = function ( type , name , value ) {
1128+ Operation . prototype . encodePathCollection = function ( type , name , value , maskPasswords ) {
11241129 var encoded = '' ;
11251130 var i ;
11261131 var separator = '' ;
@@ -1137,9 +1142,9 @@ Operation.prototype.encodePathCollection = function (type, name, value) {
11371142
11381143 for ( i = 0 ; i < value . length ; i ++ ) {
11391144 if ( i === 0 ) {
1140- encoded = this . encodeQueryParam ( value [ i ] ) ;
1145+ encoded = this . encodeQueryParam ( value [ i ] , maskPasswords ) ;
11411146 } else {
1142- encoded += separator + this . encodeQueryParam ( value [ i ] ) ;
1147+ encoded += separator + this . encodeQueryParam ( value [ i ] , maskPasswords ) ;
11431148 }
11441149 }
11451150
@@ -1197,13 +1202,23 @@ Operation.prototype.encodeQueryKey = function (arg) {
11971202 . replace ( '%5B' , '[' ) . replace ( '%5D' , ']' ) . replace ( '%24' , '$' ) ;
11981203} ;
11991204
1200- Operation . prototype . encodeQueryParam = function ( arg ) {
1205+ Operation . prototype . encodeQueryParam = function ( arg , maskPasswords ) {
1206+ if ( maskPasswords ) {
1207+ return "******" ;
1208+ }
12011209 return encodeURIComponent ( arg ) ;
12021210} ;
12031211
12041212/**
12051213 * TODO revisit, might not want to leave '/'
12061214 **/
1207- Operation . prototype . encodePathParam = function ( pathParam ) {
1208- return encodeURIComponent ( pathParam ) ;
1215+ Operation . prototype . encodePathParam = function ( pathParam , maskPasswords ) {
1216+ return encodeURIComponent ( pathParam , maskPasswords ) ;
12091217} ;
1218+
1219+ var mask = function ( value , format ) {
1220+ if ( typeof format === 'string' && format === 'password' ) {
1221+ return '******' ;
1222+ }
1223+ return value ;
1224+ }
0 commit comments