From dc54036cabbe4f52ae5fcc9db617b6cef629ada3 Mon Sep 17 00:00:00 2001 From: "Ricardo M." Date: Mon, 2 Sep 2024 18:35:34 +0200 Subject: [PATCH] fix(catalog-generator): Add "parameters" property Currently, the `parameters` property is only added for `ToDynamicDefinition` EIP. This represents a problem for Camel 4.8.0 since there's a new `poll` EIP that requires it. --- .../generator/CamelCatalogProcessor.java | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java b/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java index 33d99fcf2..9e677a28d 100644 --- a/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java +++ b/packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/generator/CamelCatalogProcessor.java @@ -15,26 +15,20 @@ */ package io.kaoto.camelcatalog.generator; -import java.io.InputStream; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.kaoto.camelcatalog.model.CatalogRuntime; import org.apache.camel.catalog.CamelCatalog; import org.apache.camel.tooling.model.ComponentModel; import org.apache.camel.tooling.model.EipModel; import org.apache.camel.tooling.model.JsonMapper; import org.apache.camel.tooling.model.Kind; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import io.kaoto.camelcatalog.model.CatalogRuntime; +import java.io.InputStream; +import java.io.StringWriter; +import java.util.*; +import java.util.logging.Logger; /** * Customize Camel Catalog for Kaoto. @@ -42,17 +36,23 @@ public class CamelCatalogProcessor { private static final Logger LOGGER = Logger.getLogger(CamelCatalogProcessor.class.getName()); - private static final String TO_DYNAMIC_DEFINITION = "org.apache.camel.model.ToDynamicDefinition"; + private static final List PARAMETRIZED_PROCESSORS = List.of( + "org.apache.camel.model.KameletDefinition", + "org.apache.camel.model.PollDefinition", + "org.apache.camel.model.ToDynamicDefinition", + "org.apache.camel.model.ToDefinition", + "org.apache.camel.model.WireTapDefinition" + ); private static final String SET_HEADERS_DEFINITION = "org.apache.camel.model.SetHeadersDefinition"; private static final String SET_VARIABLES_DEFINITION = "org.apache.camel.model.SetVariablesDefinition"; private final ObjectMapper jsonMapper; private final CamelCatalog camelCatalog; private final CamelYamlDslSchemaProcessor schemaProcessor; private final CatalogRuntime runtime; - private boolean verbose; + private final boolean verbose; public CamelCatalogProcessor(CamelCatalog camelCatalog, ObjectMapper jsonMapper, - CamelYamlDslSchemaProcessor schemaProcessor, CatalogRuntime runtime, boolean verbose) { + CamelYamlDslSchemaProcessor schemaProcessor, CatalogRuntime runtime, boolean verbose) { this.jsonMapper = jsonMapper; this.camelCatalog = camelCatalog; this.schemaProcessor = schemaProcessor; @@ -115,7 +115,7 @@ public String getComponentCatalog() throws Exception { componentDefinition.put("version", componentVersion); if (componentVersion.contains("redhat")) { - componentDefinition.put("provider", "Red Hat"); + componentDefinition.put("provider", "Red Hat"); } answer.set(name, catalogNode); @@ -312,21 +312,19 @@ public String getPatternCatalog() throws Exception { for (var propertyName : camelYamlDslProperties) { var propertySchema = processorSchema.withObject("/properties").withObject("/" + propertyName); - if (TO_DYNAMIC_DEFINITION.equals(processorFQCN) && "parameters".equals(propertyName)) { + if ("parameters".equals(propertyName) && PARAMETRIZED_PROCESSORS.contains(processorFQCN)) { // "parameters" as a common property is omitted in the catalog, but we need this - // for "toD" + // f.i. "toD" and "poll" propertySchema.put("title", "Parameters"); propertySchema.put("description", "URI parameters"); sortedSchemaProperties.set(propertyName, propertySchema); continue; - } - if (SET_HEADERS_DEFINITION.equals((processorFQCN)) && "headers".equals(propertyName)) { + } else if (SET_HEADERS_DEFINITION.equals((processorFQCN)) && "headers".equals(propertyName)) { propertySchema.put("title", "Headers"); propertySchema.put("description", "Headers to set"); sortedSchemaProperties.set(propertyName, propertySchema); continue; - } - if (SET_VARIABLES_DEFINITION.equals((processorFQCN)) && "variables".equals(propertyName)) { + } else if (SET_VARIABLES_DEFINITION.equals((processorFQCN)) && "variables".equals(propertyName)) { propertySchema.put("title", "Variables"); propertySchema.put("description", "Variables to set"); sortedSchemaProperties.set(propertyName, propertySchema);