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 5fb8a20ef62 CAMEL-22051: rest-dsl - Rest configuration context-path 
should be favoured as base-path instead of from spec file when using rest-dsl 
contract-first
5fb8a20ef62 is described below

commit 5fb8a20ef623616bafc355990f05a4e3472c0854
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Thu May 8 10:33:33 2025 +0200

    CAMEL-22051: rest-dsl - Rest configuration context-path should be favoured 
as base-path instead of from spec file when using rest-dsl contract-first
---
 .../component/rest/openapi/RestOpenApiEndpoint.java  | 15 +++++++++------
 .../ROOT/pages/camel-4x-upgrade-guide-4_12.adoc      | 20 ++++++++++++++++++++
 .../modules/ROOT/pages/rest-dsl-openapi.adoc         | 17 +++++++++++++++--
 3 files changed, 44 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java
index 71803c9aebd..1a63caa79a5 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java
@@ -296,6 +296,10 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
         if (factory != null) {
             RestConfiguration config = 
CamelContextHelper.getRestConfiguration(getCamelContext(), cname);
             Map<String, Object> copy = new HashMap<>(parameters); // defensive 
copy of the parameters
+            // avoid duplicate context-path
+            if (basePath.equals(config.getContextPath())) {
+                basePath = "";
+            }
             Consumer consumer = factory.createConsumer(getCamelContext(), 
processor, basePath, config, copy);
             if (consumer instanceof PlatformHttpConsumerAware phca) {
                 processor.setPlatformHttpConsumer(phca);
@@ -511,20 +515,19 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
             return componentBasePath;
         }
 
-        final String specificationBasePath = 
RestOpenApiHelper.getBasePathFromOpenApi(openapi);
-        if (isNotEmpty(specificationBasePath)) {
-            return specificationBasePath;
-        }
-
         final CamelContext camelContext = getCamelContext();
         final RestConfiguration restConfiguration
                 = CamelContextHelper.getRestConfiguration(camelContext, null, 
determineComponentName());
         final String restConfigurationBasePath = 
restConfiguration.getContextPath();
-
         if (isNotEmpty(restConfigurationBasePath)) {
             return restConfigurationBasePath;
         }
 
+        final String specificationBasePath = 
RestOpenApiHelper.getBasePathFromOpenApi(openapi);
+        if (isNotEmpty(specificationBasePath)) {
+            return specificationBasePath;
+        }
+
         return RestOpenApiComponent.DEFAULT_BASE_PATH;
     }
 
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
index 4e95f2f6194..1b833c534b6 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
@@ -97,6 +97,26 @@ to end the current choice (inner) and then afterwards change 
the scope to be Cho
 continue in the outer Choice. Otherwise the Java DSL cannot know the scope is 
Choice EIP and you would
 not be able to add the `otherwise` block to the outer Choice.
 
+==== Rest DSL
+
+When setting the context-path in _rest configuration_ then this now takes 
precedence over
+the base-path defined in an openapi specification when using _rest dsl 
contract-first_.
+
+For example
+
+[source,yaml]
+----
+- restConfiguration:
+    clientRequestValidation: true
+    contextPath: /cheese
+- rest:
+    openApi:
+      specification: petstore-v3.json
+----
+
+Then Camel will now use `/cheese` as the base-path for the Rest DSL API 
endpoints
+from the `petstore-v3.json` openapi specification file.
+
 === camel-as2
 
 Add options allowing the addition of an `Authorization` header for Basic or 
Bearer authentication to client and
diff --git a/docs/user-manual/modules/ROOT/pages/rest-dsl-openapi.adoc 
b/docs/user-manual/modules/ROOT/pages/rest-dsl-openapi.adoc
index 43baf0d18d6..3e536722b86 100644
--- a/docs/user-manual/modules/ROOT/pages/rest-dsl-openapi.adoc
+++ b/docs/user-manual/modules/ROOT/pages/rest-dsl-openapi.adoc
@@ -138,11 +138,24 @@ By default, Camel uses the base path that are specified 
in the OpenAPI contract
     }
 ----
 
-You can configure Camel to use a different base path by setting in 
`application.properties`:
+You can configure Camel to use a different base path (such as `cheese`) by 
either setting the base-path
+on the Rest OpenAPI component as follows, such as in `application.properties`:
 
 [source,properties]
 ----
-camel.component.rest-openapi.base-path = /myapi
+camel.component.rest-openapi.base-path = /cheese
+----
+
+Or configure this in the _rest configuration_ such as:
+
+[source,yaml]
+----
+- restConfiguration:
+    clientRequestValidation: true
+    contextPath: /cheese
+- rest:
+    openApi:
+      specification: petstore-v3.json
 ----
 
 === Ignoring missing API operations

Reply via email to