You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/03/28 14:40:35 UTC

(camel) 21/38: CAMEL-20557: Rest DSL to use openapi spec directly

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

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

commit f7d730b5d54d54e129069ea1c345f133c74f71c8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 25 16:58:34 2024 +0100

    CAMEL-20557: Rest DSL to use openapi spec directly
---
 .../vertx/PlatformHttpRestOpenApiConsumerTest.java | 32 ++++++++++
 .../src/test/resources/camel-mock/pet/444.json     |  3 +
 .../openapi/RestOpenApiComponentConfigurer.java    |  6 ++
 .../openapi/RestOpenApiEndpointConfigurer.java     |  6 ++
 .../openapi/RestOpenApiEndpointUriFactory.java     |  3 +-
 .../camel/component/rest/openapi/rest-openapi.json | 38 +++++------
 .../DefaultRestOpenapiProcessorStrategy.java       | 74 ++++++++++++++++++++--
 .../rest/openapi/RestOpenApiComponent.java         | 17 ++++-
 .../rest/openapi/RestOpenApiEndpoint.java          | 12 ++++
 .../rest/openapi/RestOpenApiProcessor.java         |  1 +
 .../rest/openapi/RestOpenapiProcessorStrategy.java | 12 ++++
 11 files changed, 179 insertions(+), 25 deletions(-)

diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerTest.java
index 57acb01609d..e67426764f1 100644
--- a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerTest.java
+++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/PlatformHttpRestOpenApiConsumerTest.java
@@ -23,6 +23,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.fail;
 
 public class PlatformHttpRestOpenApiConsumerTest {
@@ -235,4 +236,35 @@ public class PlatformHttpRestOpenApiConsumerTest {
         }
     }
 
+    @Test
+    public void testRestOpenApiMockData() throws Exception {
+        final CamelContext context = VertxPlatformHttpEngineTest.createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    from("rest-openapi:classpath:openapi-v3.json?missingOperation=mock")
+                            .log("dummy");
+                }
+            });
+
+            context.start();
+
+            given()
+                    .when()
+                    .contentType("application/json")
+                    .get("/api/v3/pet/444")
+                    .then()
+                    .statusCode(200)
+                    .body(equalToCompressingWhiteSpace(
+                            """
+                                    {
+                                      "pet": "donald the dock"
+                                    }"""));
+        } finally {
+            context.stop();
+        }
+    }
+
 }
diff --git a/components/camel-platform-http-vertx/src/test/resources/camel-mock/pet/444.json b/components/camel-platform-http-vertx/src/test/resources/camel-mock/pet/444.json
new file mode 100644
index 00000000000..9c7739d6022
--- /dev/null
+++ b/components/camel-platform-http-vertx/src/test/resources/camel-mock/pet/444.json
@@ -0,0 +1,3 @@
+{
+  "pet": "donald the dock"
+}
\ No newline at end of file
diff --git a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java
index ae6772faf9a..ee6d62376fb 100644
--- a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java
+++ b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java
@@ -37,6 +37,8 @@ public class RestOpenApiComponentConfigurer extends PropertyConfigurerSupport im
         case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
         case "missingoperation":
         case "missingOperation": target.setMissingOperation(property(camelContext, java.lang.String.class, value)); return true;
+        case "mockincludepattern":
+        case "mockIncludePattern": target.setMockIncludePattern(property(camelContext, java.lang.String.class, value)); return true;
         case "produces": target.setProduces(property(camelContext, java.lang.String.class, value)); return true;
         case "requestvalidationcustomizer":
         case "requestValidationCustomizer": target.setRequestValidationCustomizer(property(camelContext, org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer.class, value)); return true;
@@ -73,6 +75,8 @@ public class RestOpenApiComponentConfigurer extends PropertyConfigurerSupport im
         case "lazyStartProducer": return boolean.class;
         case "missingoperation":
         case "missingOperation": return java.lang.String.class;
+        case "mockincludepattern":
+        case "mockIncludePattern": return java.lang.String.class;
         case "produces": return java.lang.String.class;
         case "requestvalidationcustomizer":
         case "requestValidationCustomizer": return org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer.class;
@@ -110,6 +114,8 @@ public class RestOpenApiComponentConfigurer extends PropertyConfigurerSupport im
         case "lazyStartProducer": return target.isLazyStartProducer();
         case "missingoperation":
         case "missingOperation": return target.getMissingOperation();
+        case "mockincludepattern":
+        case "mockIncludePattern": return target.getMockIncludePattern();
         case "produces": return target.getProduces();
         case "requestvalidationcustomizer":
         case "requestValidationCustomizer": return target.getRequestValidationCustomizer();
diff --git a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointConfigurer.java b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointConfigurer.java
index 6766a773f15..93eeebc6306 100644
--- a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointConfigurer.java
+++ b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointConfigurer.java
@@ -39,6 +39,8 @@ public class RestOpenApiEndpointConfigurer extends PropertyConfigurerSupport imp
         case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
         case "missingoperation":
         case "missingOperation": target.setMissingOperation(property(camelContext, java.lang.String.class, value)); return true;
+        case "mockincludepattern":
+        case "mockIncludePattern": target.setMockIncludePattern(property(camelContext, java.lang.String.class, value)); return true;
         case "produces": target.setProduces(property(camelContext, java.lang.String.class, value)); return true;
         case "requestvalidationcustomizer":
         case "requestValidationCustomizer": target.setRequestValidationCustomizer(property(camelContext, org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer.class, value)); return true;
@@ -73,6 +75,8 @@ public class RestOpenApiEndpointConfigurer extends PropertyConfigurerSupport imp
         case "lazyStartProducer": return boolean.class;
         case "missingoperation":
         case "missingOperation": return java.lang.String.class;
+        case "mockincludepattern":
+        case "mockIncludePattern": return java.lang.String.class;
         case "produces": return java.lang.String.class;
         case "requestvalidationcustomizer":
         case "requestValidationCustomizer": return org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer.class;
@@ -108,6 +112,8 @@ public class RestOpenApiEndpointConfigurer extends PropertyConfigurerSupport imp
         case "lazyStartProducer": return target.isLazyStartProducer();
         case "missingoperation":
         case "missingOperation": return target.getMissingOperation();
+        case "mockincludepattern":
+        case "mockIncludePattern": return target.getMockIncludePattern();
         case "produces": return target.getProduces();
         case "requestvalidationcustomizer":
         case "requestValidationCustomizer": return target.getRequestValidationCustomizer();
diff --git a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriFactory.java b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriFactory.java
index f841c7ad9af..1f4cda596a6 100644
--- a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriFactory.java
+++ b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriFactory.java
@@ -21,7 +21,7 @@ public class RestOpenApiEndpointUriFactory extends org.apache.camel.support.comp
     private static final Set<String> SECRET_PROPERTY_NAMES;
     private static final Set<String> MULTI_VALUE_PREFIXES;
     static {
-        Set<String> props = new HashSet<>(17);
+        Set<String> props = new HashSet<>(18);
         props.add("basePath");
         props.add("bridgeErrorHandler");
         props.add("componentName");
@@ -32,6 +32,7 @@ public class RestOpenApiEndpointUriFactory extends org.apache.camel.support.comp
         props.add("host");
         props.add("lazyStartProducer");
         props.add("missingOperation");
+        props.add("mockIncludePattern");
         props.add("operationId");
         props.add("produces");
         props.add("requestValidationCustomizer");
diff --git a/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json b/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json
index e4b0b0ac3fb..aefaf840aac 100644
--- a/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json
+++ b/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json
@@ -30,15 +30,16 @@
     "bridgeErrorHandler": { "index": 4, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the like [...]
     "missingOperation": { "index": 5, "kind": "property", "displayName": "Missing Operation", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "fail", "ignore", "mock" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "fail", "description": "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route." },
     "consumerComponentName": { "index": 6, "kind": "property", "displayName": "Consumer Component Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will service the requests. The component must be present in Camel registry and it must implement RestOpenApiConsumerFactory service provider interfac [...]
-    "restOpenapiProcessorStrategy": { "index": 7, "kind": "property", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" },
-    "host": { "index": 8, "kind": "property", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a nam [...]
-    "lazyStartProducer": { "index": 9, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
-    "componentName": { "index": 10, "kind": "property", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPATH [...]
-    "consumes": { "index": 11, "kind": "property", "displayName": "Consumes", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the va [...]
-    "produces": { "index": 12, "kind": "property", "displayName": "Produces", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi s [...]
-    "autowiredEnabled": { "index": 13, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching  [...]
-    "sslContextParameters": { "index": 14, "kind": "property", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "description": "Customize TLS parameters used by the component. If not set defaults to the TLS parameters set in the Camel context" },
-    "useGlobalSslContextParameters": { "index": 15, "kind": "property", "displayName": "Use Global Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable usage of global SSL context parameters." }
+    "mockIncludePattern": { "index": 7, "kind": "property", "displayName": "Mock Include Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "classpath:camel-mock\/*", "description": "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple patterns can be specified separ [...]
+    "restOpenapiProcessorStrategy": { "index": 8, "kind": "property", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" },
+    "host": { "index": 9, "kind": "property", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a nam [...]
+    "lazyStartProducer": { "index": 10, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fai [...]
+    "componentName": { "index": 11, "kind": "property", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPATH [...]
+    "consumes": { "index": 12, "kind": "property", "displayName": "Consumes", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the va [...]
+    "produces": { "index": 13, "kind": "property", "displayName": "Produces", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi s [...]
+    "autowiredEnabled": { "index": 14, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching  [...]
+    "sslContextParameters": { "index": 15, "kind": "property", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "description": "Customize TLS parameters used by the component. If not set defaults to the TLS parameters set in the Camel context" },
+    "useGlobalSslContextParameters": { "index": 16, "kind": "property", "displayName": "Use Global Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable usage of global SSL context parameters." }
   },
   "properties": {
     "specificationUri": { "index": 0, "kind": "path", "displayName": "Specification Uri", "group": "common", "label": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "openapi.json", "description": "Path to the OpenApi specification file. The scheme, host base path are taken from this specification, but these can be overridden with properties on the component or endpoint level. If not  [...]
@@ -49,14 +50,15 @@
     "consumerComponentName": { "index": 5, "kind": "parameter", "displayName": "Consumer Component Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will service the requests. The component must be present in Camel registry and it must implement RestOpenApiConsumerFactory service provider interfa [...]
     "exceptionHandler": { "index": 6, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...]
     "exchangePattern": { "index": 7, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." },
-    "restOpenapiProcessorStrategy": { "index": 8, "kind": "parameter", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" },
-    "basePath": { "index": 9, "kind": "parameter", "displayName": "Base Path", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "API basePath, for example \/v3. Default is unset, if set overrides the value present in OpenApi specification and in the component configuration." },
-    "consumes": { "index": 10, "kind": "parameter", "displayName": "Consumes", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the value of Accept HTTP  [...]
-    "host": { "index": 11, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a n [...]
-    "produces": { "index": 12, "kind": "parameter", "displayName": "Produces", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi specification. Overr [...]
-    "componentName": { "index": 13, "kind": "parameter", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPAT [...]
-    "lazyStartProducer": { "index": 14, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...]
-    "requestValidationCustomizer": { "index": 15, "kind": "parameter", "displayName": "Request Validation Customizer", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer", "deprecated": false, "autowired": false, "secret": false, "description": "If request validation is enabled, this option provides the capability to customize the creation of OpenApiInteractionValidator  [...]
-    "requestValidationLevels": { "index": 16, "kind": "parameter", "displayName": "Request Validation Levels", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "prefix": "validation.", "multiValue": true, "deprecated": false, "autowired": false, "secret": false, "description": "Levels for specific OpenAPI request validation options. Multiple options can be specified as URI options prefixed by ' [...]
+    "mockIncludePattern": { "index": 8, "kind": "parameter", "displayName": "Mock Include Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "classpath:camel-mock\/*", "description": "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple patterns can be specified sepa [...]
+    "restOpenapiProcessorStrategy": { "index": 9, "kind": "parameter", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" },
+    "basePath": { "index": 10, "kind": "parameter", "displayName": "Base Path", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "API basePath, for example \/v3. Default is unset, if set overrides the value present in OpenApi specification and in the component configuration." },
+    "consumes": { "index": 11, "kind": "parameter", "displayName": "Consumes", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the value of Accept HTTP  [...]
+    "host": { "index": 12, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a n [...]
+    "produces": { "index": 13, "kind": "parameter", "displayName": "Produces", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi specification. Overr [...]
+    "componentName": { "index": 14, "kind": "parameter", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPAT [...]
+    "lazyStartProducer": { "index": 15, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a produ [...]
+    "requestValidationCustomizer": { "index": 16, "kind": "parameter", "displayName": "Request Validation Customizer", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer", "deprecated": false, "autowired": false, "secret": false, "description": "If request validation is enabled, this option provides the capability to customize the creation of OpenApiInteractionValidator  [...]
+    "requestValidationLevels": { "index": 17, "kind": "parameter", "displayName": "Request Validation Levels", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "prefix": "validation.", "multiValue": true, "deprecated": false, "autowired": false, "secret": false, "description": "Levels for specific OpenAPI request validation options. Multiple options can be specified as URI options prefixed by ' [...]
   }
 }
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 40709fb260a..bd873724294 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
@@ -17,6 +17,7 @@
 package org.apache.camel.component.rest.openapi;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -30,10 +31,17 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.NonManagedService;
 import org.apache.camel.Route;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.PackageScanResourceResolver;
 import org.apache.camel.spi.ProducerCache;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.support.ExchangeHelper;
+import org.apache.camel.support.PluginHelper;
 import org.apache.camel.support.cache.DefaultProducerCache;
 import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,6 +57,7 @@ public class DefaultRestOpenapiProcessorStrategy extends ServiceSupport
     private ProducerCache producerCache;
     private String component = "direct";
     private String missingOperation;
+    private String mockIncludePattern;
 
     @Override
     public void validateOpenApi(OpenAPI openAPI) throws Exception {
@@ -94,10 +103,7 @@ public class DefaultRestOpenapiProcessorStrategy extends ServiceSupport
             // check if there is a route
             Endpoint e = camelContext.hasEndpoint(component + ":" + operation.getOperationId());
             if (e == null) {
-                // no route for the given operation, so lets return an empty response
-                exchange.getMessage().setBody("");
-                // TODO: load canned response from classpath if exist
-                exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 204);
+                loadMockData(operation, path, exchange);
                 callback.done(true);
                 return true;
             }
@@ -114,6 +120,56 @@ public class DefaultRestOpenapiProcessorStrategy extends ServiceSupport
         });
     }
 
+    private void loadMockData(Operation operation, String path, Exchange exchange) {
+        final PackageScanResourceResolver resolver = PluginHelper.getPackageScanResourceResolver(camelContext);
+        final String[] includes = mockIncludePattern != null ? mockIncludePattern.split(",") : null;
+
+        Collection<Resource> accepted = new ArrayList<>();
+        for (String include : includes) {
+            try {
+                for (Resource resource : resolver.findResources(include)) {
+                    accepted.add(resource);
+                }
+            } catch (Exception e) {
+                throw RuntimeCamelException.wrapRuntimeException(e);
+            }
+        }
+
+        boolean json = false;
+        boolean xml = false;
+        String ct = ExchangeHelper.getContentType(exchange);
+        if (ct != null) {
+            json = ct.contains("json");
+            xml = ct.contains("xml");
+        }
+
+        Resource found = null;
+        for (Resource resource : accepted) {
+            String target = FileUtil.stripFirstLeadingSeparator(path);
+            String loc = FileUtil.stripExt(FileUtil.compactPath(resource.getLocation(), '/'));
+            String onlyExt = FileUtil.onlyExt(resource.getLocation());
+            boolean match = loc.endsWith(target);
+            boolean matchExt = !json && !xml || json && onlyExt.equals("json") || xml && onlyExt.equals("xml");
+            if (match && matchExt) {
+                found = resource;
+                break;
+            }
+        }
+        if (found != null) {
+            try {
+                // use the mock data as response
+                exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
+                exchange.getMessage().setBody(IOHelper.loadText(found.getInputStream()));
+            } catch (Exception e) {
+                // ignore
+            }
+        } else {
+            // no mock data, so return an empty response
+            exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 204);
+            exchange.getMessage().setBody("");
+        }
+    }
+
     @Override
     public CamelContext getCamelContext() {
         return camelContext;
@@ -143,6 +199,16 @@ public class DefaultRestOpenapiProcessorStrategy extends ServiceSupport
         this.missingOperation = missingOperation;
     }
 
+    @Override
+    public String getMockIncludePattern() {
+        return mockIncludePattern;
+    }
+
+    @Override
+    public void setMockIncludePattern(String mockIncludePattern) {
+        this.mockIncludePattern = mockIncludePattern;
+    }
+
     @Override
     protected void doInit() throws Exception {
         producerCache = new DefaultProducerCache(this, getCamelContext(), 1000);
diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java
index 05858566d23..cefe8244e4a 100644
--- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java
+++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java
@@ -47,7 +47,7 @@ import static org.apache.camel.util.StringHelper.notEmpty;
  * <pre>
  * from(...).to("rest-openapi:https://petstore3.swagger.io/api/v3/openapi.json#getPetById")
  * </pre>
- *
+ * <p>
  * This relies on only one {@link RestProducerFactory} component being available to Camel, you can use specific, for
  * instance preconfigured component by using the {@code componentName} endpoint property. For example using Undertow
  * component in Java DSL:
@@ -61,7 +61,7 @@ import static org.apache.camel.util.StringHelper.notEmpty;
  *
  * from(...).to("rest-openapi:https://petstore3.swagger.io/api/v3/openapi.json#getPetById?componentName=myUndertow")
  * </pre>
- *
+ * <p>
  * The most concise way of using this component would be to define it in the Camel context under a meaningful name, for
  * example:
  *
@@ -133,6 +133,10 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC
     @Metadata(description = "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route.",
               label = "consumer", enums = "fail,ignore,mock", defaultValue = "fail")
     private String missingOperation;
+    @Metadata(description = "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern."
+                            + " Multiple patterns can be specified separated by comma.",
+              label = "consumer,advanced", defaultValue = "classpath:camel-mock/*")
+    private String mockIncludePattern = "classpath:camel-mock/*";
     @Metadata(description = "To use a custom strategy for how to process Rest DSL requests", label = "consumer,advanced")
     private RestOpenapiProcessorStrategy restOpenapiProcessorStrategy = new DefaultRestOpenapiProcessorStrategy();
     @Metadata(description = "Enable usage of global SSL context parameters.", label = "security")
@@ -157,6 +161,7 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC
         endpoint.setRequestValidationLevels(PropertiesHelper.extractProperties(parameters, "validation."));
         endpoint.setRestOpenapiProcessorStrategy(getRestOpenapiProcessorStrategy());
         endpoint.setMissingOperation(getMissingOperation());
+        endpoint.setMockIncludePattern(getMockIncludePattern());
         setProperties(endpoint, parameters);
         return endpoint;
     }
@@ -214,6 +219,14 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC
         this.missingOperation = missingOperation;
     }
 
+    public String getMockIncludePattern() {
+        return mockIncludePattern;
+    }
+
+    public void setMockIncludePattern(String mockIncludePattern) {
+        this.mockIncludePattern = mockIncludePattern;
+    }
+
     public void setBasePath(final String basePath) {
         this.basePath = notEmpty(basePath, "basePath");
     }
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 90cf95b83b5..8852e838f1b 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
@@ -169,6 +169,10 @@ public final class RestOpenApiEndpoint extends DefaultEndpoint {
     @UriParam(description = "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route.",
               enums = "fail,ignore,mock", label = "consumer", defaultValue = "fail")
     private String missingOperation;
+    @UriParam(description = "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern."
+                            + " Multiple patterns can be specified separated by comma.",
+              label = "consumer,advanced", defaultValue = "classpath:camel-mock/*")
+    private String mockIncludePattern;
 
     public RestOpenApiEndpoint() {
         // help tooling instantiate endpoint
@@ -458,6 +462,14 @@ public final class RestOpenApiEndpoint extends DefaultEndpoint {
         this.missingOperation = missingOperation;
     }
 
+    public void setMockIncludePattern(String mockIncludePattern) {
+        this.mockIncludePattern = mockIncludePattern;
+    }
+
+    public String getMockIncludePattern() {
+        return mockIncludePattern;
+    }
+
     Producer createProducerFor(
             final OpenAPI openapi, final Operation operation, final String method,
             final String uriTemplate)
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 d7a6c0e50fa..35aa33035f2 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
@@ -158,6 +158,7 @@ public class RestOpenApiProcessor extends DelegateAsyncProcessor implements Came
         super.doInit();
 
         restOpenapiProcessorStrategy.setMissingOperation(endpoint.getMissingOperation());
+        restOpenapiProcessorStrategy.setMockIncludePattern(endpoint.getMockIncludePattern());
         ServiceHelper.initService(restOpenapiProcessorStrategy);
 
         // validate openapi contract
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 dcb1938dae2..325e2468cae 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
@@ -38,6 +38,18 @@ public interface RestOpenapiProcessorStrategy {
      */
     String getMissingOperation();
 
+    /**
+     * Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple
+     * patterns can be specified separated by comma.
+     */
+    void setMockIncludePattern(String mockIncludePattern);
+
+    /**
+     * Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple
+     * patterns can be specified separated by comma.
+     */
+    String getMockIncludePattern();
+
     /**
      * Validates the OpenAPI specification on startup
      *