From ba9d49d77ad5e2f371ac03d9c98ef2487f8cb0a3 Mon Sep 17 00:00:00 2001 From: Marat Gubaidullin Date: Thu, 19 Oct 2023 18:58:22 -0400 Subject: [PATCH] CamelDefinitionApiGenerator and CamelDefinitionYamlStepGenerator for Camel YAML DSL 4.1.0 --- .../src/core/api/CamelDefinitionApi.ts | 275 +++++-------- .../src/core/api/CamelDefinitionYamlStep.ts | 360 +++++------------- .../src/core/model/CamelDefinition.ts | 14 +- .../karavan/generator/AbstractGenerator.java | 103 +++-- .../CamelDefinitionApiGenerator.java | 87 +++-- .../generator/CamelDefinitionGenerator.java | 47 +-- .../CamelDefinitionYamlStepGenerator.java | 108 +++--- .../karavan/generator/KaravanGenerator.java | 4 +- 8 files changed, 381 insertions(+), 617 deletions(-) diff --git a/karavan-core/src/core/api/CamelDefinitionApi.ts b/karavan-core/src/core/api/CamelDefinitionApi.ts index 19f5299c8ba..c856e3e19d2 100644 --- a/karavan-core/src/core/api/CamelDefinitionApi.ts +++ b/karavan-core/src/core/api/CamelDefinitionApi.ts @@ -121,6 +121,8 @@ import { WhenSkipSendToEndpointDefinition, WireTapDefinition, ApplicationDefinition, + BeanConstructorDefinition, + BeanConstructorsDefinition, BeanPropertiesDefinition, BeanPropertyDefinition, BeansDefinition, @@ -306,15 +308,6 @@ export class CamelDefinitionApi { if (element?.idempotentConsumer !== undefined) { def.idempotentConsumer = CamelDefinitionApi.createIdempotentConsumerDefinition(element.idempotentConsumer); } - if (element?.intercept !== undefined) { - def.intercept = CamelDefinitionApi.createInterceptDefinition(element.intercept); - } - if (element?.interceptFrom !== undefined) { - def.interceptFrom = CamelDefinitionApi.createInterceptFromDefinition(element.interceptFrom); - } - if (element?.interceptSendToEndpoint !== undefined) { - def.interceptSendToEndpoint = CamelDefinitionApi.createInterceptSendToEndpointDefinition(element.interceptSendToEndpoint); - } if (element?.kamelet !== undefined) { def.kamelet = CamelDefinitionApi.createKameletDefinition(element.kamelet); } @@ -333,9 +326,6 @@ export class CamelDefinitionApi { if (element?.multicast !== undefined) { def.multicast = CamelDefinitionApi.createMulticastDefinition(element.multicast); } - if (element?.onCompletion !== undefined) { - def.onCompletion = CamelDefinitionApi.createOnCompletionDefinition(element.onCompletion); - } if (element?.onFallback !== undefined) { def.onFallback = CamelDefinitionApi.createOnFallbackDefinition(element.onFallback); } @@ -496,17 +486,17 @@ export class CamelDefinitionApi { static createAggregateDefinition = (element: any): AggregateDefinition => { const def = element ? new AggregateDefinition({...element}) : new AggregateDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + if (element?.correlationExpression !== undefined) { + def.correlationExpression = CamelDefinitionApi.createExpressionSubElementDefinition(element.correlationExpression); + } if (element?.completionPredicate !== undefined) { def.completionPredicate = CamelDefinitionApi.createExpressionSubElementDefinition(element.completionPredicate); } - if (element?.completionSizeExpression !== undefined) { - def.completionSizeExpression = CamelDefinitionApi.createExpressionSubElementDefinition(element.completionSizeExpression); - } if (element?.completionTimeoutExpression !== undefined) { def.completionTimeoutExpression = CamelDefinitionApi.createExpressionSubElementDefinition(element.completionTimeoutExpression); } - if (element?.correlationExpression !== undefined) { - def.correlationExpression = CamelDefinitionApi.createExpressionSubElementDefinition(element.correlationExpression); + if (element?.completionSizeExpression !== undefined) { + def.completionSizeExpression = CamelDefinitionApi.createExpressionSubElementDefinition(element.completionSizeExpression); } if (element?.optimisticLockRetryPolicy !== undefined) { def.optimisticLockRetryPolicy = CamelDefinitionApi.createOptimisticLockRetryPolicyDefinition(element.optimisticLockRetryPolicy); @@ -534,25 +524,25 @@ export class CamelDefinitionApi { static createChoiceDefinition = (element: any): ChoiceDefinition => { const def = element ? new ChoiceDefinition({...element}) : new ChoiceDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + def.when = element && element?.when ? element?.when.map((x:any) => CamelDefinitionApi.createWhenDefinition(x)) :[]; if (element?.otherwise !== undefined) { def.otherwise = CamelDefinitionApi.createOtherwiseDefinition(element.otherwise); } - def.when = element && element?.when ? element?.when.map((x:any) => CamelDefinitionApi.createWhenDefinition(x)) :[]; return def; } static createCircuitBreakerDefinition = (element: any): CircuitBreakerDefinition => { const def = element ? new CircuitBreakerDefinition({...element}) : new CircuitBreakerDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + if (element?.resilience4jConfiguration !== undefined) { + def.resilience4jConfiguration = CamelDefinitionApi.createResilience4jConfigurationDefinition(element.resilience4jConfiguration); + } if (element?.faultToleranceConfiguration !== undefined) { def.faultToleranceConfiguration = CamelDefinitionApi.createFaultToleranceConfigurationDefinition(element.faultToleranceConfiguration); } if (element?.onFallback !== undefined) { def.onFallback = CamelDefinitionApi.createOnFallbackDefinition(element.onFallback); } - if (element?.resilience4jConfiguration !== undefined) { - def.resilience4jConfiguration = CamelDefinitionApi.createResilience4jConfigurationDefinition(element.resilience4jConfiguration); - } def.steps = CamelDefinitionApi.createSteps(element?.steps); return def; } @@ -812,7 +802,6 @@ export class CamelDefinitionApi { if (element?.roundRobin !== undefined) { def.roundRobin = CamelDefinitionApi.createRoundRobinLoadBalancerDefinition(element.roundRobin); } - def.steps = CamelDefinitionApi.createSteps(element?.steps); if (element?.sticky !== undefined) { def.sticky = CamelDefinitionApi.createStickyLoadBalancerDefinition(element.sticky); } @@ -822,6 +811,7 @@ export class CamelDefinitionApi { if (element?.weighted !== undefined) { def.weighted = CamelDefinitionApi.createWeightedLoadBalancerDefinition(element.weighted); } + def.steps = CamelDefinitionApi.createSteps(element?.steps); return def; } @@ -989,20 +979,20 @@ export class CamelDefinitionApi { static createOnExceptionDefinition = (element: any): OnExceptionDefinition => { const def = element ? new OnExceptionDefinition({...element}) : new OnExceptionDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; - if (element?.continued !== undefined) { - def.continued = CamelDefinitionApi.createExpressionSubElementDefinition(element.continued); - } - if (element?.handled !== undefined) { - def.handled = CamelDefinitionApi.createExpressionSubElementDefinition(element.handled); - } if (element?.onWhen !== undefined) { def.onWhen = CamelDefinitionApi.createWhenDefinition(element.onWhen); } + if (element?.retryWhile !== undefined) { + def.retryWhile = CamelDefinitionApi.createExpressionSubElementDefinition(element.retryWhile); + } if (element?.redeliveryPolicy !== undefined) { def.redeliveryPolicy = CamelDefinitionApi.createRedeliveryPolicyDefinition(element.redeliveryPolicy); } - if (element?.retryWhile !== undefined) { - def.retryWhile = CamelDefinitionApi.createExpressionSubElementDefinition(element.retryWhile); + if (element?.handled !== undefined) { + def.handled = CamelDefinitionApi.createExpressionSubElementDefinition(element.handled); + } + if (element?.continued !== undefined) { + def.continued = CamelDefinitionApi.createExpressionSubElementDefinition(element.continued); } def.steps = CamelDefinitionApi.createSteps(element?.steps); return def; @@ -1148,15 +1138,9 @@ export class CamelDefinitionApi { static createResequenceDefinition = (element: any): ResequenceDefinition => { const def = element ? new ResequenceDefinition({...element}) : new ResequenceDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; - if (element?.batchConfig !== undefined) { - def.batchConfig = CamelDefinitionApi.createBatchResequencerConfig(element.batchConfig); - } def.expression = CamelDefinitionApi.createExpressionDefinition(element.expression); def.steps = CamelDefinitionApi.createSteps(element?.steps); - if (element?.streamConfig !== undefined) { - def.streamConfig = CamelDefinitionApi.createStreamResequencerConfig(element.streamConfig); - } return def; } @@ -1211,11 +1195,6 @@ export class CamelDefinitionApi { if (element?.errorHandler !== undefined) { def.errorHandler = CamelDefinitionApi.createErrorHandlerDefinition(element.errorHandler); } - def.intercept = element && element?.intercept ? element?.intercept.map((x:any) => CamelDefinitionApi.createInterceptDefinition(x)) :[]; - def.interceptFrom = element && element?.interceptFrom ? element?.interceptFrom.map((x:any) => CamelDefinitionApi.createInterceptFromDefinition(x)) :[]; - def.interceptSendToEndpoint = element && element?.interceptSendToEndpoint ? element?.interceptSendToEndpoint.map((x:any) => CamelDefinitionApi.createInterceptSendToEndpointDefinition(x)) :[]; - def.onCompletion = element && element?.onCompletion ? element?.onCompletion.map((x:any) => CamelDefinitionApi.createOnCompletionDefinition(x)) :[]; - def.onException = element && element?.onException ? element?.onException.map((x:any) => CamelDefinitionApi.createOnExceptionDefinition(x)) :[]; return def; } @@ -1253,14 +1232,14 @@ export class CamelDefinitionApi { static createRouteTemplateDefinition = (element: any): RouteTemplateDefinition => { const def = element ? new RouteTemplateDefinition({...element}) : new RouteTemplateDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + if (element?.route !== undefined) { + def.route = CamelDefinitionApi.createRouteDefinition(element.route); + } def.beans = element && element?.beans ? element?.beans.map((x:any) => CamelDefinitionApi.createRouteTemplateBeanDefinition(x)) :[]; if (element?.from !== undefined) { def.from = CamelDefinitionApi.createFromDefinition(element.from); } def.parameters = element && element?.parameters ? element?.parameters.map((x:any) => CamelDefinitionApi.createRouteTemplateParameterDefinition(x)) :[]; - if (element?.route !== undefined) { - def.route = CamelDefinitionApi.createRouteDefinition(element.route); - } return def; } @@ -1405,11 +1384,11 @@ export class CamelDefinitionApi { static createThrottleDefinition = (element: any): ThrottleDefinition => { const def = element ? new ThrottleDefinition({...element}) : new ThrottleDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + def.expression = CamelDefinitionApi.createExpressionDefinition(element.expression); + if (element?.correlationExpression !== undefined) { def.correlationExpression = CamelDefinitionApi.createExpressionSubElementDefinition(element.correlationExpression); } - def.expression = CamelDefinitionApi.createExpressionDefinition(element.expression); - return def; } @@ -1641,6 +1620,19 @@ export class CamelDefinitionApi { return def; } + static createBeanConstructorDefinition = (element: any): BeanConstructorDefinition => { + const def = element ? new BeanConstructorDefinition({...element}) : new BeanConstructorDefinition(); + def.uuid = element?.uuid ? element.uuid : def.uuid; + return def; + } + + static createBeanConstructorsDefinition = (element: any): BeanConstructorsDefinition => { + const def = element ? new BeanConstructorsDefinition({...element}) : new BeanConstructorsDefinition(); + def.uuid = element?.uuid ? element.uuid : def.uuid; + def.constructor = element && element?.constructor ? element?.constructor.map((x:any) => CamelDefinitionApi.createBeanConstructorDefinition(x)) :[]; + return def; + } + static createBeanPropertiesDefinition = (element: any): BeanPropertiesDefinition => { const def = element ? new BeanPropertiesDefinition({...element}) : new BeanPropertiesDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; @@ -1661,13 +1653,13 @@ export class CamelDefinitionApi { const def = element ? new BeansDefinition({...element}) : new BeansDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; def.bean = element && element?.bean ? element?.bean.map((x:any) => CamelDefinitionApi.createRegistryBeanDefinition(x)) :[]; - def.componentScan = element && element?.componentScan ? element?.componentScan.map((x:any) => CamelDefinitionApi.createComponentScanDefinition(x)) :[]; - def.rest = element && element?.rest ? element?.rest.map((x:any) => CamelDefinitionApi.createRestDefinition(x)) :[]; def.restConfiguration = element && element?.restConfiguration ? element?.restConfiguration.map((x:any) => CamelDefinitionApi.createRestConfigurationDefinition(x)) :[]; - def.route = element && element?.route ? element?.route.map((x:any) => CamelDefinitionApi.createRouteDefinition(x)) :[]; + def.rest = element && element?.rest ? element?.rest.map((x:any) => CamelDefinitionApi.createRestDefinition(x)) :[]; def.routeConfiguration = element && element?.routeConfiguration ? element?.routeConfiguration.map((x:any) => CamelDefinitionApi.createRouteConfigurationDefinition(x)) :[]; def.routeTemplate = element && element?.routeTemplate ? element?.routeTemplate.map((x:any) => CamelDefinitionApi.createRouteTemplateDefinition(x)) :[]; def.templatedRoute = element && element?.templatedRoute ? element?.templatedRoute.map((x:any) => CamelDefinitionApi.createTemplatedRouteDefinition(x)) :[]; + def.route = element && element?.route ? element?.route.map((x:any) => CamelDefinitionApi.createRouteDefinition(x)) :[]; + def.componentScan = element && element?.componentScan ? element?.componentScan.map((x:any) => CamelDefinitionApi.createComponentScanDefinition(x)) :[]; return def; } @@ -1705,10 +1697,10 @@ export class CamelDefinitionApi { if (element?.kubernetesServiceDiscovery !== undefined) { def.kubernetesServiceDiscovery = CamelDefinitionApi.createKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery); } - def.properties = element && element?.properties ? element?.properties.map((x:any) => CamelDefinitionApi.createPropertyDefinition(x)) :[]; if (element?.staticServiceDiscovery !== undefined) { def.staticServiceDiscovery = CamelDefinitionApi.createStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery); } + def.properties = element && element?.properties ? element?.properties.map((x:any) => CamelDefinitionApi.createPropertyDefinition(x)) :[]; return def; } @@ -1805,48 +1797,23 @@ export class CamelDefinitionApi { static createServiceCallConfigurationDefinition = (element: any): ServiceCallConfigurationDefinition => { const def = element ? new ServiceCallConfigurationDefinition({...element}) : new ServiceCallConfigurationDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + def.expression = CamelDefinitionApi.createExpressionDefinition(element.expression); + if (element?.blacklistServiceFilter !== undefined) { def.blacklistServiceFilter = CamelDefinitionApi.createBlacklistServiceCallServiceFilterConfiguration(element.blacklistServiceFilter); } - if (element?.cachingServiceDiscovery !== undefined) { - def.cachingServiceDiscovery = CamelDefinitionApi.createCachingServiceCallServiceDiscoveryConfiguration(element.cachingServiceDiscovery); - } - if (element?.combinedServiceDiscovery !== undefined) { - def.combinedServiceDiscovery = CamelDefinitionApi.createCombinedServiceCallServiceDiscoveryConfiguration(element.combinedServiceDiscovery); - } if (element?.combinedServiceFilter !== undefined) { def.combinedServiceFilter = CamelDefinitionApi.createCombinedServiceCallServiceFilterConfiguration(element.combinedServiceFilter); } - if (element?.consulServiceDiscovery !== undefined) { - def.consulServiceDiscovery = CamelDefinitionApi.createConsulServiceCallServiceDiscoveryConfiguration(element.consulServiceDiscovery); - } if (element?.customServiceFilter !== undefined) { def.customServiceFilter = CamelDefinitionApi.createCustomServiceCallServiceFilterConfiguration(element.customServiceFilter); } - if (element?.defaultLoadBalancer !== undefined) { - def.defaultLoadBalancer = CamelDefinitionApi.createDefaultServiceCallServiceLoadBalancerConfiguration(element.defaultLoadBalancer); - } - if (element?.dnsServiceDiscovery !== undefined) { - def.dnsServiceDiscovery = CamelDefinitionApi.createDnsServiceCallServiceDiscoveryConfiguration(element.dnsServiceDiscovery); - } - if (element?.expression !== undefined) { - def.expression = CamelDefinitionApi.createServiceCallExpressionConfiguration(element.expression); - } if (element?.healthyServiceFilter !== undefined) { def.healthyServiceFilter = CamelDefinitionApi.createHealthyServiceCallServiceFilterConfiguration(element.healthyServiceFilter); } - if (element?.kubernetesServiceDiscovery !== undefined) { - def.kubernetesServiceDiscovery = CamelDefinitionApi.createKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery); - } if (element?.passThroughServiceFilter !== undefined) { def.passThroughServiceFilter = CamelDefinitionApi.createPassThroughServiceCallServiceFilterConfiguration(element.passThroughServiceFilter); } - if (element?.staticServiceDiscovery !== undefined) { - def.staticServiceDiscovery = CamelDefinitionApi.createStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery); - } - if (element?.zookeeperServiceDiscovery !== undefined) { - def.zookeeperServiceDiscovery = CamelDefinitionApi.createZooKeeperServiceCallServiceDiscoveryConfiguration(element.zookeeperServiceDiscovery); - } return def; } @@ -1856,48 +1823,8 @@ export class CamelDefinitionApi { } const def = element ? new ServiceCallDefinition({...element}) : new ServiceCallDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; - if (element?.blacklistServiceFilter !== undefined) { - def.blacklistServiceFilter = CamelDefinitionApi.createBlacklistServiceCallServiceFilterConfiguration(element.blacklistServiceFilter); - } - if (element?.cachingServiceDiscovery !== undefined) { - def.cachingServiceDiscovery = CamelDefinitionApi.createCachingServiceCallServiceDiscoveryConfiguration(element.cachingServiceDiscovery); - } - if (element?.combinedServiceDiscovery !== undefined) { - def.combinedServiceDiscovery = CamelDefinitionApi.createCombinedServiceCallServiceDiscoveryConfiguration(element.combinedServiceDiscovery); - } - if (element?.combinedServiceFilter !== undefined) { - def.combinedServiceFilter = CamelDefinitionApi.createCombinedServiceCallServiceFilterConfiguration(element.combinedServiceFilter); - } - if (element?.consulServiceDiscovery !== undefined) { - def.consulServiceDiscovery = CamelDefinitionApi.createConsulServiceCallServiceDiscoveryConfiguration(element.consulServiceDiscovery); - } - if (element?.customServiceFilter !== undefined) { - def.customServiceFilter = CamelDefinitionApi.createCustomServiceCallServiceFilterConfiguration(element.customServiceFilter); - } - if (element?.defaultLoadBalancer !== undefined) { - def.defaultLoadBalancer = CamelDefinitionApi.createDefaultServiceCallServiceLoadBalancerConfiguration(element.defaultLoadBalancer); - } - if (element?.dnsServiceDiscovery !== undefined) { - def.dnsServiceDiscovery = CamelDefinitionApi.createDnsServiceCallServiceDiscoveryConfiguration(element.dnsServiceDiscovery); - } - if (element?.expression !== undefined) { - def.expression = CamelDefinitionApi.createServiceCallExpressionConfiguration(element.expression); - } - if (element?.healthyServiceFilter !== undefined) { - def.healthyServiceFilter = CamelDefinitionApi.createHealthyServiceCallServiceFilterConfiguration(element.healthyServiceFilter); - } - if (element?.kubernetesServiceDiscovery !== undefined) { - def.kubernetesServiceDiscovery = CamelDefinitionApi.createKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery); - } - if (element?.passThroughServiceFilter !== undefined) { - def.passThroughServiceFilter = CamelDefinitionApi.createPassThroughServiceCallServiceFilterConfiguration(element.passThroughServiceFilter); - } - if (element?.staticServiceDiscovery !== undefined) { - def.staticServiceDiscovery = CamelDefinitionApi.createStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery); - } - if (element?.zookeeperServiceDiscovery !== undefined) { - def.zookeeperServiceDiscovery = CamelDefinitionApi.createZooKeeperServiceCallServiceDiscoveryConfiguration(element.zookeeperServiceDiscovery); - } + def.expression = CamelDefinitionApi.createExpressionDefinition(element.expression); + return def; } @@ -2839,8 +2766,8 @@ export class CamelDefinitionApi { static createResponseMessageDefinition = (element: any): ResponseMessageDefinition => { const def = element ? new ResponseMessageDefinition({...element}) : new ResponseMessageDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; - def.examples = element && element?.examples ? element?.examples.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; def.header = element && element?.header ? element?.header.map((x:any) => CamelDefinitionApi.createResponseHeaderDefinition(x)) :[]; + def.examples = element && element?.examples ? element?.examples.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; return def; } @@ -2853,28 +2780,28 @@ export class CamelDefinitionApi { static createRestConfigurationDefinition = (element: any): RestConfigurationDefinition => { const def = element ? new RestConfigurationDefinition({...element}) : new RestConfigurationDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; - def.apiProperty = element && element?.apiProperty ? element?.apiProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; def.componentProperty = element && element?.componentProperty ? element?.componentProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; + def.endpointProperty = element && element?.endpointProperty ? element?.endpointProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; def.consumerProperty = element && element?.consumerProperty ? element?.consumerProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; - def.corsHeaders = element && element?.corsHeaders ? element?.corsHeaders.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; def.dataFormatProperty = element && element?.dataFormatProperty ? element?.dataFormatProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; - def.endpointProperty = element && element?.endpointProperty ? element?.endpointProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; + def.apiProperty = element && element?.apiProperty ? element?.apiProperty.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; + def.corsHeaders = element && element?.corsHeaders ? element?.corsHeaders.map((x:any) => CamelDefinitionApi.createRestPropertyDefinition(x)) :[]; return def; } static createRestDefinition = (element: any): RestDefinition => { const def = element ? new RestDefinition({...element}) : new RestDefinition(); def.uuid = element?.uuid ? element.uuid : def.uuid; + if (element?.securityDefinitions !== undefined) { + def.securityDefinitions = CamelDefinitionApi.createRestSecuritiesDefinition(element.securityDefinitions); + } + def.securityRequirements = element && element?.securityRequirements ? element?.securityRequirements.map((x:any) => CamelDefinitionApi.createSecurityDefinition(x)) :[]; def.delete = element && element?.delete ? element?.delete.map((x:any) => CamelDefinitionApi.createDeleteDefinition(x)) :[]; def.get = element && element?.get ? element?.get.map((x:any) => CamelDefinitionApi.createGetDefinition(x)) :[]; def.head = element && element?.head ? element?.head.map((x:any) => CamelDefinitionApi.createHeadDefinition(x)) :[]; def.patch = element && element?.patch ? element?.patch.map((x:any) => CamelDefinitionApi.createPatchDefinition(x)) :[]; def.post = element && element?.post ? element?.post.map((x:any) => CamelDefinitionApi.createPostDefinition(x)) :[]; def.put = element && element?.put ? element?.put.map((x:any) => CamelDefinitionApi.createPutDefinition(x)) :[]; - if (element?.securityDefinitions !== undefined) { - def.securityDefinitions = CamelDefinitionApi.createRestSecuritiesDefinition(element.securityDefinitions); - } - def.securityRequirements = element && element?.securityRequirements ? element?.securityRequirements.map((x:any) => CamelDefinitionApi.createSecurityDefinition(x)) :[]; return def; } @@ -3222,6 +3149,8 @@ export class CamelDefinitionApi { case 'WhenSkipSendToEndpointDefinition': return CamelDefinitionApi.createWhenSkipSendToEndpointDefinition(newBody); case 'WireTapDefinition': return CamelDefinitionApi.createWireTapDefinition(newBody); case 'ApplicationDefinition': return CamelDefinitionApi.createApplicationDefinition(newBody); + case 'BeanConstructorDefinition': return CamelDefinitionApi.createBeanConstructorDefinition(newBody); + case 'BeanConstructorsDefinition': return CamelDefinitionApi.createBeanConstructorsDefinition(newBody); case 'BeanPropertiesDefinition': return CamelDefinitionApi.createBeanPropertiesDefinition(newBody); case 'BeanPropertyDefinition': return CamelDefinitionApi.createBeanPropertyDefinition(newBody); case 'BeansDefinition': return CamelDefinitionApi.createBeansDefinition(newBody); @@ -3369,29 +3298,29 @@ export class CamelDefinitionApi { delete newBody.expressionName; delete newBody.dslName; switch (name) { - case 'XPathExpression': return CamelDefinitionApi.createXPathExpression(newBody); case 'ConstantExpression': return CamelDefinitionApi.createConstantExpression(newBody); - case 'GroovyExpression': return CamelDefinitionApi.createGroovyExpression(newBody); - case 'SimpleExpression': return CamelDefinitionApi.createSimpleExpression(newBody); - case 'MvelExpression': return CamelDefinitionApi.createMvelExpression(newBody); - case 'RefExpression': return CamelDefinitionApi.createRefExpression(newBody); - case 'MethodCallExpression': return CamelDefinitionApi.createMethodCallExpression(newBody); - case 'LanguageExpression': return CamelDefinitionApi.createLanguageExpression(newBody); + case 'CSimpleExpression': return CamelDefinitionApi.createCSimpleExpression(newBody); + case 'DatasonnetExpression': return CamelDefinitionApi.createDatasonnetExpression(newBody); case 'ExchangePropertyExpression': return CamelDefinitionApi.createExchangePropertyExpression(newBody); + case 'GroovyExpression': return CamelDefinitionApi.createGroovyExpression(newBody); + case 'HeaderExpression': return CamelDefinitionApi.createHeaderExpression(newBody); + case 'Hl7TerserExpression': return CamelDefinitionApi.createHl7TerserExpression(newBody); + case 'JoorExpression': return CamelDefinitionApi.createJoorExpression(newBody); + case 'JqExpression': return CamelDefinitionApi.createJqExpression(newBody); case 'JavaScriptExpression': return CamelDefinitionApi.createJavaScriptExpression(newBody); + case 'JsonPathExpression': return CamelDefinitionApi.createJsonPathExpression(newBody); + case 'LanguageExpression': return CamelDefinitionApi.createLanguageExpression(newBody); + case 'MethodCallExpression': return CamelDefinitionApi.createMethodCallExpression(newBody); + case 'MvelExpression': return CamelDefinitionApi.createMvelExpression(newBody); case 'OgnlExpression': return CamelDefinitionApi.createOgnlExpression(newBody); case 'PythonExpression': return CamelDefinitionApi.createPythonExpression(newBody); + case 'RefExpression': return CamelDefinitionApi.createRefExpression(newBody); + case 'SimpleExpression': return CamelDefinitionApi.createSimpleExpression(newBody); + case 'SpELExpression': return CamelDefinitionApi.createSpELExpression(newBody); + case 'TokenizerExpression': return CamelDefinitionApi.createTokenizerExpression(newBody); + case 'XPathExpression': return CamelDefinitionApi.createXPathExpression(newBody); case 'XQueryExpression': return CamelDefinitionApi.createXQueryExpression(newBody); - case 'HeaderExpression': return CamelDefinitionApi.createHeaderExpression(newBody); - case 'CSimpleExpression': return CamelDefinitionApi.createCSimpleExpression(newBody); case 'XMLTokenizerExpression': return CamelDefinitionApi.createXMLTokenizerExpression(newBody); - case 'JqExpression': return CamelDefinitionApi.createJqExpression(newBody); - case 'DatasonnetExpression': return CamelDefinitionApi.createDatasonnetExpression(newBody); - case 'TokenizerExpression': return CamelDefinitionApi.createTokenizerExpression(newBody); - case 'SpELExpression': return CamelDefinitionApi.createSpELExpression(newBody); - case 'JoorExpression': return CamelDefinitionApi.createJoorExpression(newBody); - case 'JsonPathExpression': return CamelDefinitionApi.createJsonPathExpression(newBody); - case 'Hl7TerserExpression': return CamelDefinitionApi.createHl7TerserExpression(newBody); default: return new SimpleExpression(newBody); } } @@ -3401,46 +3330,46 @@ export class CamelDefinitionApi { delete newBody.dataFormatName; delete newBody.dslName; switch (name) { - case 'TarFileDataFormat': return CamelDefinitionApi.createTarFileDataFormat(newBody); + case 'ASN1DataFormat': return CamelDefinitionApi.createASN1DataFormat(newBody); + case 'AvroDataFormat': return CamelDefinitionApi.createAvroDataFormat(newBody); + case 'BarcodeDataFormat': return CamelDefinitionApi.createBarcodeDataFormat(newBody); + case 'Base64DataFormat': return CamelDefinitionApi.createBase64DataFormat(newBody); + case 'BindyDataFormat': return CamelDefinitionApi.createBindyDataFormat(newBody); case 'CBORDataFormat': return CamelDefinitionApi.createCBORDataFormat(newBody); - case 'LZFDataFormat': return CamelDefinitionApi.createLZFDataFormat(newBody); - case 'UniVocityFixedDataFormat': return CamelDefinitionApi.createUniVocityFixedDataFormat(newBody); - case 'JsonApiDataFormat': return CamelDefinitionApi.createJsonApiDataFormat(newBody); - case 'XMLSecurityDataFormat': return CamelDefinitionApi.createXMLSecurityDataFormat(newBody); - case 'TidyMarkupDataFormat': return CamelDefinitionApi.createTidyMarkupDataFormat(newBody); - case 'FhirJsonDataFormat': return CamelDefinitionApi.createFhirJsonDataFormat(newBody); - case 'ThriftDataFormat': return CamelDefinitionApi.createThriftDataFormat(newBody); - case 'IcalDataFormat': return CamelDefinitionApi.createIcalDataFormat(newBody); case 'CryptoDataFormat': return CamelDefinitionApi.createCryptoDataFormat(newBody); - case 'ZipFileDataFormat': return CamelDefinitionApi.createZipFileDataFormat(newBody); - case 'JaxbDataFormat': return CamelDefinitionApi.createJaxbDataFormat(newBody); - case 'UniVocityTsvDataFormat': return CamelDefinitionApi.createUniVocityTsvDataFormat(newBody); - case 'BarcodeDataFormat': return CamelDefinitionApi.createBarcodeDataFormat(newBody); case 'CsvDataFormat': return CamelDefinitionApi.createCsvDataFormat(newBody); - case 'GrokDataFormat': return CamelDefinitionApi.createGrokDataFormat(newBody); + case 'CustomDataFormat': return CamelDefinitionApi.createCustomDataFormat(newBody); + case 'FhirJsonDataFormat': return CamelDefinitionApi.createFhirJsonDataFormat(newBody); + case 'FhirXmlDataFormat': return CamelDefinitionApi.createFhirXmlDataFormat(newBody); case 'FlatpackDataFormat': return CamelDefinitionApi.createFlatpackDataFormat(newBody); - case 'SoapDataFormat': return CamelDefinitionApi.createSoapDataFormat(newBody); - case 'AvroDataFormat': return CamelDefinitionApi.createAvroDataFormat(newBody); + case 'GrokDataFormat': return CamelDefinitionApi.createGrokDataFormat(newBody); case 'GzipDeflaterDataFormat': return CamelDefinitionApi.createGzipDeflaterDataFormat(newBody); + case 'HL7DataFormat': return CamelDefinitionApi.createHL7DataFormat(newBody); + case 'IcalDataFormat': return CamelDefinitionApi.createIcalDataFormat(newBody); case 'JacksonXMLDataFormat': return CamelDefinitionApi.createJacksonXMLDataFormat(newBody); - case 'ProtobufDataFormat': return CamelDefinitionApi.createProtobufDataFormat(newBody); - case 'BindyDataFormat': return CamelDefinitionApi.createBindyDataFormat(newBody); + case 'JaxbDataFormat': return CamelDefinitionApi.createJaxbDataFormat(newBody); case 'JsonDataFormat': return CamelDefinitionApi.createJsonDataFormat(newBody); + case 'JsonApiDataFormat': return CamelDefinitionApi.createJsonApiDataFormat(newBody); + case 'LZFDataFormat': return CamelDefinitionApi.createLZFDataFormat(newBody); case 'MimeMultipartDataFormat': return CamelDefinitionApi.createMimeMultipartDataFormat(newBody); - case 'ZipDeflaterDataFormat': return CamelDefinitionApi.createZipDeflaterDataFormat(newBody); - case 'ASN1DataFormat': return CamelDefinitionApi.createASN1DataFormat(newBody); - case 'YAMLDataFormat': return CamelDefinitionApi.createYAMLDataFormat(newBody); - case 'SwiftMxDataFormat': return CamelDefinitionApi.createSwiftMxDataFormat(newBody); - case 'CustomDataFormat': return CamelDefinitionApi.createCustomDataFormat(newBody); - case 'HL7DataFormat': return CamelDefinitionApi.createHL7DataFormat(newBody); - case 'Base64DataFormat': return CamelDefinitionApi.createBase64DataFormat(newBody); - case 'RssDataFormat': return CamelDefinitionApi.createRssDataFormat(newBody); - case 'PGPDataFormat': return CamelDefinitionApi.createPGPDataFormat(newBody); - case 'UniVocityCsvDataFormat': return CamelDefinitionApi.createUniVocityCsvDataFormat(newBody); - case 'SyslogDataFormat': return CamelDefinitionApi.createSyslogDataFormat(newBody); case 'ParquetAvroDataFormat': return CamelDefinitionApi.createParquetAvroDataFormat(newBody); - case 'FhirXmlDataFormat': return CamelDefinitionApi.createFhirXmlDataFormat(newBody); + case 'PGPDataFormat': return CamelDefinitionApi.createPGPDataFormat(newBody); + case 'ProtobufDataFormat': return CamelDefinitionApi.createProtobufDataFormat(newBody); + case 'RssDataFormat': return CamelDefinitionApi.createRssDataFormat(newBody); + case 'SoapDataFormat': return CamelDefinitionApi.createSoapDataFormat(newBody); case 'SwiftMtDataFormat': return CamelDefinitionApi.createSwiftMtDataFormat(newBody); + case 'SwiftMxDataFormat': return CamelDefinitionApi.createSwiftMxDataFormat(newBody); + case 'SyslogDataFormat': return CamelDefinitionApi.createSyslogDataFormat(newBody); + case 'TarFileDataFormat': return CamelDefinitionApi.createTarFileDataFormat(newBody); + case 'ThriftDataFormat': return CamelDefinitionApi.createThriftDataFormat(newBody); + case 'TidyMarkupDataFormat': return CamelDefinitionApi.createTidyMarkupDataFormat(newBody); + case 'UniVocityCsvDataFormat': return CamelDefinitionApi.createUniVocityCsvDataFormat(newBody); + case 'UniVocityFixedDataFormat': return CamelDefinitionApi.createUniVocityFixedDataFormat(newBody); + case 'UniVocityTsvDataFormat': return CamelDefinitionApi.createUniVocityTsvDataFormat(newBody); + case 'XMLSecurityDataFormat': return CamelDefinitionApi.createXMLSecurityDataFormat(newBody); + case 'YAMLDataFormat': return CamelDefinitionApi.createYAMLDataFormat(newBody); + case 'ZipDeflaterDataFormat': return CamelDefinitionApi.createZipDeflaterDataFormat(newBody); + case 'ZipFileDataFormat': return CamelDefinitionApi.createZipFileDataFormat(newBody); default: return new JsonDataFormat(newBody); } } diff --git a/karavan-core/src/core/api/CamelDefinitionYamlStep.ts b/karavan-core/src/core/api/CamelDefinitionYamlStep.ts index 0a1ef7c66f8..646bb533f9e 100644 --- a/karavan-core/src/core/api/CamelDefinitionYamlStep.ts +++ b/karavan-core/src/core/api/CamelDefinitionYamlStep.ts @@ -122,6 +122,8 @@ import { WhenSkipSendToEndpointDefinition, WireTapDefinition, ApplicationDefinition, + BeanConstructorDefinition, + BeanConstructorsDefinition, BeanPropertiesDefinition, BeanPropertyDefinition, BeansDefinition, @@ -326,13 +328,6 @@ export class CamelDefinitionYamlStep { def.split = CamelDefinitionYamlStep.readSplitDefinition(element.split); } } - if (element?.interceptSendToEndpoint !== undefined) { - if (Array.isArray(element.interceptSendToEndpoint)) { - def.interceptSendToEndpoint = CamelDefinitionYamlStep.readInterceptSendToEndpointDefinition(element.interceptSendToEndpoint[0]); - } else { - def.interceptSendToEndpoint = CamelDefinitionYamlStep.readInterceptSendToEndpointDefinition(element.interceptSendToEndpoint); - } - } if (element?.loop !== undefined) { if (Array.isArray(element.loop)) { def.loop = CamelDefinitionYamlStep.readLoopDefinition(element.loop[0]); @@ -452,13 +447,6 @@ export class CamelDefinitionYamlStep { def.serviceCall = CamelDefinitionYamlStep.readServiceCallDefinition(element.serviceCall); } } - if (element?.intercept !== undefined) { - if (Array.isArray(element.intercept)) { - def.intercept = CamelDefinitionYamlStep.readInterceptDefinition(element.intercept[0]); - } else { - def.intercept = CamelDefinitionYamlStep.readInterceptDefinition(element.intercept); - } - } if (element?.whenSkipSendToEndpoint !== undefined) { if (Array.isArray(element.whenSkipSendToEndpoint)) { def.whenSkipSendToEndpoint = CamelDefinitionYamlStep.readWhenSkipSendToEndpointDefinition(element.whenSkipSendToEndpoint[0]); @@ -480,20 +468,6 @@ export class CamelDefinitionYamlStep { def.removeProperty = CamelDefinitionYamlStep.readRemovePropertyDefinition(element.removeProperty); } } - if (element?.interceptFrom !== undefined) { - if (Array.isArray(element.interceptFrom)) { - def.interceptFrom = CamelDefinitionYamlStep.readInterceptFromDefinition(element.interceptFrom[0]); - } else { - def.interceptFrom = CamelDefinitionYamlStep.readInterceptFromDefinition(element.interceptFrom); - } - } - if (element?.onCompletion !== undefined) { - if (Array.isArray(element.onCompletion)) { - def.onCompletion = CamelDefinitionYamlStep.readOnCompletionDefinition(element.onCompletion[0]); - } else { - def.onCompletion = CamelDefinitionYamlStep.readOnCompletionDefinition(element.onCompletion); - } - } if (element?.pausable !== undefined) { if (Array.isArray(element.pausable)) { def.pausable = CamelDefinitionYamlStep.readPausableDefinition(element.pausable[0]); @@ -1329,7 +1303,6 @@ export class CamelDefinitionYamlStep { def.topic = CamelDefinitionYamlStep.readTopicLoadBalancerDefinition(element.topic); } } - def.steps = CamelDefinitionYamlStep.readSteps(element?.steps); if (element?.weighted !== undefined) { if (Array.isArray(element.weighted)) { def.weighted = CamelDefinitionYamlStep.readWeightedLoadBalancerDefinition(element.weighted[0]); @@ -1337,6 +1310,7 @@ export class CamelDefinitionYamlStep { def.weighted = CamelDefinitionYamlStep.readWeightedLoadBalancerDefinition(element.weighted); } } + def.steps = CamelDefinitionYamlStep.readSteps(element?.steps); if (element?.roundRobin !== undefined) { if (Array.isArray(element.roundRobin)) { def.roundRobin = CamelDefinitionYamlStep.readRoundRobinLoadBalancerDefinition(element.roundRobin[0]); @@ -1901,13 +1875,6 @@ export class CamelDefinitionYamlStep { static readResequenceDefinition = (element: any): ResequenceDefinition => { let def = element ? new ResequenceDefinition({...element}) : new ResequenceDefinition(); - if (element?.streamConfig !== undefined) { - if (Array.isArray(element.streamConfig)) { - def.streamConfig = CamelDefinitionYamlStep.readStreamResequencerConfig(element.streamConfig[0]); - } else { - def.streamConfig = CamelDefinitionYamlStep.readStreamResequencerConfig(element.streamConfig); - } - } if (element?.expression !== undefined) { def.expression = CamelDefinitionYamlStep.readExpressionDefinition(element.expression); } else { @@ -1920,13 +1887,6 @@ export class CamelDefinitionYamlStep { } } def.steps = CamelDefinitionYamlStep.readSteps(element?.steps); - if (element?.batchConfig !== undefined) { - if (Array.isArray(element.batchConfig)) { - def.batchConfig = CamelDefinitionYamlStep.readBatchResequencerConfig(element.batchConfig[0]); - } else { - def.batchConfig = CamelDefinitionYamlStep.readBatchResequencerConfig(element.batchConfig); - } - } return def; } @@ -1976,9 +1936,6 @@ export class CamelDefinitionYamlStep { static readRouteConfigurationDefinition = (element: any): RouteConfigurationDefinition => { let def = element ? new RouteConfigurationDefinition({...element}) : new RouteConfigurationDefinition(); - def.onCompletion = element && element?.onCompletion ? element?.onCompletion.map((x:any) => CamelDefinitionYamlStep.readOnCompletionDefinition(x.onCompletion)) :[]; - def.interceptSendToEndpoint = element && element?.interceptSendToEndpoint ? element?.interceptSendToEndpoint.map((x:any) => CamelDefinitionYamlStep.readInterceptSendToEndpointDefinition(x.interceptSendToEndpoint)) :[]; - def.intercept = element && element?.intercept ? element?.intercept.map((x:any) => CamelDefinitionYamlStep.readInterceptDefinition(x.intercept)) :[]; if (element?.errorHandler !== undefined) { if (Array.isArray(element.errorHandler)) { def.errorHandler = CamelDefinitionYamlStep.readErrorHandlerDefinition(element.errorHandler[0]); @@ -1986,8 +1943,6 @@ export class CamelDefinitionYamlStep { def.errorHandler = CamelDefinitionYamlStep.readErrorHandlerDefinition(element.errorHandler); } } - def.onException = element && element?.onException ? element?.onException.map((x:any) => CamelDefinitionYamlStep.readOnExceptionDefinition(x.onException)) :[]; - def.interceptFrom = element && element?.interceptFrom ? element?.interceptFrom.map((x:any) => CamelDefinitionYamlStep.readInterceptFromDefinition(x.interceptFrom)) :[]; return def; } @@ -2739,6 +2694,21 @@ export class CamelDefinitionYamlStep { return def; } + static readBeanConstructorDefinition = (element: any): BeanConstructorDefinition => { + + let def = element ? new BeanConstructorDefinition({...element}) : new BeanConstructorDefinition(); + + return def; + } + + static readBeanConstructorsDefinition = (element: any): BeanConstructorsDefinition => { + + let def = element ? new BeanConstructorsDefinition({...element}) : new BeanConstructorsDefinition(); + def.constructor = element && element?.constructor ? element?.constructor.map((x:any) => CamelDefinitionYamlStep.readBeanConstructorDefinition(x)) :[]; + + return def; + } + static readBeanPropertiesDefinition = (element: any): BeanPropertiesDefinition => { let def = element ? new BeanPropertiesDefinition({...element}) : new BeanPropertiesDefinition(); @@ -2980,41 +2950,6 @@ export class CamelDefinitionYamlStep { let def = element ? new ServiceCallConfigurationDefinition({...element}) : new ServiceCallConfigurationDefinition(); def = ComponentApi.parseElementUri(def); - if (element?.defaultLoadBalancer !== undefined) { - if (Array.isArray(element.defaultLoadBalancer)) { - def.defaultLoadBalancer = CamelDefinitionYamlStep.readDefaultServiceCallServiceLoadBalancerConfiguration(element.defaultLoadBalancer[0]); - } else { - def.defaultLoadBalancer = CamelDefinitionYamlStep.readDefaultServiceCallServiceLoadBalancerConfiguration(element.defaultLoadBalancer); - } - } - if (element?.expression !== undefined) { - if (Array.isArray(element.expression)) { - def.expression = CamelDefinitionYamlStep.readServiceCallExpressionConfiguration(element.expression[0]); - } else { - def.expression = CamelDefinitionYamlStep.readServiceCallExpressionConfiguration(element.expression); - } - } - if (element?.kubernetesServiceDiscovery !== undefined) { - if (Array.isArray(element.kubernetesServiceDiscovery)) { - def.kubernetesServiceDiscovery = CamelDefinitionYamlStep.readKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery[0]); - } else { - def.kubernetesServiceDiscovery = CamelDefinitionYamlStep.readKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery); - } - } - if (element?.customServiceFilter !== undefined) { - if (Array.isArray(element.customServiceFilter)) { - def.customServiceFilter = CamelDefinitionYamlStep.readCustomServiceCallServiceFilterConfiguration(element.customServiceFilter[0]); - } else { - def.customServiceFilter = CamelDefinitionYamlStep.readCustomServiceCallServiceFilterConfiguration(element.customServiceFilter); - } - } - if (element?.zookeeperServiceDiscovery !== undefined) { - if (Array.isArray(element.zookeeperServiceDiscovery)) { - def.zookeeperServiceDiscovery = CamelDefinitionYamlStep.readZooKeeperServiceCallServiceDiscoveryConfiguration(element.zookeeperServiceDiscovery[0]); - } else { - def.zookeeperServiceDiscovery = CamelDefinitionYamlStep.readZooKeeperServiceCallServiceDiscoveryConfiguration(element.zookeeperServiceDiscovery); - } - } if (element?.blacklistServiceFilter !== undefined) { if (Array.isArray(element.blacklistServiceFilter)) { def.blacklistServiceFilter = CamelDefinitionYamlStep.readBlacklistServiceCallServiceFilterConfiguration(element.blacklistServiceFilter[0]); @@ -3022,6 +2957,17 @@ export class CamelDefinitionYamlStep { def.blacklistServiceFilter = CamelDefinitionYamlStep.readBlacklistServiceCallServiceFilterConfiguration(element.blacklistServiceFilter); } } + if (element?.expression !== undefined) { + def.expression = CamelDefinitionYamlStep.readExpressionDefinition(element.expression); + } else { + const languageName: string | undefined = Object.keys(element).filter(key => CamelMetadataApi.hasLanguage(key))[0] || undefined; + if (languageName){ + const exp:any = {}; + exp[languageName] = element[languageName] + def.expression = CamelDefinitionYamlStep.readExpressionDefinition(exp); + delete (def as any)[languageName]; + } + } if (element?.passThroughServiceFilter !== undefined) { if (Array.isArray(element.passThroughServiceFilter)) { def.passThroughServiceFilter = CamelDefinitionYamlStep.readPassThroughServiceCallServiceFilterConfiguration(element.passThroughServiceFilter[0]); @@ -3029,20 +2975,6 @@ export class CamelDefinitionYamlStep { def.passThroughServiceFilter = CamelDefinitionYamlStep.readPassThroughServiceCallServiceFilterConfiguration(element.passThroughServiceFilter); } } - if (element?.cachingServiceDiscovery !== undefined) { - if (Array.isArray(element.cachingServiceDiscovery)) { - def.cachingServiceDiscovery = CamelDefinitionYamlStep.readCachingServiceCallServiceDiscoveryConfiguration(element.cachingServiceDiscovery[0]); - } else { - def.cachingServiceDiscovery = CamelDefinitionYamlStep.readCachingServiceCallServiceDiscoveryConfiguration(element.cachingServiceDiscovery); - } - } - if (element?.dnsServiceDiscovery !== undefined) { - if (Array.isArray(element.dnsServiceDiscovery)) { - def.dnsServiceDiscovery = CamelDefinitionYamlStep.readDnsServiceCallServiceDiscoveryConfiguration(element.dnsServiceDiscovery[0]); - } else { - def.dnsServiceDiscovery = CamelDefinitionYamlStep.readDnsServiceCallServiceDiscoveryConfiguration(element.dnsServiceDiscovery); - } - } if (element?.healthyServiceFilter !== undefined) { if (Array.isArray(element.healthyServiceFilter)) { def.healthyServiceFilter = CamelDefinitionYamlStep.readHealthyServiceCallServiceFilterConfiguration(element.healthyServiceFilter[0]); @@ -3057,25 +2989,11 @@ export class CamelDefinitionYamlStep { def.combinedServiceFilter = CamelDefinitionYamlStep.readCombinedServiceCallServiceFilterConfiguration(element.combinedServiceFilter); } } - if (element?.consulServiceDiscovery !== undefined) { - if (Array.isArray(element.consulServiceDiscovery)) { - def.consulServiceDiscovery = CamelDefinitionYamlStep.readConsulServiceCallServiceDiscoveryConfiguration(element.consulServiceDiscovery[0]); - } else { - def.consulServiceDiscovery = CamelDefinitionYamlStep.readConsulServiceCallServiceDiscoveryConfiguration(element.consulServiceDiscovery); - } - } - if (element?.staticServiceDiscovery !== undefined) { - if (Array.isArray(element.staticServiceDiscovery)) { - def.staticServiceDiscovery = CamelDefinitionYamlStep.readStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery[0]); - } else { - def.staticServiceDiscovery = CamelDefinitionYamlStep.readStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery); - } - } - if (element?.combinedServiceDiscovery !== undefined) { - if (Array.isArray(element.combinedServiceDiscovery)) { - def.combinedServiceDiscovery = CamelDefinitionYamlStep.readCombinedServiceCallServiceDiscoveryConfiguration(element.combinedServiceDiscovery[0]); + if (element?.customServiceFilter !== undefined) { + if (Array.isArray(element.customServiceFilter)) { + def.customServiceFilter = CamelDefinitionYamlStep.readCustomServiceCallServiceFilterConfiguration(element.customServiceFilter[0]); } else { - def.combinedServiceDiscovery = CamelDefinitionYamlStep.readCombinedServiceCallServiceDiscoveryConfiguration(element.combinedServiceDiscovery); + def.customServiceFilter = CamelDefinitionYamlStep.readCustomServiceCallServiceFilterConfiguration(element.customServiceFilter); } } @@ -3086,104 +3004,17 @@ export class CamelDefinitionYamlStep { if (element && typeof element === 'string') element = {name: element}; let def = element ? new ServiceCallDefinition({...element}) : new ServiceCallDefinition(); def = ComponentApi.parseElementUri(def); - if (element?.defaultLoadBalancer !== undefined) { - if (Array.isArray(element.defaultLoadBalancer)) { - def.defaultLoadBalancer = CamelDefinitionYamlStep.readDefaultServiceCallServiceLoadBalancerConfiguration(element.defaultLoadBalancer[0]); - } else { - def.defaultLoadBalancer = CamelDefinitionYamlStep.readDefaultServiceCallServiceLoadBalancerConfiguration(element.defaultLoadBalancer); - } - } if (element?.expression !== undefined) { - if (Array.isArray(element.expression)) { - def.expression = CamelDefinitionYamlStep.readServiceCallExpressionConfiguration(element.expression[0]); - } else { - def.expression = CamelDefinitionYamlStep.readServiceCallExpressionConfiguration(element.expression); - } - } - if (element?.kubernetesServiceDiscovery !== undefined) { - if (Array.isArray(element.kubernetesServiceDiscovery)) { - def.kubernetesServiceDiscovery = CamelDefinitionYamlStep.readKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery[0]); - } else { - def.kubernetesServiceDiscovery = CamelDefinitionYamlStep.readKubernetesServiceCallServiceDiscoveryConfiguration(element.kubernetesServiceDiscovery); - } - } - if (element?.customServiceFilter !== undefined) { - if (Array.isArray(element.customServiceFilter)) { - def.customServiceFilter = CamelDefinitionYamlStep.readCustomServiceCallServiceFilterConfiguration(element.customServiceFilter[0]); - } else { - def.customServiceFilter = CamelDefinitionYamlStep.readCustomServiceCallServiceFilterConfiguration(element.customServiceFilter); - } - } - if (element?.zookeeperServiceDiscovery !== undefined) { - if (Array.isArray(element.zookeeperServiceDiscovery)) { - def.zookeeperServiceDiscovery = CamelDefinitionYamlStep.readZooKeeperServiceCallServiceDiscoveryConfiguration(element.zookeeperServiceDiscovery[0]); - } else { - def.zookeeperServiceDiscovery = CamelDefinitionYamlStep.readZooKeeperServiceCallServiceDiscoveryConfiguration(element.zookeeperServiceDiscovery); - } - } - if (element?.blacklistServiceFilter !== undefined) { - if (Array.isArray(element.blacklistServiceFilter)) { - def.blacklistServiceFilter = CamelDefinitionYamlStep.readBlacklistServiceCallServiceFilterConfiguration(element.blacklistServiceFilter[0]); - } else { - def.blacklistServiceFilter = CamelDefinitionYamlStep.readBlacklistServiceCallServiceFilterConfiguration(element.blacklistServiceFilter); - } - } - if (element?.passThroughServiceFilter !== undefined) { - if (Array.isArray(element.passThroughServiceFilter)) { - def.passThroughServiceFilter = CamelDefinitionYamlStep.readPassThroughServiceCallServiceFilterConfiguration(element.passThroughServiceFilter[0]); - } else { - def.passThroughServiceFilter = CamelDefinitionYamlStep.readPassThroughServiceCallServiceFilterConfiguration(element.passThroughServiceFilter); - } - } - if (element?.cachingServiceDiscovery !== undefined) { - if (Array.isArray(element.cachingServiceDiscovery)) { - def.cachingServiceDiscovery = CamelDefinitionYamlStep.readCachingServiceCallServiceDiscoveryConfiguration(element.cachingServiceDiscovery[0]); - } else { - def.cachingServiceDiscovery = CamelDefinitionYamlStep.readCachingServiceCallServiceDiscoveryConfiguration(element.cachingServiceDiscovery); - } - } - if (element?.dnsServiceDiscovery !== undefined) { - if (Array.isArray(element.dnsServiceDiscovery)) { - def.dnsServiceDiscovery = CamelDefinitionYamlStep.readDnsServiceCallServiceDiscoveryConfiguration(element.dnsServiceDiscovery[0]); - } else { - def.dnsServiceDiscovery = CamelDefinitionYamlStep.readDnsServiceCallServiceDiscoveryConfiguration(element.dnsServiceDiscovery); - } - } - if (element?.healthyServiceFilter !== undefined) { - if (Array.isArray(element.healthyServiceFilter)) { - def.healthyServiceFilter = CamelDefinitionYamlStep.readHealthyServiceCallServiceFilterConfiguration(element.healthyServiceFilter[0]); - } else { - def.healthyServiceFilter = CamelDefinitionYamlStep.readHealthyServiceCallServiceFilterConfiguration(element.healthyServiceFilter); - } - } - if (element?.combinedServiceFilter !== undefined) { - if (Array.isArray(element.combinedServiceFilter)) { - def.combinedServiceFilter = CamelDefinitionYamlStep.readCombinedServiceCallServiceFilterConfiguration(element.combinedServiceFilter[0]); - } else { - def.combinedServiceFilter = CamelDefinitionYamlStep.readCombinedServiceCallServiceFilterConfiguration(element.combinedServiceFilter); - } - } - if (element?.consulServiceDiscovery !== undefined) { - if (Array.isArray(element.consulServiceDiscovery)) { - def.consulServiceDiscovery = CamelDefinitionYamlStep.readConsulServiceCallServiceDiscoveryConfiguration(element.consulServiceDiscovery[0]); - } else { - def.consulServiceDiscovery = CamelDefinitionYamlStep.readConsulServiceCallServiceDiscoveryConfiguration(element.consulServiceDiscovery); - } - } - if (element?.staticServiceDiscovery !== undefined) { - if (Array.isArray(element.staticServiceDiscovery)) { - def.staticServiceDiscovery = CamelDefinitionYamlStep.readStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery[0]); - } else { - def.staticServiceDiscovery = CamelDefinitionYamlStep.readStaticServiceCallServiceDiscoveryConfiguration(element.staticServiceDiscovery); - } - } - if (element?.combinedServiceDiscovery !== undefined) { - if (Array.isArray(element.combinedServiceDiscovery)) { - def.combinedServiceDiscovery = CamelDefinitionYamlStep.readCombinedServiceCallServiceDiscoveryConfiguration(element.combinedServiceDiscovery[0]); - } else { - def.combinedServiceDiscovery = CamelDefinitionYamlStep.readCombinedServiceCallServiceDiscoveryConfiguration(element.combinedServiceDiscovery); - } - } + def.expression = CamelDefinitionYamlStep.readExpressionDefinition(element.expression); + } else { + const languageName: string | undefined = Object.keys(element).filter(key => CamelMetadataApi.hasLanguage(key))[0] || undefined; + if (languageName){ + const exp:any = {}; + exp[languageName] = element[languageName] + def.expression = CamelDefinitionYamlStep.readExpressionDefinition(exp); + delete (def as any)[languageName]; + } + } return def; } @@ -4454,8 +4285,8 @@ export class CamelDefinitionYamlStep { def.corsHeaders = element && element?.corsHeaders ? element?.corsHeaders.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; def.dataFormatProperty = element && element?.dataFormatProperty ? element?.dataFormatProperty.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; def.consumerProperty = element && element?.consumerProperty ? element?.consumerProperty.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; - def.apiProperty = element && element?.apiProperty ? element?.apiProperty.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; def.endpointProperty = element && element?.endpointProperty ? element?.endpointProperty.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; + def.apiProperty = element && element?.apiProperty ? element?.apiProperty.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; def.componentProperty = element && element?.componentProperty ? element?.componentProperty.map((x:any) => CamelDefinitionYamlStep.readRestPropertyDefinition(x)) :[]; return def; @@ -4467,9 +4298,8 @@ export class CamelDefinitionYamlStep { def.head = element && element?.head ? element?.head.map((x:any) => CamelDefinitionYamlStep.readHeadDefinition(x)) :[]; def.patch = element && element?.patch ? element?.patch.map((x:any) => CamelDefinitionYamlStep.readPatchDefinition(x)) :[]; def.post = element && element?.post ? element?.post.map((x:any) => CamelDefinitionYamlStep.readPostDefinition(x)) :[]; - def.get = element && element?.get ? element?.get.map((x:any) => CamelDefinitionYamlStep.readGetDefinition(x)) :[]; def.securityRequirements = element && element?.securityRequirements ? element?.securityRequirements.map((x:any) => CamelDefinitionYamlStep.readSecurityDefinition(x)) :[]; - def.delete = element && element?.delete ? element?.delete.map((x:any) => CamelDefinitionYamlStep.readDeleteDefinition(x)) :[]; + def.get = element && element?.get ? element?.get.map((x:any) => CamelDefinitionYamlStep.readGetDefinition(x)) :[]; if (element?.securityDefinitions !== undefined) { if (Array.isArray(element.securityDefinitions)) { def.securityDefinitions = CamelDefinitionYamlStep.readRestSecuritiesDefinition(element.securityDefinitions[0]); @@ -4477,6 +4307,7 @@ export class CamelDefinitionYamlStep { def.securityDefinitions = CamelDefinitionYamlStep.readRestSecuritiesDefinition(element.securityDefinitions); } } + def.delete = element && element?.delete ? element?.delete.map((x:any) => CamelDefinitionYamlStep.readDeleteDefinition(x)) :[]; def.put = element && element?.put ? element?.put.map((x:any) => CamelDefinitionYamlStep.readPutDefinition(x)) :[]; return def; @@ -4962,71 +4793,66 @@ export class CamelDefinitionYamlStep { const name = Object.getOwnPropertyNames(body)[0]; const newBody = CamelUtil.camelizeBody(name, body[name], clone); switch (name) { - case 'setProperty': return CamelDefinitionYamlStep.readSetPropertyDefinition(newBody); - case 'to': return CamelDefinitionYamlStep.readToDefinition(newBody); - case 'doCatch': return CamelDefinitionYamlStep.readCatchDefinition(newBody); - case 'onFallback': return CamelDefinitionYamlStep.readOnFallbackDefinition(newBody); - case 'loadBalance': return CamelDefinitionYamlStep.readLoadBalanceDefinition(newBody); - case 'process': return CamelDefinitionYamlStep.readProcessDefinition(newBody); + case 'aggregate': return CamelDefinitionYamlStep.readAggregateDefinition(newBody); case 'bean': return CamelDefinitionYamlStep.readBeanDefinition(newBody); - case 'transacted': return CamelDefinitionYamlStep.readTransactedDefinition(newBody); - case 'pollEnrich': return CamelDefinitionYamlStep.readPollEnrichDefinition(newBody); - case 'filter': return CamelDefinitionYamlStep.readFilterDefinition(newBody); - case 'pausable': return CamelDefinitionYamlStep.readPausableDefinition(newBody); - case 'setBody': return CamelDefinitionYamlStep.readSetBodyDefinition(newBody); + case 'doCatch': return CamelDefinitionYamlStep.readCatchDefinition(newBody); + case 'choice': return CamelDefinitionYamlStep.readChoiceDefinition(newBody); + case 'circuitBreaker': return CamelDefinitionYamlStep.readCircuitBreakerDefinition(newBody); case 'claimCheck': return CamelDefinitionYamlStep.readClaimCheckDefinition(newBody); - case 'step': return CamelDefinitionYamlStep.readStepDefinition(newBody); - case 'aggregate': return CamelDefinitionYamlStep.readAggregateDefinition(newBody); - case 'when': return CamelDefinitionYamlStep.readWhenDefinition(newBody); - case 'loop': return CamelDefinitionYamlStep.readLoopDefinition(newBody); - case 'stop': return CamelDefinitionYamlStep.readStopDefinition(newBody); - case 'resumable': return CamelDefinitionYamlStep.readResumableDefinition(newBody); - case 'removeProperty': return CamelDefinitionYamlStep.readRemovePropertyDefinition(newBody); - case 'split': return CamelDefinitionYamlStep.readSplitDefinition(newBody); - case 'multicast': return CamelDefinitionYamlStep.readMulticastDefinition(newBody); - case 'otherwise': return CamelDefinitionYamlStep.readOtherwiseDefinition(newBody); - case 'removeProperties': return CamelDefinitionYamlStep.readRemovePropertiesDefinition(newBody); - case 'saga': return CamelDefinitionYamlStep.readSagaDefinition(newBody); - case 'removeHeaders': return CamelDefinitionYamlStep.readRemoveHeadersDefinition(newBody); - case 'setExchangePattern': return CamelDefinitionYamlStep.readSetExchangePatternDefinition(newBody); - case 'intercept': return CamelDefinitionYamlStep.readInterceptDefinition(newBody); - case 'transform': return CamelDefinitionYamlStep.readTransformDefinition(newBody); - case 'routingSlip': return CamelDefinitionYamlStep.readRoutingSlipDefinition(newBody); - case 'doTry': return CamelDefinitionYamlStep.readTryDefinition(newBody); + case 'convertBodyTo': return CamelDefinitionYamlStep.readConvertBodyDefinition(newBody); case 'delay': return CamelDefinitionYamlStep.readDelayDefinition(newBody); - case 'script': return CamelDefinitionYamlStep.readScriptDefinition(newBody); + case 'dynamicRouter': return CamelDefinitionYamlStep.readDynamicRouterDefinition(newBody); case 'enrich': return CamelDefinitionYamlStep.readEnrichDefinition(newBody); - case 'onCompletion': return CamelDefinitionYamlStep.readOnCompletionDefinition(newBody); - case 'wireTap': return CamelDefinitionYamlStep.readWireTapDefinition(newBody); - case 'kamelet': return CamelDefinitionYamlStep.readKameletDefinition(newBody); - case 'interceptFrom': return CamelDefinitionYamlStep.readInterceptFromDefinition(newBody); + case 'filter': return CamelDefinitionYamlStep.readFilterDefinition(newBody); case 'doFinally': return CamelDefinitionYamlStep.readFinallyDefinition(newBody); case 'idempotentConsumer': return CamelDefinitionYamlStep.readIdempotentConsumerDefinition(newBody); - case 'removeHeader': return CamelDefinitionYamlStep.readRemoveHeaderDefinition(newBody); - case 'circuitBreaker': return CamelDefinitionYamlStep.readCircuitBreakerDefinition(newBody); - case 'rollback': return CamelDefinitionYamlStep.readRollbackDefinition(newBody); - case 'dynamicRouter': return CamelDefinitionYamlStep.readDynamicRouterDefinition(newBody); - case 'resequence': return CamelDefinitionYamlStep.readResequenceDefinition(newBody); + case 'kamelet': return CamelDefinitionYamlStep.readKameletDefinition(newBody); + case 'loadBalance': return CamelDefinitionYamlStep.readLoadBalanceDefinition(newBody); case 'log': return CamelDefinitionYamlStep.readLogDefinition(newBody); - case 'throttle': return CamelDefinitionYamlStep.readThrottleDefinition(newBody); - case 'recipientList': return CamelDefinitionYamlStep.readRecipientListDefinition(newBody); + case 'loop': return CamelDefinitionYamlStep.readLoopDefinition(newBody); case 'marshal': return CamelDefinitionYamlStep.readMarshalDefinition(newBody); - case 'policy': return CamelDefinitionYamlStep.readPolicyDefinition(newBody); - case 'serviceCall': return CamelDefinitionYamlStep.readServiceCallDefinition(newBody); - case 'unmarshal': return CamelDefinitionYamlStep.readUnmarshalDefinition(newBody); - case 'threads': return CamelDefinitionYamlStep.readThreadsDefinition(newBody); - case 'toD': return CamelDefinitionYamlStep.readToDynamicDefinition(newBody); - case 'convertBodyTo': return CamelDefinitionYamlStep.readConvertBodyDefinition(newBody); + case 'multicast': return CamelDefinitionYamlStep.readMulticastDefinition(newBody); + case 'onFallback': return CamelDefinitionYamlStep.readOnFallbackDefinition(newBody); + case 'otherwise': return CamelDefinitionYamlStep.readOtherwiseDefinition(newBody); + case 'pausable': return CamelDefinitionYamlStep.readPausableDefinition(newBody); case 'pipeline': return CamelDefinitionYamlStep.readPipelineDefinition(newBody); - case 'throwException': return CamelDefinitionYamlStep.readThrowExceptionDefinition(newBody); - case 'validate': return CamelDefinitionYamlStep.readValidateDefinition(newBody); - case 'interceptSendToEndpoint': return CamelDefinitionYamlStep.readInterceptSendToEndpointDefinition(newBody); - case 'choice': return CamelDefinitionYamlStep.readChoiceDefinition(newBody); - case 'whenSkipSendToEndpoint': return CamelDefinitionYamlStep.readWhenSkipSendToEndpointDefinition(newBody); + case 'policy': return CamelDefinitionYamlStep.readPolicyDefinition(newBody); + case 'pollEnrich': return CamelDefinitionYamlStep.readPollEnrichDefinition(newBody); + case 'process': return CamelDefinitionYamlStep.readProcessDefinition(newBody); + case 'recipientList': return CamelDefinitionYamlStep.readRecipientListDefinition(newBody); + case 'removeHeader': return CamelDefinitionYamlStep.readRemoveHeaderDefinition(newBody); + case 'removeHeaders': return CamelDefinitionYamlStep.readRemoveHeadersDefinition(newBody); + case 'removeProperties': return CamelDefinitionYamlStep.readRemovePropertiesDefinition(newBody); + case 'removeProperty': return CamelDefinitionYamlStep.readRemovePropertyDefinition(newBody); + case 'resequence': return CamelDefinitionYamlStep.readResequenceDefinition(newBody); + case 'resumable': return CamelDefinitionYamlStep.readResumableDefinition(newBody); + case 'rollback': return CamelDefinitionYamlStep.readRollbackDefinition(newBody); + case 'routingSlip': return CamelDefinitionYamlStep.readRoutingSlipDefinition(newBody); + case 'saga': return CamelDefinitionYamlStep.readSagaDefinition(newBody); case 'sample': return CamelDefinitionYamlStep.readSamplingDefinition(newBody); + case 'script': return CamelDefinitionYamlStep.readScriptDefinition(newBody); + case 'setBody': return CamelDefinitionYamlStep.readSetBodyDefinition(newBody); + case 'setExchangePattern': return CamelDefinitionYamlStep.readSetExchangePatternDefinition(newBody); case 'setHeader': return CamelDefinitionYamlStep.readSetHeaderDefinition(newBody); + case 'setProperty': return CamelDefinitionYamlStep.readSetPropertyDefinition(newBody); case 'sort': return CamelDefinitionYamlStep.readSortDefinition(newBody); + case 'split': return CamelDefinitionYamlStep.readSplitDefinition(newBody); + case 'step': return CamelDefinitionYamlStep.readStepDefinition(newBody); + case 'stop': return CamelDefinitionYamlStep.readStopDefinition(newBody); + case 'threads': return CamelDefinitionYamlStep.readThreadsDefinition(newBody); + case 'throttle': return CamelDefinitionYamlStep.readThrottleDefinition(newBody); + case 'throwException': return CamelDefinitionYamlStep.readThrowExceptionDefinition(newBody); + case 'to': return CamelDefinitionYamlStep.readToDefinition(newBody); case 'toD': return CamelDefinitionYamlStep.readToDynamicDefinition(newBody); + case 'transacted': return CamelDefinitionYamlStep.readTransactedDefinition(newBody); + case 'transform': return CamelDefinitionYamlStep.readTransformDefinition(newBody); + case 'doTry': return CamelDefinitionYamlStep.readTryDefinition(newBody); + case 'unmarshal': return CamelDefinitionYamlStep.readUnmarshalDefinition(newBody); + case 'validate': return CamelDefinitionYamlStep.readValidateDefinition(newBody); + case 'when': return CamelDefinitionYamlStep.readWhenDefinition(newBody); + case 'whenSkipSendToEndpoint': return CamelDefinitionYamlStep.readWhenSkipSendToEndpointDefinition(newBody); + case 'wireTap': return CamelDefinitionYamlStep.readWireTapDefinition(newBody); + case 'serviceCall': return CamelDefinitionYamlStep.readServiceCallDefinition(newBody); default: return new CamelElement(''); } } diff --git a/karavan-core/src/core/model/CamelDefinition.ts b/karavan-core/src/core/model/CamelDefinition.ts index 676dbab090f..63b0827b8de 100644 --- a/karavan-core/src/core/model/CamelDefinition.ts +++ b/karavan-core/src/core/model/CamelDefinition.ts @@ -1516,18 +1516,18 @@ export class ToDefinition extends CamelElement { } export class ToDynamicDefinition extends CamelElement { - stepName?: string = 'toDynamic'; + stepName?: string = 'toD'; + uri: string = ''; + pattern?: string; + cacheSize?: number; + ignoreInvalidEndpoint?: boolean; allowOptimisedComponents?: boolean; autoStartComponents?: boolean; - cacheSize?: number; - description?: string; disabled?: boolean; - id?: string = 'toDynamic-' + uuidv4().substring(0,4); - ignoreInvalidEndpoint?: boolean; + id?: string = 'toD-' + uuidv4().substring(0,4); + description?: string; inheritErrorHandler?: boolean; parameters?: any = {}; - pattern?: string; - uri: string = ''; public constructor(init?: Partial) { super('ToDynamicDefinition'); Object.assign(this, init); diff --git a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/AbstractGenerator.java b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/AbstractGenerator.java index a7fbbfa80de..80490dd0b3f 100644 --- a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/AbstractGenerator.java +++ b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/AbstractGenerator.java @@ -61,6 +61,8 @@ protected String getStepNameForClass (String className) { className = "convertBodyTo"; } else if (className.equals("FinallyDefinition")) { className = "doFinally"; + } else if (className.equals("ToDynamicDefinition")) { + className = "toD"; } else if (className.equals("SamplingDefinition")) { className = "sample"; } else if (className.endsWith("Definition")) { @@ -94,11 +96,60 @@ protected Map getExpressionStepNameForClass(){ String fullClassName = prop.getJsonObject("properties").getJsonObject(key).getString("$ref"); String className = classSimple(fullClassName); stepNames.put(className, key); - System.out.println(className + " : " + key); } return stepNames; } + private Map getJsonObjectProperties (JsonObject val) { + Map properties = new LinkedHashMap<>(); + val.getMap().keySet().forEach(s -> { + JsonObject value = val.getJsonObject(s); + if (!value.getMap().isEmpty()) { + properties.put(s, val.getJsonObject(s)); + } else if (s.equals("expression")){ + properties.put(s, JsonObject.of("$ref", "#/items/definitions/org.apache.camel.model.language.ExpressionDefinition")); + } + }); + return properties; + } + + protected Map getClassProperties (JsonObject obj) { + Map properties = new LinkedHashMap<>(); + + obj.getMap().keySet().forEach(key -> { + if (key.equals("oneOf")) { + JsonObject val = obj.getJsonArray("oneOf").getJsonObject(1).getJsonObject("properties"); + properties.putAll(getJsonObjectProperties(val)); + } else if (key.equals("properties")) { + JsonObject val = obj.getJsonObject("properties"); + properties.putAll(getJsonObjectProperties(val)); + } else if (key.equals("anyOf")) { + JsonArray vals = obj.getJsonArray("anyOf").getJsonObject(0).getJsonArray("oneOf"); + for (int i = 0; i < vals.size(); i++){ + JsonObject data = vals.getJsonObject(i); + if (!data.containsKey("not") && data.containsKey("type")) { + JsonObject val = data.getJsonObject("properties"); + properties.putAll(getJsonObjectProperties(val)); + } + } + } + }); + return properties; + } + + protected Comparator getComparator(String stepName) { + String json = getMetaModel(stepName); + if (json != null) { + JsonObject props = new JsonObject(json).getJsonObject("properties"); + List propsLowerCase = props.getMap().keySet().stream().map(String::toLowerCase).collect(Collectors.toList()); + return Comparator.comparing(e -> { + if (propsLowerCase.contains(e.toLowerCase())) return propsLowerCase.indexOf(e.toLowerCase()); + else return propsLowerCase.size() + 1; + }); + } + return Comparator.comparing(s -> 0); + } + // protected Map getStepNames(){ // // Prepare stepNames map // JsonObject definitions = getDefinitions(); @@ -118,8 +169,8 @@ protected Map getDslMetadata(){ // Prepare stepNames map Map stepNames = getProcessorStepNameMap(); - Map classProps = new HashMap<>(); - Map defsMap = new HashMap<>(); + Map classProps = new LinkedHashMap<>(); + Map defsMap = new LinkedHashMap<>(); defsMap.putAll(definitions.getJsonObject("org.apache.camel.model.ProcessorDefinition").getJsonObject("properties").getMap()); defsMap.putAll(new JsonObject(camelYamlDSL).getJsonObject("items").getJsonObject("properties").getMap()); @@ -284,26 +335,8 @@ protected List getClasses(JsonObject definitions, String filter) { return result; } - protected Map getProcessorStepName(JsonObject properties) { - Map result = new HashMap<>(); - properties.getMap().forEach((name, o) -> { - String ref = properties.getJsonObject(name).getString("$ref"); - ref = ref.equals("#/items/definitions/org.apache.camel.dsl.yaml.deserializers.RouteFromDefinitionDeserializer") - ? "#/items/definitions/org.apache.camel.model.FromDefinition" - : ref; - ref = ref.equals("#/items/definitions/org.apache.camel.dsl.yaml.deserializers.ErrorHandlerBuilderDeserializer") - ? "#/items/definitions/org.apache.camel.model.ErrorHandlerDefinition" - : ref; - String className = classSimple(ref); - result.put(className, className.equals("ToDynamicDefinition") ? "toD" : name); - }); - return result; - } - - - protected Map getProcessorStepNameMapForObject(String key, JsonObject jsonObject) { - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); jsonObject.fieldNames().forEach(k -> { Object object = jsonObject.getValue(k); @@ -323,7 +356,7 @@ protected Map getProcessorStepNameMapForObject(String key, JsonO } protected Map getProcessorStepNameMapForArray(JsonArray jsonArray) { - Map result = new HashMap<>(); + Map result = new LinkedHashMap<>(); jsonArray.forEach(object -> { if (object instanceof JsonObject) { @@ -339,8 +372,28 @@ protected Map getProcessorStepNameMap() { String camelYamlDSL = getCamelYamlDSL(); JsonObject definitions = new JsonObject(camelYamlDSL); - Map result = new HashMap<>(getProcessorStepNameMapForObject(null, definitions)); - result.put("ToDynamicDefinition", "toD"); + Map result = new LinkedHashMap<>(getProcessorStepNameMapForObject(null, definitions)); + return result; + } + + protected Map getProcessorDefinitionStepNameMap() { + Map result = new LinkedHashMap<>(); + String camelYamlDSL = getCamelYamlDSL(); + JsonObject definitions = new JsonObject(camelYamlDSL); + + JsonObject properties = definitions + .getJsonObject("items") + .getJsonObject("definitions") + .getJsonObject("org.apache.camel.model.ProcessorDefinition") + .getJsonObject("properties"); + + properties.getMap().forEach((key, o) -> { + String ref = ((Map)o).get("$ref").toString(); + System.out.println(ref); + System.out.println(key); + String className = classSimple(ref); + result.put(className, key); + }); return result; } diff --git a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionApiGenerator.java b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionApiGenerator.java index 8979d8d19fa..e440c396a7c 100644 --- a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionApiGenerator.java +++ b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionApiGenerator.java @@ -66,8 +66,9 @@ private void createCamelDefinitions() throws Exception { }); // generate createStep function - Map stepNames = getProcessorStepName(new JsonObject(camelYamlDSL).getJsonObject("items").getJsonObject("properties")); - stepNames.putAll(getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.ProcessorDefinition").getJsonObject("properties"))); + Map stepNames = getProcessorStepNameMap(); +// Map stepNames = getProcessorStepName(new JsonObject(camelYamlDSL).getJsonObject("items").getJsonObject("properties")); +// stepNames.putAll(getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.ProcessorDefinition").getJsonObject("properties"))); StringBuilder cs = new StringBuilder( " static createStep = (name: string, body: any, clone: boolean = false): CamelElement => {\n" + " const newBody = CamelUtil.camelizeBody(name, body, clone);\n" + @@ -85,8 +86,8 @@ private void createCamelDefinitions() throws Exception { camelModel.append(cs); // generate createExpression function - stepNames.clear(); - stepNames.putAll(getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.language.ExpressionDefinition").getJsonObject("properties"))); +// stepNames.clear(); +// stepNames.putAll(getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.language.ExpressionDefinition").getJsonObject("properties"))); StringBuilder ce = new StringBuilder( " static createExpression = (name: string, body: any): CamelElement => {\n" + " const newBody = CamelUtil.camelizeBody(name, body, false);\n" + @@ -94,7 +95,9 @@ private void createCamelDefinitions() throws Exception { " delete newBody.dslName;\n" + " switch (name) { \n" ); - stepNames.forEach((className, stepName) -> { + stepNames.entrySet().stream().filter(e-> e.getKey().endsWith("Expression")).forEach(e -> { + String className = e.getKey(); + String stepName = e.getValue(); String code = String.format(" case '%1$s': return CamelDefinitionApi.create%1$s(newBody);\n", className); ce.append(code); }); @@ -105,8 +108,8 @@ private void createCamelDefinitions() throws Exception { camelModel.append(ce); // generate createDataFormat function - stepNames.clear(); - stepNames.putAll(getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.dataformat.DataFormatsDefinition").getJsonObject("properties"))); +// stepNames.clear(); +// stepNames.putAll(getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.dataformat.DataFormatsDefinition").getJsonObject("properties"))); StringBuilder df = new StringBuilder( " static createDataFormat = (name: string, body: any): CamelElement => {\n" + " const newBody = CamelUtil.camelizeBody(name, body, false);\n" + @@ -114,7 +117,10 @@ private void createCamelDefinitions() throws Exception { " delete newBody.dslName;\n" + " switch (name) { \n" ); - stepNames.forEach((className, stepName) -> { + stepNames.entrySet().stream().filter(e-> e.getKey().endsWith("DataFormat")).forEach(e -> { + String className = e.getKey(); + String stepName = e.getValue(); +// stepNames.forEach((className, stepName) -> { String code = String.format(" case '%1$s': return CamelDefinitionApi.create%1$s(newBody);\n", className); df.append(code); }); @@ -132,44 +138,41 @@ private void createCamelDefinitions() throws Exception { private String generateModelApi(String classFullName, JsonObject obj) { String className = classSimple(classFullName); + String stepName = getStepNameForClass(className); - JsonObject properties = obj.containsKey("oneOf") - ? obj.getJsonArray("oneOf").getJsonObject(1).getJsonObject("properties") - : obj.getJsonObject("properties"); + Map properties = getClassProperties(obj); List attrs = new ArrayList<>(); AtomicBoolean hasId = new AtomicBoolean(false); - if (properties != null) { - properties.getMap().keySet().forEach(name -> { - JsonObject aValue = properties.getJsonObject(name); - if ("id".equals(name)) { - hasId.set(true); - } - if (isAttributeRefArray(aValue) && name.equals("steps") && ! className.equals("ChoiceDefinition") && ! className.equals("SwitchDefinition") && ! className.equals("KameletDefinition")) { - attrs.add(" def.steps = CamelDefinitionApi.createSteps(element?.steps);"); - } else if (isAttributeRefArray(aValue) && !name.equals("steps")) { - String code = String.format( - " def.%1$s = element && element?.%1$s ? element?.%1$s.map((x:any) => CamelDefinitionApi.create%2$s(x)) :[];" - , name, getAttributeArrayClass(aValue)); - attrs.add(code); - } else if (isAttributeRef(aValue) - && !getAttributeClass(aValue).equals("SagaActionUriDefinition") // SagaActionUriDefinition is exception - && !getAttributeClass(aValue).equals("ToDefinition") // exception for ToDefinition (in REST Methods) - && !getAttributeClass(aValue).equals("ToDynamicDefinition") // exception for ToDynamicDefinition (in REST Methods) - ) { - String attributeClass = getAttributeClass(aValue); - String template = attributeClass.equals("ExpressionDefinition") - ? " def.%1$s = CamelDefinitionApi.create%2$s(element.%1$s); \n" - : " if (element?.%1$s !== undefined) { \n" + - " def.%1$s = CamelDefinitionApi.create%2$s(element.%1$s); \n" + - " }"; - String code = String.format(template, name, getAttributeClass(aValue)); - attrs.add(code); - } else { - - } - }); - } + properties.keySet().stream().sorted(getComparator(stepName)).forEach(name -> { + JsonObject aValue = properties.get(name); + if ("id".equals(name)) { + hasId.set(true); + } + if (isAttributeRefArray(aValue) && name.equals("steps") && ! className.equals("ChoiceDefinition") && ! className.equals("SwitchDefinition") && ! className.equals("KameletDefinition")) { + attrs.add(" def.steps = CamelDefinitionApi.createSteps(element?.steps);"); + } else if (isAttributeRefArray(aValue) && !name.equals("steps")) { + String code = String.format( + " def.%1$s = element && element?.%1$s ? element?.%1$s.map((x:any) => CamelDefinitionApi.create%2$s(x)) :[];" + , name, getAttributeArrayClass(aValue)); + attrs.add(code); + } else if (isAttributeRef(aValue) + && !getAttributeClass(aValue).equals("SagaActionUriDefinition") // SagaActionUriDefinition is exception + && !getAttributeClass(aValue).equals("ToDefinition") // exception for ToDefinition (in REST Methods) + && !getAttributeClass(aValue).equals("ToDynamicDefinition") // exception for ToDynamicDefinition (in REST Methods) + ) { + String attributeClass = getAttributeClass(aValue); + String template = attributeClass.equals("ExpressionDefinition") + ? " def.%1$s = CamelDefinitionApi.create%2$s(element.%1$s); \n" + : " if (element?.%1$s !== undefined) { \n" + + " def.%1$s = CamelDefinitionApi.create%2$s(element.%1$s); \n" + + " }"; + String code = String.format(template, name, getAttributeClass(aValue)); + attrs.add(code); + } else { + + } + }); String stringToRequired = getStringToRequired(obj, className); String s2 = stringToRequired.isEmpty() ? "" : "\n" + stringToRequired; String s3 = attrs.size() > 0 ? "\n" + attrs.stream().collect(Collectors.joining("\n")) : ""; diff --git a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionGenerator.java b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionGenerator.java index c540caed7ac..c217b5f17ec 100644 --- a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionGenerator.java +++ b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionGenerator.java @@ -58,41 +58,11 @@ private void createCamelDefinitions() throws Exception { writeFileText(targetModel, camelModel.toString()); } - private Map getJsonObjectProperties (JsonObject val) { - Map properties = new LinkedHashMap<>(); - val.getMap().keySet().forEach(s -> { - JsonObject value = val.getJsonObject(s); - if (!value.getMap().isEmpty()) { - properties.put(s, val.getJsonObject(s)); - } else if (s.equals("expression")){ - properties.put(s, JsonObject.of("$ref", "#/items/definitions/org.apache.camel.model.language.ExpressionDefinition")); - } - }); - return properties; - } + private String generateModel(String classFullName, JsonObject obj, JsonObject definitions, Map dslMetadata) { String className = classSimple(classFullName); - Map properties = new LinkedHashMap<>(); - - obj.getMap().keySet().forEach(key -> { - if (key.equals("oneOf")) { - JsonObject val = obj.getJsonArray("oneOf").getJsonObject(1).getJsonObject("properties"); - properties.putAll(getJsonObjectProperties(val)); - } else if (key.equals("properties")) { - JsonObject val = obj.getJsonObject("properties"); - properties.putAll(getJsonObjectProperties(val)); - } else if (key.equals("anyOf")) { - JsonArray vals = obj.getJsonArray("anyOf").getJsonObject(0).getJsonArray("oneOf"); - for (int i = 0; i < vals.size(); i++){ - JsonObject data = vals.getJsonObject(i); - if (!data.containsKey("not") && data.containsKey("type")) { - JsonObject val = data.getJsonObject("properties"); - properties.putAll(getJsonObjectProperties(val)); - } - } - } - }); + Map properties = getClassProperties(obj); List required = obj.containsKey("required") ? obj.getJsonArray("required").getList() : List.of(); List attrs = new ArrayList<>(); @@ -124,19 +94,6 @@ private String generateModel(String classFullName, JsonObject obj, JsonObject de return String.format(readFileText(modelTemplate), className, s2); } - private Comparator getComparator(String stepName) { - String json = getMetaModel(stepName); - if (json != null) { - JsonObject props = new JsonObject(json).getJsonObject("properties"); - List propsLowerCase = props.getMap().keySet().stream().map(String::toLowerCase).collect(Collectors.toList()); - return Comparator.comparing(e -> { - if (propsLowerCase.contains(e.toLowerCase())) return propsLowerCase.indexOf(e.toLowerCase()); - else return propsLowerCase.size() + 1; - }); - } - return Comparator.comparing(s -> 0); - } - private String getAttributeType(String stepName, JsonObject attribute, boolean required, JsonObject definitions, String generatedValue) { if (attribute.containsKey("$ref")) { String classFullName = attribute.getString("$ref"); diff --git a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionYamlStepGenerator.java b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionYamlStepGenerator.java index f1c87d18e04..29b406066d6 100644 --- a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionYamlStepGenerator.java +++ b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/CamelDefinitionYamlStepGenerator.java @@ -67,7 +67,7 @@ private void createCamelDefinitions() throws Exception { camelModel.append(model).append(System.lineSeparator()); }); // generate readStep function - Map stepNames = getProcessorStepName(definitions.getJsonObject("org.apache.camel.model.ProcessorDefinition").getJsonObject("properties")); + Map stepNames = getProcessorDefinitionStepNameMap(); StringBuilder cs = new StringBuilder( " static readStep = (body: any, clone: boolean = false): CamelElement => {\n" + " const name = Object.getOwnPropertyNames(body)[0];\n" + @@ -75,10 +75,9 @@ private void createCamelDefinitions() throws Exception { " switch (name) { \n" ); stepNames.forEach((className, stepName) -> { - String code = String.format(" case '%1$s': return CamelDefinitionYamlStep.read%2$s(newBody);\n",stepName, className); + String code = String.format(" case '%1$s': return CamelDefinitionYamlStep.read%2$s(newBody);\n", stepName, className); cs.append(code); }); - cs.append(" case 'toD': return CamelDefinitionYamlStep.readToDynamicDefinition(newBody);\n"); //exception for ToDynamicDefinition cs.append( " default: return new CamelElement('');\n" + " }\n" + @@ -93,65 +92,62 @@ private void createCamelDefinitions() throws Exception { private String generateModelApi(String classFullName, JsonObject obj) { String className = classSimple(classFullName); + String stepName = getStepNameForClass(className); String s1 = getStringToRequired(obj, className); AtomicReference s3 = new AtomicReference<>(""); - JsonObject properties = obj.containsKey("oneOf") - ? obj.getJsonArray("oneOf").getJsonObject(1).getJsonObject("properties") - : obj.getJsonObject("properties"); + Map properties = getClassProperties(obj); Map attrs = new HashMap<>(); - if (properties != null) { - properties.getMap().keySet().forEach(aName -> { - if (aName.equals("uri")) { - s3.set("\n def = ComponentApi.parseElementUri(def);"); - } - JsonObject aValue = properties.getJsonObject(aName); - if (isAttributeRefArray(aValue) && aName.equals("steps") && ! className.equals("ChoiceDefinition") && ! className.equals("SwitchDefinition") && ! className.equals("KameletDefinition")) { - attrs.put(aName, " def.steps = CamelDefinitionYamlStep.readSteps(element?.steps);\n"); - } else if (isAttributeRefArray(aValue) && !aName.equals("steps")) { - String format = Arrays.asList("intercept", "interceptFrom", "interceptSendToEndpoint", "onCompletion", "onException").contains(aName) - ? " def.%1$s = element && element?.%1$s ? element?.%1$s.map((x:any) => CamelDefinitionYamlStep.read%2$s(x.%1$s)) :[]; \n" - : " def.%1$s = element && element?.%1$s ? element?.%1$s.map((x:any) => CamelDefinitionYamlStep.read%2$s(x)) :[]; \n"; - - String code = String.format(format, aName, getAttributeArrayClass(aValue)); - attrs.put(aName, code); - } else if (isAttributeRef(aValue) && getAttributeClass(aValue).equals("ExpressionDefinition")) { // Expressions implicits - String code = String.format( - " if (element?.%1$s !== undefined) { \n" + - " def.%1$s = CamelDefinitionYamlStep.read%2$s(element.%1$s); \n" + - " } else {\n" + - " const languageName: string | undefined = Object.keys(element).filter(key => CamelMetadataApi.hasLanguage(key))[0] || undefined;\n" + - " if (languageName){\n" + - " const exp:any = {};\n" + - " exp[languageName] = element[languageName]\n" + - " def.%1$s = CamelDefinitionYamlStep.readExpressionDefinition(exp);\n" + - " delete (def as any)[languageName];\n" + - " }\n" + - " }\n" - , aName, getAttributeClass(aValue)); - attrs.put(aName, code); - } else if (isAttributeRef(aValue) - && !getAttributeClass(aValue).equals("SagaActionUriDefinition") // SagaActionUriDefinition is exception - && !getAttributeClass(aValue).equals("ToDefinition") // exception for ToDefinition (in REST Methods) - && !getAttributeClass(aValue).equals("ToDynamicDefinition") // exception for ToDynamicDefinition (in REST Methods) - ) { - String code = String.format( - " if (element?.%1$s !== undefined) { \n" + - " if (Array.isArray(element.%1$s)) { \n" + - " def.%1$s = CamelDefinitionYamlStep.read%2$s(element.%1$s[0]); \n" + - " } else { \n" + - " def.%1$s = CamelDefinitionYamlStep.read%2$s(element.%1$s); \n" + - " } \n" + - " } \n" - , aName, getAttributeClass(aValue)); - attrs.put(aName, code); - } else { - - } - }); - } + properties.keySet().stream().sorted(getComparator(stepName)).forEach(aName -> { + if (aName.equals("uri")) { + s3.set("\n def = ComponentApi.parseElementUri(def);"); + } + JsonObject aValue = properties.get(aName); + if (isAttributeRefArray(aValue) && aName.equals("steps") && ! className.equals("ChoiceDefinition") && ! className.equals("SwitchDefinition") && ! className.equals("KameletDefinition")) { + attrs.put(aName, " def.steps = CamelDefinitionYamlStep.readSteps(element?.steps);\n"); + } else if (isAttributeRefArray(aValue) && !aName.equals("steps")) { + String format = Arrays.asList("intercept", "interceptFrom", "interceptSendToEndpoint", "onCompletion", "onException").contains(aName) + ? " def.%1$s = element && element?.%1$s ? element?.%1$s.map((x:any) => CamelDefinitionYamlStep.read%2$s(x.%1$s)) :[]; \n" + : " def.%1$s = element && element?.%1$s ? element?.%1$s.map((x:any) => CamelDefinitionYamlStep.read%2$s(x)) :[]; \n"; + + String code = String.format(format, aName, getAttributeArrayClass(aValue)); + attrs.put(aName, code); + } else if (isAttributeRef(aValue) && getAttributeClass(aValue).equals("ExpressionDefinition")) { // Expressions implicits + String code = String.format( + " if (element?.%1$s !== undefined) { \n" + + " def.%1$s = CamelDefinitionYamlStep.read%2$s(element.%1$s); \n" + + " } else {\n" + + " const languageName: string | undefined = Object.keys(element).filter(key => CamelMetadataApi.hasLanguage(key))[0] || undefined;\n" + + " if (languageName){\n" + + " const exp:any = {};\n" + + " exp[languageName] = element[languageName]\n" + + " def.%1$s = CamelDefinitionYamlStep.readExpressionDefinition(exp);\n" + + " delete (def as any)[languageName];\n" + + " }\n" + + " }\n" + , aName, getAttributeClass(aValue)); + attrs.put(aName, code); + } else if (isAttributeRef(aValue) + && !getAttributeClass(aValue).equals("SagaActionUriDefinition") // SagaActionUriDefinition is exception + && !getAttributeClass(aValue).equals("ToDefinition") // exception for ToDefinition (in REST Methods) + && !getAttributeClass(aValue).equals("ToDynamicDefinition") // exception for ToDynamicDefinition (in REST Methods) + ) { + String code = String.format( + " if (element?.%1$s !== undefined) { \n" + + " if (Array.isArray(element.%1$s)) { \n" + + " def.%1$s = CamelDefinitionYamlStep.read%2$s(element.%1$s[0]); \n" + + " } else { \n" + + " def.%1$s = CamelDefinitionYamlStep.read%2$s(element.%1$s); \n" + + " } \n" + + " } \n" + , aName, getAttributeClass(aValue)); + attrs.put(aName, code); + } else { + + } + }); return String.format(readFileText(modelTemplate), className, s1, s3, attrs.values().stream().collect(Collectors.joining(""))); } diff --git a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/KaravanGenerator.java b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/KaravanGenerator.java index 5e6360e4e2b..e48b32d8055 100644 --- a/karavan-generator/src/main/java/org/apache/camel/karavan/generator/KaravanGenerator.java +++ b/karavan-generator/src/main/java/org/apache/camel/karavan/generator/KaravanGenerator.java @@ -28,8 +28,8 @@ public static void main(String[] args) throws Exception { paths = new String[] {args[0]}; } CamelDefinitionGenerator.generate(); -// CamelDefinitionApiGenerator.generate(); -// CamelDefinitionYamlStepGenerator.generate(); + CamelDefinitionApiGenerator.generate(); + CamelDefinitionYamlStepGenerator.generate(); // CamelMetadataGenerator.generate(); KameletGenerator.generate(paths); CamelComponentsGenerator.generate(paths);