Skip to content

Commit

Permalink
Workaround for resolving beans catalog from plain Camel
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Sep 26, 2024
1 parent a8b1d6d commit 40318e1
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public CqCatalog(Path baseDir, Flavor flavor) {

public CqCatalog(Flavor flavor, Function<String, InputStream> 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;
Expand Down Expand Up @@ -173,7 +174,7 @@ public Stream<ArtifactModel<?>> models() {
}

public Stream<ArtifactModel<?>> 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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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");
}
}

}

0 comments on commit 40318e1

Please sign in to comment.