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

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

commit f3431fa2ddfe5f6cda855d998b44509a2056beab
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Apr 2 06:40:20 2024 +0200

    CAMEL-20557: Rest DSL to use openapi spec directly
---
 ...mHttpRestOpenApiConsumerRestDslBindingTest.java | 66 +++++++++++++++
 ...PlatformHttpRestOpenApiConsumerRestDslTest.java |  4 +
 .../platform/http/vertx/model/Category.java}       | 47 +++++-----
 .../component/platform/http/vertx/model/Pet.java   | 99 ++++++++++++++++++++++
 .../component/platform/http/vertx/model/Tag.java}  | 47 +++++-----
 .../DefaultRestOpenapiProcessorStrategy.java       | 21 ++++-
 ...sumerPath.java => RestOpenApiBindingAfter.java} | 35 ++------
 ...umerPath.java => RestOpenApiBindingBefore.java} | 35 ++------
 .../rest/openapi/RestOpenApiConsumerPath.java      | 16 +++-
 .../rest/openapi/RestOpenApiProcessor.java         | 21 ++++-
 .../rest/openapi/RestOpenapiProcessorStrategy.java | 24 ++++--
 .../openapi/validator/DefaultRequestValidator.java | 19 -----
 12 files changed, 288 insertions(+), 146 deletions(-)

diff --git 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslBindingTest.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslBindingTest.java
new file mode 100644
index 00000000000..45fd9cbac50
--- /dev/null
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslBindingTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.component.platform.http.vertx;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.platform.http.vertx.model.Pet;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+public class PlatformHttpRestOpenApiConsumerRestDslBindingTest {
+
+    @Test
+    public void testRestOpenApi() throws Exception {
+        final CamelContext context = 
VertxPlatformHttpEngineTest.createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    restConfiguration().bindingMode(RestBindingMode.json);
+
+                    
rest().openApi().specification("openapi-v3.json").missingOperation("ignore");
+
+                    from("direct:getPetById")
+                            .process(e -> {
+                                Pet pet = new Pet();
+                                pet.setId(e.getMessage().getHeader("petId", 
long.class));
+                                pet.setName("tony the tiger");
+                                pet.setStatus(Pet.Status.AVAILABLE);
+                            });
+                }
+            });
+
+            context.start();
+
+            given()
+                    .when()
+                    .get("/api/v3/pet/123")
+                    .then()
+                    .statusCode(200)
+                    .body(equalTo("{\"pet\": \"tony the tiger\"}"));
+
+        } finally {
+            context.stop();
+        }
+    }
+
+}
diff --git 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslTest.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslTest.java
index 0a64d1edb0c..b81eaff10d4 100644
--- 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslTest.java
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerRestDslTest.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
 import static io.restassured.RestAssured.given;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.equalToCompressingWhiteSpace;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.fail;
 
 public class PlatformHttpRestOpenApiConsumerRestDslTest {
@@ -42,6 +43,9 @@ public class PlatformHttpRestOpenApiConsumerRestDslTest {
                     
rest().openApi().specification("openapi-v3.json").missingOperation("ignore");
 
                     from("direct:getPetById")
+                            .process(e -> {
+                                assertEquals("123", 
e.getMessage().getHeader("petId"));
+                            })
                             .setBody().constant("{\"pet\": \"tony the 
tiger\"}");
                 }
             });
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/RestOpenApiPath.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Category.java
similarity index 50%
copy from 
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/RestOpenApiPath.java
copy to 
components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Category.java
index 14efcf67d8d..7fe7055c734 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/RestOpenApiPath.java
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Category.java
@@ -14,41 +14,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.rest.openapi.validator;
+package org.apache.camel.component.platform.http.vertx.model;
 
-import io.swagger.v3.oas.models.Operation;
-import org.apache.camel.support.RestConsumerContextPathMatcher;
+import jakarta.xml.bind.annotation.XmlRootElement;
 
-class RestOpenApiPath implements 
RestConsumerContextPathMatcher.ConsumerPath<Operation> {
+import com.fasterxml.jackson.annotation.JsonInclude;
 
-    private final String verb;
-    private final String path;
-    private final Operation consumer;
-
-    public RestOpenApiPath(String verb, String path, Operation consumer) {
-        this.verb = verb;
-        this.path = path;
-        this.consumer = consumer;
-    }
-
-    @Override
-    public String getRestrictMethod() {
-        return verb;
+/**
+ * The structure of this class must adhere to the schema defined in the Pet 
Store OpenAPI specification JSON / YAML.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@XmlRootElement(name = "Category")
+public class Category {
+    private Long id;
+    private String name;
+
+    public Long getId() {
+        return id;
     }
 
-    @Override
-    public String getConsumerPath() {
-        return path;
+    public void setId(Long id) {
+        this.id = id;
     }
 
-    @Override
-    public Operation getConsumer() {
-        return consumer;
+    public String getName() {
+        return name;
     }
 
-    @Override
-    public boolean isMatchOnUriPrefix() {
-        return false;
+    public void setName(String name) {
+        this.name = name;
     }
-
 }
diff --git 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Pet.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Pet.java
new file mode 100644
index 00000000000..7a1e27d887a
--- /dev/null
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Pet.java
@@ -0,0 +1,99 @@
+/*
+ * 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.component.platform.http.vertx.model;
+
+import java.util.List;
+
+import jakarta.xml.bind.annotation.XmlElement;
+import jakarta.xml.bind.annotation.XmlRootElement;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+/**
+ * The structure of this class must adhere to the schema defined in the Pet 
Store OpenAPI specification JSON / YAML.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@XmlRootElement(name = "Pet")
+public class Pet {
+    @XmlElement
+    private Long id;
+    private String name;
+    private Category category;
+    private List<String> photoUrls;
+    private List<Tag> tags;
+    private Status status;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Category getCategory() {
+        return category;
+    }
+
+    public void setCategory(Category category) {
+        this.category = category;
+    }
+
+    public List<Tag> getTags() {
+        return tags;
+    }
+
+    public void setTags(List<Tag> tags) {
+        this.tags = tags;
+    }
+
+    public List<String> getPhotoUrls() {
+        return photoUrls;
+    }
+
+    public void setPhotoUrls(List<String> photoUrls) {
+        this.photoUrls = photoUrls;
+    }
+
+    public Status getStatus() {
+        return status;
+    }
+
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+
+    public enum Status {
+        AVAILABLE,
+        PENDING,
+        SOLD;
+
+        @JsonCreator
+        public static Status fromString(String status) {
+            return Status.valueOf(status.toUpperCase());
+        }
+    }
+}
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/RestOpenApiPath.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Tag.java
similarity index 50%
rename from 
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/RestOpenApiPath.java
rename to 
components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Tag.java
index 14efcf67d8d..9571ab8e3c6 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/RestOpenApiPath.java
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/model/Tag.java
@@ -14,41 +14,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.rest.openapi.validator;
+package org.apache.camel.component.platform.http.vertx.model;
 
-import io.swagger.v3.oas.models.Operation;
-import org.apache.camel.support.RestConsumerContextPathMatcher;
+import jakarta.xml.bind.annotation.XmlRootElement;
 
-class RestOpenApiPath implements 
RestConsumerContextPathMatcher.ConsumerPath<Operation> {
+import com.fasterxml.jackson.annotation.JsonInclude;
 
-    private final String verb;
-    private final String path;
-    private final Operation consumer;
-
-    public RestOpenApiPath(String verb, String path, Operation consumer) {
-        this.verb = verb;
-        this.path = path;
-        this.consumer = consumer;
-    }
-
-    @Override
-    public String getRestrictMethod() {
-        return verb;
+/**
+ * The structure of this class must adhere to the schema defined in the Pet 
Store OpenAPI specification JSON / YAML.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@XmlRootElement(name = "Tag")
+public class Tag {
+    private Long id;
+    private String name;
+
+    public Long getId() {
+        return id;
     }
 
-    @Override
-    public String getConsumerPath() {
-        return path;
+    public void setId(Long id) {
+        this.id = id;
     }
 
-    @Override
-    public Operation getConsumer() {
-        return consumer;
+    public String getName() {
+        return name;
     }
 
-    @Override
-    public boolean isMatchOnUriPrefix() {
-        return false;
+    public void setName(String name) {
+        this.name = name;
     }
-
 }
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
index db3c0eff792..f1d47dbc6c8 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java
@@ -32,6 +32,7 @@ import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.NonManagedService;
+import org.apache.camel.Processor;
 import org.apache.camel.Route;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.platform.http.PlatformHttpComponent;
@@ -161,7 +162,10 @@ public class DefaultRestOpenapiProcessorStrategy extends 
ServiceSupport
     }
 
     @Override
-    public boolean process(Operation operation, String path, Exchange 
exchange, AsyncCallback callback) {
+    public boolean process(
+            Operation operation, String path,
+            Processor beforeBinding, Processor afterBinding,
+            Exchange exchange, AsyncCallback callback) {
         if ("mock".equalsIgnoreCase(missingOperation)) {
             // check if there is a route
             Endpoint e = camelContext.hasEndpoint(component + ":" + 
operation.getOperationId());
@@ -172,11 +176,26 @@ public class DefaultRestOpenapiProcessorStrategy extends 
ServiceSupport
             }
         }
 
+        if (beforeBinding != null) {
+            try {
+                beforeBinding.process(exchange);
+            } catch (Exception e) {
+                exchange.setException(e);
+                callback.done(true);
+                return true;
+            }
+        }
+
         Endpoint e = camelContext.getEndpoint(component + ":" + 
operation.getOperationId());
         AsyncProducer p = producerCache.acquireProducer(e);
         return p.process(exchange, doneSync -> {
             try {
                 producerCache.releaseProducer(e, p);
+                if (afterBinding != null) {
+                    afterBinding.process(exchange);
+                }
+            } catch (Exception ex) {
+                exchange.setException(ex);
             } finally {
                 callback.done(doneSync);
             }
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiBindingAfter.java
similarity index 52%
copy from 
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
copy to 
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiBindingAfter.java
index d94684eb9b2..6d11dd949f7 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiBindingAfter.java
@@ -16,38 +16,13 @@
  */
 package org.apache.camel.component.rest.openapi;
 
-import io.swagger.v3.oas.models.Operation;
-import org.apache.camel.support.RestConsumerContextPathMatcher;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 
-class RestOpenApiConsumerPath implements 
RestConsumerContextPathMatcher.ConsumerPath<Operation> {
-
-    private final String verb;
-    private final String path;
-    private final Operation consumer;
-
-    public RestOpenApiConsumerPath(String verb, String path, Operation 
consumer) {
-        this.verb = verb;
-        this.path = path;
-        this.consumer = consumer;
-    }
-
-    @Override
-    public String getRestrictMethod() {
-        return verb;
-    }
-
-    @Override
-    public String getConsumerPath() {
-        return path;
-    }
-
-    @Override
-    public Operation getConsumer() {
-        return consumer;
-    }
+public class RestOpenApiBindingAfter implements Processor {
 
     @Override
-    public boolean isMatchOnUriPrefix() {
-        return false;
+    public void process(Exchange exchange) throws Exception {
+        // TODO: binding after
     }
 }
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiBindingBefore.java
similarity index 52%
copy from 
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
copy to 
components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiBindingBefore.java
index d94684eb9b2..314fa085bf8 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiBindingBefore.java
@@ -16,38 +16,13 @@
  */
 package org.apache.camel.component.rest.openapi;
 
-import io.swagger.v3.oas.models.Operation;
-import org.apache.camel.support.RestConsumerContextPathMatcher;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 
-class RestOpenApiConsumerPath implements 
RestConsumerContextPathMatcher.ConsumerPath<Operation> {
-
-    private final String verb;
-    private final String path;
-    private final Operation consumer;
-
-    public RestOpenApiConsumerPath(String verb, String path, Operation 
consumer) {
-        this.verb = verb;
-        this.path = path;
-        this.consumer = consumer;
-    }
-
-    @Override
-    public String getRestrictMethod() {
-        return verb;
-    }
-
-    @Override
-    public String getConsumerPath() {
-        return path;
-    }
-
-    @Override
-    public Operation getConsumer() {
-        return consumer;
-    }
+public class RestOpenApiBindingBefore implements Processor {
 
     @Override
-    public boolean isMatchOnUriPrefix() {
-        return false;
+    public void process(Exchange exchange) throws Exception {
+        // TODO: binding before
     }
 }
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
index d94684eb9b2..f4123ec2f18 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiConsumerPath.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.rest.openapi;
 
 import io.swagger.v3.oas.models.Operation;
+import org.apache.camel.Processor;
 import org.apache.camel.support.RestConsumerContextPathMatcher;
 
 class RestOpenApiConsumerPath implements 
RestConsumerContextPathMatcher.ConsumerPath<Operation> {
@@ -24,11 +25,16 @@ class RestOpenApiConsumerPath implements 
RestConsumerContextPathMatcher.Consumer
     private final String verb;
     private final String path;
     private final Operation consumer;
+    private final Processor bindingBefore;
+    private final Processor bindingAfter;
 
-    public RestOpenApiConsumerPath(String verb, String path, Operation 
consumer) {
+    public RestOpenApiConsumerPath(String verb, String path, Operation 
consumer,
+                                   Processor bindingBefore, Processor 
bindingAfter) {
         this.verb = verb;
         this.path = path;
         this.consumer = consumer;
+        this.bindingBefore = bindingBefore;
+        this.bindingAfter = bindingAfter;
     }
 
     @Override
@@ -50,4 +56,12 @@ class RestOpenApiConsumerPath implements 
RestConsumerContextPathMatcher.Consumer
     public boolean isMatchOnUriPrefix() {
         return false;
     }
+
+    public Processor getBindingBefore() {
+        return bindingBefore;
+    }
+
+    public Processor getBindingAfter() {
+        return bindingAfter;
+    }
 }
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
index 4e379e3a292..a79a1d66f89 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java
@@ -33,6 +33,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.http.base.HttpHelper;
 import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.DataTypeAware;
 import org.apache.camel.spi.RestConfiguration;
@@ -95,17 +96,31 @@ public class RestOpenApiProcessor extends 
DelegateAsyncProcessor implements Came
                 = RestConsumerContextPathMatcher.matchBestPath(verb, path, 
paths);
         if (m != null) {
             Operation o = m.getConsumer();
+
+            // before and after processors for binding
+            Processor before = null;
+            Processor after = null;
+            if (m instanceof RestOpenApiConsumerPath mp) {
+                before = mp.getBindingBefore();
+                after = mp.getBindingAfter();
+            }
+
             // binding mode
             RestConfiguration config = camelContext.getRestConfiguration();
             RestConfiguration.RestBindingMode bindingMode = 
config.getBindingMode();
+
+            // map path-parameters from operation to camel headers
+            HttpHelper.evalPlaceholders(exchange.getMessage().getHeaders(), 
path, m.getConsumerPath());
+
             // we have found the op to call, but if validation is enabled then 
we need
             // to validate the incoming request first
             if (endpoint.isClientRequestValidation() && 
isInvalidClientRequest(exchange, callback, o, bindingMode)) {
                 // okay some validation error so return true
                 return true;
             }
+
             // process the incoming request
-            return restOpenapiProcessorStrategy.process(o, path, exchange, 
callback);
+            return restOpenapiProcessorStrategy.process(o, path, before, 
after, exchange, callback);
         }
 
         // is it the api-context path
@@ -315,7 +330,9 @@ public class RestOpenApiProcessor extends 
DelegateAsyncProcessor implements Came
             String path = e.getKey(); // path
             for (var o : e.getValue().readOperationsMap().entrySet()) {
                 String v = o.getKey().name(); // verb
-                paths.add(new RestOpenApiConsumerPath(v, path, o.getValue()));
+                RestOpenApiBindingBefore before = new 
RestOpenApiBindingBefore();
+                RestOpenApiBindingAfter after = new RestOpenApiBindingAfter();
+                paths.add(new RestOpenApiConsumerPath(v, path, o.getValue(), 
before, after));
             }
         }
         ServiceHelper.buildService(restOpenapiProcessorStrategy);
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategy.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategy.java
index 5dab95b0a6f..8b4c516d310 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategy.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenapiProcessorStrategy.java
@@ -20,6 +20,7 @@ import io.swagger.v3.oas.models.OpenAPI;
 import io.swagger.v3.oas.models.Operation;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 
 /**
  * Strategy for processing the Rest DSL that services an OpenAPI spec.
@@ -63,16 +64,21 @@ public interface RestOpenapiProcessorStrategy {
     /**
      * Strategy for processing the Rest DSL operation
      *
-     * @param  operation the rest operation
-     * @param  path      the context-path
-     * @param  exchange  the exchange
-     * @param  callback  the AsyncCallback will be invoked when the processing 
of the exchange is completed. If the
-     *                   exchange is completed synchronously, then the 
callback is also invoked synchronously. The
-     *                   callback should therefore be careful of starting 
recursive loop.
-     * @return           (doneSync) true to continue execute synchronously, 
false to continue being executed
-     *                   asynchronously
+     * @param  operation     the rest operation
+     * @param  path          the context-path
+     * @param  bindingBefore optional binding to execute before processing the 
Rest DSL operation
+     * @param  bindingAfter  optional binding to execute after processing the 
Rest DSL operation
+     * @param  exchange      the exchange
+     * @param  callback      the AsyncCallback will be invoked when the 
processing of the exchange is completed. If the
+     *                       exchange is completed synchronously, then the 
callback is also invoked synchronously. The
+     *                       callback should therefore be careful of starting 
recursive loop.
+     * @return               (doneSync) true to continue execute 
synchronously, false to continue being executed
+     *                       asynchronously
      */
-    boolean process(Operation operation, String path, Exchange exchange, 
AsyncCallback callback);
+    boolean process(
+            Operation operation, String path,
+            Processor bindingBefore, Processor bindingAfter,
+            Exchange exchange, AsyncCallback callback);
 
     /**
      * Strategy for processing the OpenAPI specification (to return the 
contract)
diff --git 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/DefaultRequestValidator.java
 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/DefaultRequestValidator.java
index 32ac3f42d73..7a3474db655 100644
--- 
a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/DefaultRequestValidator.java
+++ 
b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/validator/DefaultRequestValidator.java
@@ -20,8 +20,6 @@ import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 import com.fasterxml.jackson.databind.json.JsonMapper;
@@ -30,14 +28,11 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.support.MessageHelper;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.UnsafeUriCharactersEncoder;
 
 import static 
org.apache.camel.support.http.RestUtil.isValidOrAcceptedContentType;
 
 public class DefaultRequestValidator implements RequestValidator {
 
-    private static final Pattern REST_PATH_PARAM_PATTERN = 
Pattern.compile("\\{([^}]+)}");
-
     private RestOpenApiOperation operation;
 
     @Override
@@ -126,18 +121,4 @@ public class DefaultRequestValidator implements 
RequestValidator {
         return Collections.unmodifiableSet(validationErrors);
     }
 
-    protected String resolvePathParams(Exchange exchange, RestOpenApiOperation 
o) {
-        String path = o.getUriTemplate();
-        Matcher matcher = REST_PATH_PARAM_PATTERN.matcher(path);
-        String pathToProcess = path;
-        while (matcher.find()) {
-            String paramName = matcher.group(1);
-            String paramValue = exchange.getMessage().getHeader(paramName, 
String.class);
-            if (ObjectHelper.isNotEmpty(paramValue)) {
-                pathToProcess = pathToProcess.replace("{" + paramName + "}", 
UnsafeUriCharactersEncoder.encode(paramValue));
-            }
-        }
-        return pathToProcess;
-    }
-
 }

Reply via email to