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

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


The following commit(s) were added to refs/heads/camel-3.11.x by this push:
     new 71fafc3  CAMEL-17049: camel-rest-openapi should avoid duplicate 
parameters if the param is a path param.
71fafc3 is described below

commit 71fafc3304bb178f4e55bfd2ee68587dae06cfe5
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Oct 12 07:37:22 2021 +0200

    CAMEL-17049: camel-rest-openapi should avoid duplicate parameters if the 
param is a path param.
---
 .../component/rest/openapi/RestOpenApiEndpoint.java    | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 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 7c13e5f..330adb9 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
@@ -478,8 +478,7 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
             parameters.put("consumes", determinedConsumes);
         }
 
-        // what we produce is what the API defined by OpenApi specification
-        // consumes
+        // what we produce is what the API defined by OpenApi specification 
consumes
 
         List<String> specificationLevelProducers = new ArrayList<>();
         if (openapi instanceof Oas20Document) {
@@ -493,7 +492,6 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
             if (oas30Operation.requestBody != null && 
oas30Operation.requestBody.content != null) {
                 
operationLevelProducers.addAll(oas30Operation.requestBody.content.keySet());
             }
-
         }
 
         final String determinedProducers = 
determineOption(specificationLevelProducers, operationLevelProducers,
@@ -528,7 +526,18 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
         }
 
         // Add rest endpoint parameters
-        nestedParameters.putAll(this.parameters);
+        if (this.parameters != null && operation.getParameters() != null) {
+            for (Map.Entry<String, Object> entry : this.parameters.entrySet()) 
{
+                for (OasParameter param : operation.getParameters()) {
+                    // skip parameters that are part of the operation as path 
as otherwise
+                    // it will be duplicated as query parameter as well
+                    boolean clash = "path".equals(param.in) && 
entry.getKey().equals(param.getName());
+                    if (!clash) {
+                        nestedParameters.put(entry.getKey(), entry.getValue());
+                    }
+                }
+            }
+        }
 
         if (!nestedParameters.isEmpty()) {
             // we're trying to set RestEndpoint.parameters['component']
@@ -742,7 +751,6 @@ public final class RestOpenApiEndpoint extends 
DefaultEndpoint {
             } else {
                 throw new IllegalStateException("We only support OpenApi 2.0 
or 3.0 document here");
             }
-
         }
 
         if (operation.getParameters() != null) {

Reply via email to