From 40318e124f41677ccf272f0786a3591ee9b49064 Mon Sep 17 00:00:00 2001 From: JiriOndrusek Date: Thu, 26 Sep 2024 15:49:43 +0200 Subject: [PATCH] Workaround for resolving beans catalog from plain Camel --- .../apache/camel/quarkus/maven/CqCatalog.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java index 878452e0433b..ff2cbf2f9c42 100644 --- a/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java +++ b/tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java @@ -120,7 +120,8 @@ public CqCatalog(Path baseDir, Flavor flavor) { public CqCatalog(Flavor flavor, Function resourceLocator) { this.flavor = flavor; - final DefaultCamelCatalog c = new DefaultCamelCatalog(true); + // workaround for catalog `beans/*.json`, see comment on BeansWorkaroundCustomCatalog for more information + final DefaultCamelCatalog c = new BeansWorkaroundCustomCatalog(true); c.setRuntimeProvider(flavor.createRuntimeProvider(c)); c.setVersionManager(new CqVersionManager(c, resourceLocator)); this.catalog = c; @@ -173,7 +174,7 @@ public Stream> models() { } public Stream> models(Kind kind) { - return catalog.findNames(kind).stream().map(name -> (ArtifactModel) catalog.model(kind, name)); + return catalog.findNames(kind).stream().map(name -> (ArtifactModel) catalog.model(kind, name)); } public void addComponent(String name, String className, String jsonSchema) { @@ -197,6 +198,8 @@ static void serialize(final Path catalogPath, ArtifactModel model) { switch (model.getKind()) { case bean: rawJson = JsonMapper.createParameterJsonSchema((PojoBeanModel) model); + //workaround + rawJson = rawJson.replace("model", "bean"); break; case component: rawJson = JsonMapper.createParameterJsonSchema((ComponentModel) model); @@ -339,6 +342,7 @@ static class CqRuntimeProvider implements RuntimeProvider { private static final String LANGUAGE_DIR = CQ_CATALOG_DIR + "/languages"; private static final String TRANSFORMER_DIR = CQ_CATALOG_DIR + "/transformers"; private static final String OTHER_DIR = CQ_CATALOG_DIR + "/others"; + //workaround for beans private static final String BEANS_DIR = CQ_CATALOG_DIR + "/beans"; private static final String COMPONENTS_CATALOG = CQ_CATALOG_DIR + "/components.properties"; private static final String DATA_FORMATS_CATALOG = CQ_CATALOG_DIR + "/dataformats.properties"; @@ -591,4 +595,20 @@ public void close() { } } + /** + * Prior https://github.com/apache/camel/pull/15708, the catalog files from `beans/*json` might have contained + * attribute `model` instead of `bean`. This custom catalog is fixing the json, to be parsable by Camel + * tooling. + */ + public static class BeansWorkaroundCustomCatalog extends DefaultCamelCatalog { + public BeansWorkaroundCustomCatalog(boolean caching) { + super(caching); + } + + @Override + public String pojoBeanJSonSchema(String name) { + return getJSonSchemaResolver().getPojoBeanJSonSchema(name).replace("model", "bean"); + } + } + }