This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 9a1272892c84 CAMEL-25768: camel-jbang - camel run adds 
camel-openapi-java for the API description of a code-first REST DSL (#28100)
9a1272892c84 is described below

commit 9a1272892c8497b1d728d314fa85437d717e486d
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Oct 19 21:24:48 2026 +0200

    CAMEL-25768: camel-jbang - camel run adds camel-openapi-java for the API 
description of a code-first REST DSL (#28100)
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../DependencyDownloaderComponentResolver.java     |  7 +-
 .../DependencyDownloaderComponentResolverTest.java | 76 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
index c83de375c73b..9fd8e709ced8 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
@@ -89,12 +89,15 @@ public final class DependencyDownloaderComponentResolver 
extends DefaultComponen
                 downloadLoader(direct.getGroupId(), direct.getArtifactId(), 
direct.getVersion());
             }
         }
-        if ("rest-openapi".equals(name)) {
-            // include camel-openapi-java when using rest-dsl with openapi 
contract-first
+        if ("rest-openapi".equals(name) || "rest-api".equals(name)) {
+            // include camel-openapi-java when using rest-dsl with openapi 
contract-first, or the api description of a
+            // code-first rest-dsl (restConfiguration apiContextPath), which 
the rest-api component serves (CAMEL-25768)
             OtherModel oa = catalog.otherModel("openapi-java");
             if (oa != null) {
                 downloadLoader(oa.getGroupId(), oa.getArtifactId(), 
oa.getVersion());
             }
+        }
+        if ("rest-openapi".equals(name)) {
             // include the default producer component (camel-http, CAMEL-24849)
             ComponentModel http = catalog.componentModel("http");
             if (http != null) {
diff --git 
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
new file mode 100644
index 000000000000..3c418c39a81c
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.main.download;
+
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class DependencyDownloaderComponentResolverTest {
+
+    @Test
+    void theApiDescriptionOfACodeFirstRestDslDownloadsOpenApiJava() throws 
Exception {
+        // CAMEL-25768: the rest-api component serves the API description of a 
code-first REST DSL (apiContextPath),
+        // which needs camel-openapi-java, as the contract-first rest-openapi 
does
+        List<String> downloaded = resolve("rest-api");
+        assertTrue(downloaded.contains("camel-openapi-java"), 
downloaded.toString());
+        // the http producer is for the contract-first rest-openapi only
+        assertFalse(downloaded.contains("camel-http"), downloaded.toString());
+    }
+
+    @Test
+    void theContractFirstRestDslDownloadsOpenApiJavaAndHttp() throws Exception 
{
+        List<String> downloaded = resolve("rest-openapi");
+        assertTrue(downloaded.contains("camel-openapi-java"), 
downloaded.toString());
+        assertTrue(downloaded.contains("camel-http"), downloaded.toString());
+    }
+
+    /** The artifacts the resolver asks to download for the component, with 
nothing on the classpath. */
+    private static List<String> resolve(String component) throws Exception {
+        List<String> downloaded = new ArrayList<>();
+        DependencyDownloader downloader = (DependencyDownloader) 
Proxy.newProxyInstance(
+                
DependencyDownloaderComponentResolverTest.class.getClassLoader(),
+                new Class<?>[] { DependencyDownloader.class }, (proxy, method, 
args) -> switch (method.getName()) {
+                    case "downloadDependency" -> {
+                        downloaded.add((String) args[1]);
+                        yield null;
+                    }
+                    case "hashCode" -> System.identityHashCode(proxy);
+                    case "equals" -> proxy == args[0];
+                    case "toString" -> "RecordingDependencyDownloader";
+                    default -> method.getReturnType() == boolean.class ? 
Boolean.FALSE : null;
+                });
+        try (CamelContext context = new DefaultCamelContext()) {
+            context.addService(downloader);
+            DependencyDownloaderComponentResolver resolver
+                    = new DependencyDownloaderComponentResolver(context, null, 
false, false);
+            try {
+                resolver.resolveComponent(component, context);
+            } catch (Exception e) {
+                // the component itself need not be on the test classpath: the 
downloads are asked before
+            }
+        }
+        return downloaded;
+    }
+}

Reply via email to