@@ -691,8 +691,8 @@ function getBrokerSettings(asyncapi, params) {
691
691
function getBindings ( asyncapi , params ) {
692
692
const ret = { } ;
693
693
const funcs = getFunctionSpecs ( asyncapi , params ) ;
694
-
695
- funcs . forEach ( ( spec , name , map ) => {
694
+ const functionsThatAreBeans = filterOutNonBeanFunctionSpecs ( funcs ) ;
695
+ functionsThatAreBeans . forEach ( ( spec , name , map ) => {
696
696
if ( spec . isPublisher ) {
697
697
ret [ spec . publishBindingName ] = { } ;
698
698
ret [ spec . publishBindingName ] . destination = spec . publishChannel ;
@@ -736,11 +736,31 @@ function getFunctionName(channelName, operation, isSubscriber) {
736
736
return ret ;
737
737
}
738
738
739
+ function filterOutNonBeanFunctionSpecs ( funcs ) {
740
+ const beanFunctionSpecs = new Map ( ) ;
741
+ const entriesIterator = funcs . entries ( ) ;
742
+
743
+ let iterValue = entriesIterator . next ( ) ;
744
+ while ( ! iterValue . done ) {
745
+ const funcSpec = iterValue . value [ 1 ] ;
746
+
747
+ // This is the inverse of the condition in the Application template file
748
+ // Add it if its not dynamic (hasParams = true, isPublisher = true) and type is supplier or streamBridge
749
+ if ( ! ( funcSpec . isPublisher && funcSpec . channelInfo . hasParams &&
750
+ ( funcSpec . type === 'supplier' || funcSpec . dynamicType === 'streamBridge' ) ) ) {
751
+ beanFunctionSpecs . set ( iterValue . value [ 0 ] , iterValue . value [ 1 ] ) ;
752
+ }
753
+ iterValue = entriesIterator . next ( ) ;
754
+ }
755
+ return beanFunctionSpecs ;
756
+ }
757
+
739
758
// This returns the string that gets rendered in the function.definition part of application.yaml.
740
759
function getFunctionDefinitions ( asyncapi , params ) {
741
760
let ret = '' ;
742
761
const funcs = getFunctionSpecs ( asyncapi , params ) ;
743
- const names = funcs . keys ( ) ;
762
+ const functionsThatAreBeans = filterOutNonBeanFunctionSpecs ( funcs ) ;
763
+ const names = functionsThatAreBeans . keys ( ) ;
744
764
ret = Array . from ( names ) . join ( ';' ) ;
745
765
return ret ;
746
766
}
@@ -953,6 +973,14 @@ function getMessagePayloadType(message) {
953
973
return ret ;
954
974
}
955
975
976
+ function sortParametersUsingChannelName ( parameters , channelName ) {
977
+ // This doesnt work if theres two of the same variables in the channel name (scenario unlikely)
978
+ parameters . forEach ( param => {
979
+ param . indexInChannelName = channelName . indexOf ( param . rawName ) ;
980
+ } ) ;
981
+ return _ . sortBy ( parameters , [ 'indexInChannelName' ] ) ;
982
+ }
983
+
956
984
// This returns the connection properties for a solace binder, for application.yaml.
957
985
function getSolace ( params ) {
958
986
const ret = { } ;
@@ -975,10 +1003,6 @@ function getChannelInfo(params, channelName, channel) {
975
1003
let publishChannel = String ( channelName ) ;
976
1004
let subscribeChannel = String ( channelName ) ;
977
1005
const parameters = [ ] ;
978
- let functionParamList = '' ;
979
- let functionArgList = '' ;
980
- let sampleArgList = '' ;
981
- let first = true ;
982
1006
983
1007
debugChannel ( 'parameters:' ) ;
984
1008
debugChannel ( channel . parameters ( ) ) ;
@@ -987,39 +1011,35 @@ function getChannelInfo(params, channelName, channel) {
987
1011
const parameter = channel . parameter ( name ) ;
988
1012
const schema = parameter . schema ( ) ;
989
1013
const type = getType ( schema . type ( ) , schema . format ( ) ) ;
990
- const param = { name : _ . camelCase ( name ) } ;
1014
+ const param = {
1015
+ name : _ . camelCase ( name ) ,
1016
+ rawName : name
1017
+ } ;
991
1018
debugChannel ( `name: ${ name } type:` ) ;
992
1019
debugChannel ( type ) ;
993
1020
let sampleArg = 1 ;
994
1021
995
- // Figure out what position it's in. This is just for the parameterToHeader feature.
1022
+ subscribeChannel = subscribeChannel . replace ( nameWithBrackets , '*' ) ;
1023
+
1024
+ // Figure out what channel part it's in. This is just for the parameterToHeader feature.
996
1025
for ( let i = 0 ; i < channelParts . length ; i ++ ) {
997
1026
if ( channelParts [ i ] === nameWithBrackets ) {
998
1027
param . position = i ;
999
1028
break ;
1000
1029
}
1001
1030
}
1002
1031
1003
- if ( first ) {
1004
- first = false ;
1005
- } else {
1006
- functionParamList += ', ' ;
1007
- functionArgList += ', ' ;
1008
- }
1009
-
1010
- sampleArgList += ', ' ;
1011
1032
[ publishChannel , sampleArg ] = handleParameterType ( name , param , type , publishChannel , schema , nameWithBrackets ) ;
1012
- subscribeChannel = subscribeChannel . replace ( nameWithBrackets , '*' ) ;
1013
- functionParamList += `${ param . type } ${ param . name } ` ;
1014
- functionArgList += param . name ;
1015
- sampleArgList += sampleArg ;
1033
+ param . sampleArg = sampleArg ;
1016
1034
parameters . push ( param ) ;
1017
1035
}
1018
- ret . functionArgList = functionArgList ;
1019
- ret . functionParamList = functionParamList ;
1020
- ret . sampleArgList = sampleArgList ;
1036
+ // The channel parameters aren't in any particular order when they come in.
1037
+ // This means, to be safe, we need to order them like how it is in the channel name.
1038
+ ret . parameters = sortParametersUsingChannelName ( parameters , channelName ) ;
1039
+ ret . functionArgList = ret . parameters . map ( param => param . name ) . join ( ', ' ) ;
1040
+ ret . functionParamList = ret . parameters . map ( param => `${ param . type } ${ param . name } ` ) . join ( ', ' ) ;
1041
+ ret . sampleArgList = ret . parameters . map ( param => param . sampleArg ) . join ( ', ' ) ;
1021
1042
ret . channelName = channelName ;
1022
- ret . parameters = parameters ;
1023
1043
ret . publishChannel = publishChannel ;
1024
1044
ret . subscribeChannel = subscribeChannel ;
1025
1045
ret . hasParams = parameters . length > 0 ;
0 commit comments