@@ -499,20 +499,46 @@ module.exports = function generate(ctx) {
499499 }
500500 return output . join ( ', ' ) ;
501501 }
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+ }
502518 /**
503519 * @method buildPostBody
504520 * @description
505521 * Define which properties should be passed while posting data (POST, PUT, PATCH)
506522 */
507523 function buildPostBody ( postData ) {
508524 let output = [ ] ;
509- if ( postData && postData . length > 0 ) {
510- output . push ( '' ) ;
511- let l = postData . length ;
512- postData . forEach ( ( property , i ) => {
513- output . push ( ` ${ property . arg } : ${ property . arg } ${ ( i < l - 1 ) ? ',' : '' } ` ) ;
514- } ) ;
515- 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+ }
516542 }
517543 return output . join ( '\n' ) ;
518544 }
@@ -525,13 +551,12 @@ module.exports = function generate(ctx) {
525551 let output = [ '' ] ;
526552 // filter params that should not go over url query string
527553 urlParams = urlParams . filter ( param => {
528- let isRouteParam = ( 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 ) / ) )
529- // Filter out route params
530- if ( isRouteParam ) {
531- return false
532- }
533- // Filter out body params
534- return ( ! param . http || param . http . source != 'body' )
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' )
535560 } ) ;
536561 if ( model . isUser && methodName === 'logout' )
537562 output . push ( ` urlParams.access_token = this.auth.getAccessTokenId();` ) ;
@@ -549,12 +574,15 @@ module.exports = function generate(ctx) {
549574 */
550575 function buildRouteParams ( routeParams ) {
551576 let output = [ ] ;
552- if ( routeParams && routeParams . length > 0 ) {
553- output . push ( '' ) ;
554- routeParams . forEach ( ( param , i ) => {
555- output . push ( ` ${ param . arg } : ${ param . arg } ${ ( i < routeParams . length - 1 ) ? ',' : '' } ` ) ;
556- } ) ;
557- 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+ }
558586 }
559587 return output . join ( '\n' ) ;
560588 }
0 commit comments