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 bcd4534903ced30e334ba235ce9883c2afbc8c52
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Mar 25 10:37:12 2024 +0100

    CAMEL-20557: Rest DSL to use openapi spec directly
---
 .../component/rest/openapi/RestOpenApiComponent.java   |  3 ++-
 .../component/rest/openapi/RestOpenApiEndpoint.java    | 18 +++---------------
 .../component/rest/openapi/RestOpenApiProcessor.java   | 10 ++++++++++
 .../rest/openapi/RestOpenApiRequestValidationTest.java |  3 +--
 4 files changed, 16 insertions(+), 18 deletions(-)

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 eef794e5371..b405b1466c5 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
@@ -22,6 +22,7 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.SSLContextParametersAware;
+import 
org.apache.camel.component.rest.openapi.validator.DefaultRequestValidationCustomizer;
 import 
org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RestProducerFactory;
@@ -133,7 +134,7 @@ public final class RestOpenApiComponent extends 
DefaultComponent implements SSLC
     @Metadata(description = "If request validation is enabled, this option 
provides the capability to customize"
                             + " the creation of OpenApiInteractionValidator 
used to validate requests.",
               label = "advanced")
-    private RequestValidationCustomizer requestValidationCustomizer;
+    private RequestValidationCustomizer requestValidationCustomizer = new 
DefaultRequestValidationCustomizer();
     @Metadata(description = "Enable usage of global SSL context parameters.", 
label = "security")
     private boolean useGlobalSslContextParameters;
     @Metadata(description = "Customize TLS parameters used by the component. 
If not set defaults to the TLS parameters set in the Camel context ",
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 21fde6f5618..034a7e3e56b 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
@@ -62,7 +62,6 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
-import 
org.apache.camel.component.rest.openapi.validator.DefaultRequestValidationCustomizer;
 import 
org.apache.camel.component.rest.openapi.validator.RequestValidationCustomizer;
 import org.apache.camel.component.rest.openapi.validator.RequestValidator;
 import org.apache.camel.component.rest.openapi.validator.RestOpenApiOperation;
@@ -468,9 +467,8 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
         // let the rest endpoint configure itself
         endpoint.configureProperties(params);
 
-        RestOpenApiComponent component = getComponent();
         RequestValidator requestValidator = null;
-        if (component.isRequestValidationEnabled() || 
requestValidationEnabled) {
+        if (requestValidationEnabled) {
             requestValidator = configureRequestValidator(openapi, operation, 
method, uriTemplate);
         }
 
@@ -810,16 +808,6 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
     }
 
     RequestValidator configureRequestValidator(OpenAPI openapi, Operation 
operation, String method, String uriTemplate) {
-        RestOpenApiComponent component = getComponent();
-        RequestValidationCustomizer validationCustomizer = 
requestValidationCustomizer;
-        if (validationCustomizer == null) {
-            validationCustomizer = component.getRequestValidationCustomizer();
-        }
-
-        if (validationCustomizer == null) {
-            validationCustomizer = new DefaultRequestValidationCustomizer();
-        }
-
         RestOpenApiOperation restOpenApiOperation = new 
RestOpenApiOperation(operation, method, uriTemplate);
         OpenApiInteractionValidator.Builder builder = 
OpenApiInteractionValidator.createFor(openapi);
 
@@ -837,9 +825,9 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
         });
         builder.withLevelResolver(levelResolverBuilder.build());
 
-        validationCustomizer.customizeOpenApiInteractionValidator(builder);
+        
requestValidationCustomizer.customizeOpenApiInteractionValidator(builder);
 
-        return new RequestValidator(builder.build(), restOpenApiOperation, 
validationCustomizer);
+        return new RequestValidator(builder.build(), restOpenApiOperation, 
requestValidationCustomizer);
     }
 
     static String determineOption(
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 4cfbccc1839..5e3291d82c9 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
@@ -27,6 +27,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.component.rest.openapi.validator.RequestValidator;
 import org.apache.camel.support.RestConsumerContextPathMatcher;
 import org.apache.camel.support.processor.DelegateAsyncProcessor;
 import org.apache.camel.support.service.ServiceHelper;
@@ -41,6 +42,7 @@ public class RestOpenApiProcessor extends 
DelegateAsyncProcessor implements Came
     private final String basePath;
     private final List<RestConsumerContextPathMatcher.ConsumerPath<Operation>> 
paths = new ArrayList<>();
     private RestOpenapiProcessorStrategy restOpenapiProcessorStrategy;
+    private RequestValidator requestValidator;
 
     public RestOpenApiProcessor(OpenAPI openAPI, String basePath, Processor 
processor) {
         super(processor);
@@ -67,6 +69,14 @@ public class RestOpenApiProcessor extends 
DelegateAsyncProcessor implements Came
         this.restOpenapiProcessorStrategy = restOpenapiProcessorStrategy;
     }
 
+    public RequestValidator getRequestValidator() {
+        return requestValidator;
+    }
+
+    public void setRequestValidator(RequestValidator requestValidator) {
+        this.requestValidator = requestValidator;
+    }
+
     @Override
     public boolean process(Exchange exchange, AsyncCallback callback) {
         // TODO: RequestValidator
diff --git 
a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiRequestValidationTest.java
 
b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiRequestValidationTest.java
index 82593e6c461..cf2cf854e58 100644
--- 
a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiRequestValidationTest.java
+++ 
b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiRequestValidationTest.java
@@ -68,7 +68,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class RestOpenApiRequestValidationTest extends CamelTestSupport {
@@ -362,7 +361,7 @@ public class RestOpenApiRequestValidationTest extends 
CamelTestSupport {
         RestOpenApiEndpoint endpoint = context.getEndpoint(petStoreVersion + 
":#addPet", RestOpenApiEndpoint.class);
         endpoint.createProducer();
         assertFalse(endpoint.isRequestValidationEnabled());
-        assertNull(endpoint.getRequestValidationCustomizer());
+        assertNotNull(endpoint.getRequestValidationCustomizer());
         assertTrue(endpoint.getRequestValidationLevels().isEmpty());
     }
 

Reply via email to