@@ -404,6 +404,7 @@ module.exports = function generate(ctx) {
404404 { module : 'LoopBackAuth' , from : './auth.service' } ,
405405 { module : 'LoopBackConfig' , from : '../../lb.config' } ,
406406 { module : 'AccessToken' , from : '../../models' } ,
407+ { module : 'Observable' , from : 'rxjs/Observable' } ,
407408 { module : 'ErrorObservable' , from : 'rxjs/observable/ErrorObservable' } ,
408409 { module : 'rxjs/add/operator/catch' } ,
409410 { module : 'rxjs/add/operator/map' } ,
@@ -498,20 +499,46 @@ module.exports = function generate(ctx) {
498499 }
499500 return output . join ( ', ' ) ;
500501 }
502+ /**
503+ * @method paramIsRoute
504+ * @description
505+ * Testing if the param is route type
506+ */
507+ function paramIsRoute ( param ) {
508+ return ( param . http && param . http . source === 'path' ) || ( param . arg && param . arg . match ( / ( i d | f k | f i l e | c o n t a i n e r ) / ) ) ;
509+ }
510+ /**
511+ * @method paramIsFunction
512+ * @description
513+ * Testing if the param is function type
514+ */
515+ function paramIsFunction ( param ) {
516+ return typeof param . http === 'function'
517+ }
501518 /**
502519 * @method buildPostBody
503520 * @description
504521 * Define which properties should be passed while posting data (POST, PUT, PATCH)
505522 */
506523 function buildPostBody ( postData ) {
507524 let output = [ ] ;
508- if ( postData && postData . length > 0 ) {
509- output . push ( '' ) ;
510- let l = postData . length ;
511- postData . forEach ( ( property , i ) => {
512- output . push ( ` ${ property . arg } : ${ property . arg } ${ ( i < l - 1 ) ? ',' : '' } ` ) ;
513- } ) ;
514- output . push ( ' ' ) ;
525+ if ( Array . isArray ( postData ) ) {
526+ postData = postData . filter ( param => {
527+ // Filter out route params and function params
528+ if ( paramIsRoute ( param ) || paramIsFunction ( param ) ) {
529+ return false
530+ }
531+ // Make sure the param is body
532+ return param . http && param . http . source == 'body'
533+ } )
534+ if ( postData . length > 0 ) {
535+ output . push ( '' ) ;
536+ let l = postData . length ;
537+ postData . forEach ( ( property , i ) => {
538+ output . push ( ` ${ property . arg } : ${ property . arg } ${ ( i < l - 1 ) ? ',' : '' } ` ) ;
539+ } ) ;
540+ output . push ( ' ' ) ;
541+ }
515542 }
516543 return output . join ( '\n' ) ;
517544 }
@@ -523,7 +550,14 @@ module.exports = function generate(ctx) {
523550 function buildUrlParams ( model , methodName , urlParams ) {
524551 let output = [ '' ] ;
525552 // filter params that should not go over url query string
526- urlParams = urlParams . filter ( param => ( param . arg && ! param . arg . match ( / ( i d | f k | d a t a | o p t i o n s | c r e d e n t i a l s ) / g) ) ) ;
553+ urlParams = urlParams . filter ( param => {
554+ // Filter out route params and function params
555+ if ( paramIsRoute ( param ) || paramIsFunction ( param ) ) {
556+ return false
557+ }
558+ // Filter out body params
559+ return ( ! param . http || param . http . source != 'body' )
560+ } ) ;
527561 if ( model . isUser && methodName === 'logout' )
528562 output . push ( ` urlParams.access_token = this.auth.getAccessTokenId();` ) ;
529563 if ( urlParams && urlParams . length > 0 ) {
@@ -540,12 +574,15 @@ module.exports = function generate(ctx) {
540574 */
541575 function buildRouteParams ( routeParams ) {
542576 let output = [ ] ;
543- if ( routeParams && routeParams . length > 0 ) {
544- output . push ( '' ) ;
545- routeParams . forEach ( ( param , i ) => {
546- output . push ( ` ${ param . arg } : ${ param . arg } ${ ( i < routeParams . length - 1 ) ? ',' : '' } ` ) ;
547- } ) ;
548- output . push ( ' ' ) ;
577+ if ( routeParams ) {
578+ routeParams = routeParams . filter ( paramIsRoute )
579+ if ( routeParams . length > 0 ) {
580+ output . push ( '' ) ;
581+ routeParams . forEach ( ( param , i ) => {
582+ output . push ( ` ${ param . arg } : ${ param . arg } ${ ( i < routeParams . length - 1 ) ? ',' : '' } ` ) ;
583+ } ) ;
584+ output . push ( ' ' ) ;
585+ }
549586 }
550587 return output . join ( '\n' ) ;
551588 }
0 commit comments