You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2020/03/10 22:49:21 UTC

[camel] branch master updated (9f22b6a -> 1070ac8)

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

zregvart pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 9f22b6a  Merge pull request #3623 from tulsidas/patch-1
     new fe5c7a2  CAMEL-14691: Remove versions from pom.xml
     new 9529789  CAMEL-14691: Code cleanup
     new 1070ac8  CAMEL-14691: dereference parameters

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 tooling/openapi-rest-dsl-generator/pom.xml         |   2 -
 .../generator/openapi/AppendableGenerator.java     |   4 +-
 .../camel/generator/openapi/FilerGenerator.java    |   4 +-
 .../openapi/MethodBodySourceCodeEmitter.java       |  64 +++---
 .../camel/generator/openapi/OperationFilter.java   |   9 +-
 .../camel/generator/openapi/OperationVisitor.java  |  93 +++++----
 .../camel/generator/openapi/PathGenerator.java     |   4 +-
 .../camel/generator/openapi/PathVisitor.java       |  41 ++--
 .../generator/openapi/RestDefinitionEmitter.java   |  10 +-
 .../openapi/RestDslDefinitionGenerator.java        |   8 +-
 .../camel/generator/openapi/RestDslGenerator.java  | 230 +++++++++++----------
 .../openapi/RestDslSourceCodeGenerator.java        |  33 ++-
 .../generator/openapi/RestDslXmlGenerator.java     |  10 +-
 .../SpringBootProjectSourceCodeGenerator.java      |  48 ++---
 .../generator/openapi/OperationVisitorTest.java    | 163 +++++++++++++++
 .../PathSpringBootProjectSourceGeneratorTest.java  |   5 +-
 .../openapi/RestDefinitionEmitterTest.java         |  60 +++---
 .../generator/openapi/RestDslGeneratorTest.java    | 163 ++++++++++++---
 .../generator/openapi/RestDslGeneratorV3Test.java  |  85 ++++----
 .../openapi/RestDslSourceCodeGeneratorTest.java    |  13 +-
 .../openapi/RestDslSourceCodeGeneratorV3Test.java  |  19 +-
 .../generator/openapi/RestDslXmlGeneratorTest.java |  84 ++++----
 .../openapi/RestDslXmlGeneratorV3Test.java         |  86 ++++----
 .../camel/generator/openapi}/openapi-spec.json     |   0
 .../camel/generator/openapi}/openapi-v2.json       |   0
 25 files changed, 766 insertions(+), 472 deletions(-)
 create mode 100644 tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/OperationVisitorTest.java
 rename tooling/openapi-rest-dsl-generator/{ => src/test/resources/org/apache/camel/generator/openapi}/openapi-spec.json (100%)
 rename tooling/openapi-rest-dsl-generator/{ => src/test/resources/org/apache/camel/generator/openapi}/openapi-v2.json (100%)


[camel] 02/03: CAMEL-14691: Code cleanup

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9529789dd2de8e57c66b580f9a7daa5f441e41ec
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Tue Mar 10 23:02:11 2020 +0100

    CAMEL-14691: Code cleanup
    
     - makes sure that autocloseable resources are used with
       try-with-resources
     - parameter names reflect their use
     - resources are not loaded outside of the `src` directory
     - methods that can be static are declared as static
     - methods are not named `get...`
     - referenced values are used instead of fetched again (e.g. repeated
       getServers())
     - URL class is not used
     - when possible early exits are taken
     - doesn't rely on non-standard base path resolution from `basePath`
       variable (used in example, no bearing on the base path)
     - removes trailing whitespace
     - use final where possible
     - corrects AssertJ usage
     - adds tests for refactored code
---
 .../generator/openapi/AppendableGenerator.java     |   4 +-
 .../camel/generator/openapi/FilerGenerator.java    |   4 +-
 .../openapi/MethodBodySourceCodeEmitter.java       |  64 +++---
 .../camel/generator/openapi/OperationFilter.java   |   9 +-
 .../camel/generator/openapi/OperationVisitor.java  |  59 +++---
 .../camel/generator/openapi/PathGenerator.java     |   4 +-
 .../camel/generator/openapi/PathVisitor.java       |  41 ++--
 .../generator/openapi/RestDefinitionEmitter.java   |  10 +-
 .../openapi/RestDslDefinitionGenerator.java        |   8 +-
 .../camel/generator/openapi/RestDslGenerator.java  | 230 +++++++++++----------
 .../openapi/RestDslSourceCodeGenerator.java        |  33 ++-
 .../generator/openapi/RestDslXmlGenerator.java     |  10 +-
 .../SpringBootProjectSourceCodeGenerator.java      |  48 ++---
 .../PathSpringBootProjectSourceGeneratorTest.java  |   5 +-
 .../openapi/RestDefinitionEmitterTest.java         |  60 +++---
 .../generator/openapi/RestDslGeneratorTest.java    | 163 ++++++++++++---
 .../generator/openapi/RestDslGeneratorV3Test.java  |  85 ++++----
 .../openapi/RestDslSourceCodeGeneratorTest.java    |  13 +-
 .../openapi/RestDslSourceCodeGeneratorV3Test.java  |  19 +-
 .../generator/openapi/RestDslXmlGeneratorTest.java |  84 ++++----
 .../openapi/RestDslXmlGeneratorV3Test.java         |  86 ++++----
 .../camel/generator/openapi}/openapi-spec.json     |   0
 .../camel/generator/openapi}/openapi-v2.json       |   0
 23 files changed, 583 insertions(+), 456 deletions(-)

diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/AppendableGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/AppendableGenerator.java
index 3e51540..b76a2ac 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/AppendableGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/AppendableGenerator.java
@@ -23,8 +23,8 @@ import io.apicurio.datamodels.openapi.models.OasDocument;
 
 final class AppendableGenerator extends RestDslSourceCodeGenerator<Appendable> {
 
-    AppendableGenerator(final OasDocument openapi) {
-        super(openapi);
+    AppendableGenerator(final OasDocument document) {
+        super(document);
     }
 
     @Override
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/FilerGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/FilerGenerator.java
index 093b373..c376842 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/FilerGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/FilerGenerator.java
@@ -25,8 +25,8 @@ import io.apicurio.datamodels.openapi.models.OasDocument;
 
 final class FilerGenerator extends RestDslSourceCodeGenerator<Filer> {
 
-    FilerGenerator(final OasDocument openapi) {
-        super(openapi);
+    FilerGenerator(final OasDocument document) {
+        super(document);
     }
 
     @Override
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/MethodBodySourceCodeEmitter.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/MethodBodySourceCodeEmitter.java
index 34e70bf..dbbe3cd 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/MethodBodySourceCodeEmitter.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/MethodBodySourceCodeEmitter.java
@@ -81,38 +81,6 @@ class MethodBodySourceCodeEmitter implements CodeEmitter<MethodSpec> {
         return builder.build();
     }
 
-    Object[] argumentsFor(final Object[] args) {
-        final List<Object> arguments = new ArrayList<>(args.length);
-
-        for (final Object arg : args) {
-            if (isPrimitiveOrWrapper(arg.getClass())) {
-                arguments.add(arg);
-            } else if (arg instanceof String) {
-                arguments.add(arg);
-            } else if (arg instanceof Enum) {
-                arguments.add(arg.getClass());
-                arguments.add(arg);
-            } else if (arg instanceof String[]) {
-                arguments.add(Arrays.stream((String[]) arg).collect(Collectors.joining(",")));
-            }
-        }
-
-        return arguments.toArray(new Object[arguments.size()]);
-    }
-
-    Object[] extend(final Object first, final Object... others) {
-        if (others == null || others.length == 0) {
-            return new Object[] {first};
-        }
-
-        final Object[] ret = new Object[1 + others.length];
-
-        ret[0] = first;
-        System.arraycopy(others, 0, ret, 1, others.length);
-
-        return ret;
-    }
-
     int indentLevelOf(final String method) {
         switch (method) {
             case "rest":
@@ -163,4 +131,36 @@ class MethodBodySourceCodeEmitter implements CodeEmitter<MethodSpec> {
         return literals.toString();
     }
 
+    static Object[] argumentsFor(final Object[] args) {
+        final List<Object> arguments = new ArrayList<>(args.length);
+
+        for (final Object arg : args) {
+            if (isPrimitiveOrWrapper(arg.getClass())) {
+                arguments.add(arg);
+            } else if (arg instanceof String) {
+                arguments.add(arg);
+            } else if (arg instanceof Enum) {
+                arguments.add(arg.getClass());
+                arguments.add(arg);
+            } else if (arg instanceof String[]) {
+                arguments.add(Arrays.stream((String[]) arg).collect(Collectors.joining(",")));
+            }
+        }
+
+        return arguments.toArray(new Object[arguments.size()]);
+    }
+
+    static Object[] extend(final Object first, final Object... others) {
+        if (others == null || others.length == 0) {
+            return new Object[] {first};
+        }
+
+        final Object[] ret = new Object[1 + others.length];
+
+        ret[0] = first;
+        System.arraycopy(others, 0, ret, 1, others.length);
+
+        return ret;
+    }
+
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationFilter.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationFilter.java
index 82371f6..ad74141 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationFilter.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationFilter.java
@@ -22,22 +22,23 @@ import org.apache.camel.support.PatternHelper;
 
 class OperationFilter {
 
-    // operation names to include separated by comma (wildcards can be used, eg find*)
+    // operation names to include separated by comma (wildcards can be used, eg
+    // find*)
     private String includes;
 
     public String getIncludes() {
         return includes;
     }
 
-    public void setIncludes(String includes) {
+    public void setIncludes(final String includes) {
         this.includes = includes;
     }
 
-    boolean accept(String name) {
+    boolean accept(final String name) {
         boolean match = true;
 
         if (includes != null) {
-            String[] patterns = includes.split(",");
+            final String[] patterns = includes.split(",");
             match = Arrays.stream(patterns).anyMatch(pattern -> PatternHelper.matchPattern(name, pattern));
         }
         return match;
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java
index d905f78..98e7d82 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java
@@ -76,7 +76,7 @@ class OperationVisitor<T> {
         }
         if (!parameterType.equals("body")) {
             if (parameter instanceof Oas20Parameter) {
-                final Oas20Parameter serializableParameter = (Oas20Parameter)parameter;
+                final Oas20Parameter serializableParameter = (Oas20Parameter) parameter;
 
                 final String dataType = serializableParameter.type;
                 emit("dataType", dataType);
@@ -86,7 +86,7 @@ class OperationVisitor<T> {
                     emit("collectionFormat", CollectionFormat.valueOf(collectionFormat));
                 }
                 if (ObjectHelper.isNotEmpty(serializableParameter.default_)) {
-                    String value = serializableParameter.default_.toString();
+                    final String value = serializableParameter.default_.toString();
                     emit("defaultValue", value);
                 }
 
@@ -95,8 +95,8 @@ class OperationVisitor<T> {
                     emit("arrayType", items.type);
                 }
             } else if (parameter instanceof Oas30Parameter) {
-                final Oas30Parameter serializableParameter = (Oas30Parameter)parameter;
-                Oas30Schema schema = (Oas30Schema)serializableParameter.schema;
+                final Oas30Parameter serializableParameter = (Oas30Parameter) parameter;
+                final Oas30Schema schema = (Oas30Schema) serializableParameter.schema;
                 if (schema != null) {
                     final String dataType = schema.type;
                     if (ObjectHelper.isNotEmpty(dataType)) {
@@ -114,13 +114,13 @@ class OperationVisitor<T> {
                         }
                     }
                     if (ObjectHelper.isNotEmpty(schema.default_)) {
-                        String value = schema.default_.toString();
+                        final String value = schema.default_.toString();
                         emit("defaultValue", value);
                     }
 
                     if ("array".equals(dataType) && schema.items != null
                         && schema.items instanceof Oas30ItemsSchema) {
-                        emit("arrayType", ((Oas30ItemsSchema)schema.items).type);
+                        emit("arrayType", ((Oas30ItemsSchema) schema.items).type);
                     }
                 }
             }
@@ -159,59 +159,58 @@ class OperationVisitor<T> {
 
             emit("id", operation.operationId);
             emit("description", operation.description);
-            List<String> operationLevelConsumes = new ArrayList<String>();
+            List<String> operationLevelConsumes = new ArrayList<>();
             if (operation instanceof Oas20Operation) {
-                operationLevelConsumes = ((Oas20Operation)operation).consumes;
+                operationLevelConsumes = ((Oas20Operation) operation).consumes;
             } else if (operation instanceof Oas30Operation) {
-                Oas30Operation oas30Operation = (Oas30Operation)operation;
-                if (oas30Operation.requestBody != null 
-                    && oas30Operation.requestBody.content != null) { 
-                    for (String ct : oas30Operation.requestBody.content.keySet()) {
+                final Oas30Operation oas30Operation = (Oas30Operation) operation;
+                if (oas30Operation.requestBody != null
+                    && oas30Operation.requestBody.content != null) {
+                    for (final String ct : oas30Operation.requestBody.content.keySet()) {
                         operationLevelConsumes.add(ct);
                     }
                 }
-                    
+
             }
             emit("consumes", operationLevelConsumes);
-            List<String> operationLevelProduces = new ArrayList<String>();
+            List<String> operationLevelProduces = new ArrayList<>();
             if (operation instanceof Oas20Operation) {
-                operationLevelProduces = ((Oas20Operation)operation).produces;
+                operationLevelProduces = ((Oas20Operation) operation).produces;
             } else if (operation instanceof Oas30Operation) {
-                Oas30Operation oas30Operation = (Oas30Operation)operation;
+                final Oas30Operation oas30Operation = (Oas30Operation) operation;
                 if (oas30Operation.responses != null) {
-                    for (OasResponse response : oas30Operation.responses.getResponses()) {
-                        Oas30Response oas30Response = (Oas30Response)response;
-                        for (String ct : oas30Response.content.keySet()) {
+                    for (final OasResponse response : oas30Operation.responses.getResponses()) {
+                        final Oas30Response oas30Response = (Oas30Response) response;
+                        for (final String ct : oas30Response.content.keySet()) {
                             operationLevelProduces.add(ct);
                         }
                     }
                 }
             }
             emit("produces", operationLevelProduces);
-            
+
             if (operation.getParameters() != null) {
                 operation.getParameters().forEach(parameter -> {
                     emit(parameter);
                 });
             }
             if (operation instanceof Oas30Operation) {
-                emitOas30Operation((Oas30Operation)operation);
+                emitOas30Operation((Oas30Operation) operation);
             }
 
             emitter.emit("to", destinationGenerator.generateDestinationFor(operation));
         }
     }
 
-    private CodeEmitter<T> emitOas30Operation(Oas30Operation operation) {
-        
+    private CodeEmitter<T> emitOas30Operation(final Oas30Operation operation) {
         if (operation.requestBody != null) {
             boolean foundForm = false;
-            Oas30RequestBody requestBody = operation.requestBody;
-            for (Entry<String, Oas30MediaType> entry : requestBody.content.entrySet()) {
-                String ct = entry.getKey();
-                Oas30MediaType mediaType = entry.getValue();
+            final Oas30RequestBody requestBody = operation.requestBody;
+            for (final Entry<String, Oas30MediaType> entry : requestBody.content.entrySet()) {
+                final String ct = entry.getKey();
+                final Oas30MediaType mediaType = entry.getValue();
                 if (ct.contains("form") && mediaType.schema.properties != null) {
-                    for (Entry<String, OasSchema> entrySchema :  mediaType.schema.properties.entrySet()) {
+                    for (final Entry<String, OasSchema> entrySchema : mediaType.schema.properties.entrySet()) {
                         foundForm = true;
                         emitter.emit("param");
                         emit("name", entrySchema.getKey());
@@ -232,8 +231,8 @@ class OperationVisitor<T> {
                 emitter.emit("endParam");
             }
         }
-        
+
         return emitter;
-        
+
     }
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathGenerator.java
index f89aba8..148e449 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathGenerator.java
@@ -24,8 +24,8 @@ import io.apicurio.datamodels.openapi.models.OasDocument;
 
 final class PathGenerator extends RestDslSourceCodeGenerator<Path> {
 
-    PathGenerator(final OasDocument openapi) {
-        super(openapi);
+    PathGenerator(final OasDocument document) {
+        super(document);
     }
 
     @Override
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathVisitor.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathVisitor.java
index ca3c0bc..a6cac93 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathVisitor.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/PathVisitor.java
@@ -28,9 +28,20 @@ class PathVisitor<T> {
     private final DestinationGenerator destinationGenerator;
 
     private final CodeEmitter<T> emitter;
+
     private final OperationFilter filter;
 
-    PathVisitor(final String basePath, final CodeEmitter<T> emitter, OperationFilter filter, final DestinationGenerator destinationGenerator) {
+    public enum HttpMethod {
+        DELETE,
+        GET,
+        HEAD,
+        OPTIONS,
+        PATCH,
+        POST,
+        PUT
+    }
+
+    PathVisitor(final String basePath, final CodeEmitter<T> emitter, final OperationFilter filter, final DestinationGenerator destinationGenerator) {
         this.emitter = emitter;
         this.filter = filter;
         this.destinationGenerator = destinationGenerator;
@@ -42,20 +53,20 @@ class PathVisitor<T> {
         }
     }
 
+    void visit(final OasPathItem definition) {
+        final OperationVisitor<T> restDslOperation = new OperationVisitor<>(emitter, filter, definition.getPath(), destinationGenerator);
+
+        operationMapFrom(definition).forEach(restDslOperation::visit);
+    }
+
     void visit(final String path, final OasPathItem definition) {
         final OperationVisitor<T> restDslOperation = new OperationVisitor<>(emitter, filter, path, destinationGenerator);
 
-        getOperationMap(definition).forEach(restDslOperation::visit);
+        operationMapFrom(definition).forEach(restDslOperation::visit);
     }
-    
-    void visit(final OasPathItem definition) {
-        final OperationVisitor<T> restDslOperation = new OperationVisitor<>(emitter, filter, definition.getPath(), destinationGenerator);
 
-        getOperationMap(definition).forEach(restDslOperation::visit);
-    }
-    
-    private Map<HttpMethod, OasOperation> getOperationMap(OasPathItem path) {
-        Map<HttpMethod, OasOperation> result = new LinkedHashMap<HttpMethod, OasOperation>();
+    private static Map<HttpMethod, OasOperation> operationMapFrom(final OasPathItem path) {
+        final Map<HttpMethod, OasOperation> result = new LinkedHashMap<>();
 
         if (path.get != null) {
             result.put(HttpMethod.GET, path.get);
@@ -81,15 +92,5 @@ class PathVisitor<T> {
 
         return result;
     }
-    
-    public enum HttpMethod {
-        POST,
-        GET,
-        PUT,
-        PATCH,
-        DELETE,
-        HEAD,
-        OPTIONS
-    }
 
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDefinitionEmitter.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDefinitionEmitter.java
index 955647b..bcad4fe 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDefinitionEmitter.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDefinitionEmitter.java
@@ -49,9 +49,9 @@ class RestDefinitionEmitter implements CodeEmitter<RestsDefinition> {
         } catch (final Throwable e) {
             if (e instanceof RuntimeException) {
                 throw (RuntimeException) e;
-            } else {
-                throw new IllegalStateException(e);
             }
+
+            throw new IllegalStateException(e);
         }
 
         return this;
@@ -62,7 +62,7 @@ class RestDefinitionEmitter implements CodeEmitter<RestsDefinition> {
         return definition;
     }
 
-    Object[] argumentsFor(final Object[] args) {
+    static Object[] argumentsFor(final Object[] args) {
         final List<Object> arguments = new ArrayList<>(args.length);
 
         for (final Object arg : args) {
@@ -76,7 +76,7 @@ class RestDefinitionEmitter implements CodeEmitter<RestsDefinition> {
         return arguments.toArray(new Object[arguments.size()]);
     }
 
-    Class<?>[] parameterTypesOf(final Object[] args) {
+    static Class<?>[] parameterTypesOf(final Object[] args) {
         final Class<?>[] parameterTypes = new Class<?>[args.length];
 
         for (int i = 0; i < args.length; i++) {
@@ -86,7 +86,7 @@ class RestDefinitionEmitter implements CodeEmitter<RestsDefinition> {
         return parameterTypes;
     }
 
-    Class<?>[] typesOf(final Object[] args) {
+    static Class<?>[] typesOf(final Object[] args) {
         final Class<?>[] types = new Class<?>[args.length];
 
         for (int i = 0; i < types.length; i++) {
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslDefinitionGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslDefinitionGenerator.java
index 27ae620..3fdb374 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslDefinitionGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslDefinitionGenerator.java
@@ -22,16 +22,16 @@ import org.apache.camel.model.rest.RestsDefinition;
 
 public final class RestDslDefinitionGenerator extends RestDslGenerator<RestDslDefinitionGenerator> {
 
-    RestDslDefinitionGenerator(final OasDocument openapi) {
-        super(openapi);
+    RestDslDefinitionGenerator(final OasDocument document) {
+        super(document);
     }
 
     public RestsDefinition generate(final CamelContext context) {
         final RestDefinitionEmitter emitter = new RestDefinitionEmitter(context);
-        String basePath = RestDslGenerator.getBasePathFromOasDocument(openapi);
+        final String basePath = RestDslGenerator.determineBasePathFrom(document);
         final PathVisitor<RestsDefinition> restDslStatement = new PathVisitor<>(basePath, emitter, filter, destinationGenerator());
 
-        openapi.paths.getPathItems().forEach(restDslStatement::visit);
+        document.paths.getPathItems().forEach(restDslStatement::visit);
 
         return emitter.result();
     }
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslGenerator.java
index 90d243f..b2b7c48 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslGenerator.java
@@ -16,21 +16,20 @@
  */
 package org.apache.camel.generator.openapi;
 
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
 import java.nio.file.Path;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.List;
+import java.util.Objects;
 
 import javax.annotation.processing.Filer;
 
+import io.apicurio.datamodels.core.models.common.Server;
+import io.apicurio.datamodels.core.models.common.ServerVariable;
 import io.apicurio.datamodels.openapi.models.OasDocument;
 import io.apicurio.datamodels.openapi.v2.models.Oas20Document;
 import io.apicurio.datamodels.openapi.v3.models.Oas30Document;
 import io.apicurio.datamodels.openapi.v3.models.Oas30Server;
 import org.apache.camel.model.rest.RestsDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.util.ObjectHelper.notNull;
 
@@ -40,25 +39,28 @@ import static org.apache.camel.util.ObjectHelper.notNull;
  */
 public abstract class RestDslGenerator<G> {
 
-    private static final Logger LOG = LoggerFactory.getLogger(RestDslGenerator.class);
-    final OasDocument openapi;
+    String apiContextPath;
 
-    
     DestinationGenerator destinationGenerator = new DirectToOperationId();
+
+    final OasDocument document;
+
     OperationFilter filter = new OperationFilter();
+
     String restComponent;
+
     String restContextPath;
-    String apiContextPath;
-    boolean springComponent;
+
     boolean springBootProject;
 
-    RestDslGenerator(final OasDocument openapi) {
-        this.openapi = notNull(openapi, "openapi");
+    boolean springComponent;
+
+    RestDslGenerator(final OasDocument document) {
+        this.document = notNull(document, "document");
     }
 
-    public G withDestinationGenerator(final DestinationGenerator directRouteGenerator) {
-        notNull(directRouteGenerator, "directRouteGenerator");
-        this.destinationGenerator = directRouteGenerator;
+    public G asSpringBootProject() {
+        this.springBootProject = true;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -66,12 +68,8 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    DestinationGenerator destinationGenerator() {
-        return destinationGenerator;
-    }
-
-    public G withOperationFilter(OperationFilter filter) {
-        this.filter = filter;
+    public G asSpringComponent() {
+        this.springComponent = true;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -79,8 +77,8 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    public G withOperationFilter(String include) {
-        this.filter.setIncludes(include);
+    public G withApiContextPath(final String contextPath) {
+        this.apiContextPath = contextPath;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -88,8 +86,9 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    public G withRestComponent(String restComponent) {
-        this.restComponent = restComponent;
+    public G withDestinationGenerator(final DestinationGenerator directRouteGenerator) {
+        notNull(directRouteGenerator, "directRouteGenerator");
+        this.destinationGenerator = directRouteGenerator;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -97,17 +96,17 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    public G withRestContextPath(String contextPath) {
-        this.restContextPath = contextPath;
+    public G withOperationFilter(final OperationFilter filter) {
+        this.filter = filter;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
 
         return that;
     }
-    
-    public G withApiContextPath(String contextPath) {
-        this.apiContextPath = contextPath;
+
+    public G withOperationFilter(final String include) {
+        this.filter.setIncludes(include);
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -115,8 +114,8 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    public G asSpringComponent() {
-        this.springComponent = true;
+    public G withRestComponent(final String restComponent) {
+        this.restComponent = restComponent;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -124,8 +123,8 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    public G asSpringBootProject() {
-        this.springBootProject = true;
+    public G withRestContextPath(final String contextPath) {
+        this.restContextPath = contextPath;
 
         @SuppressWarnings("unchecked")
         final G that = (G) this;
@@ -133,93 +132,98 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
-    public static RestDslSourceCodeGenerator<Appendable> toAppendable(final OasDocument openapi) {
-        return new AppendableGenerator(openapi);
+    DestinationGenerator destinationGenerator() {
+        return destinationGenerator;
     }
 
-    public static RestDslDefinitionGenerator toDefinition(final OasDocument openapi) {
-        return new RestDslDefinitionGenerator(openapi);
-    }
+    public static String determineBasePathFrom(final OasDocument document) {
+        Objects.requireNonNull(document, "document");
 
-    public static RestDslXmlGenerator toXml(final OasDocument openapi) {
-        return new RestDslXmlGenerator(openapi);
-    }
+        if (document instanceof Oas20Document) {
+            return ((Oas20Document) document).basePath;
+        } else if (document instanceof Oas30Document) {
+            final Oas30Document oas30Document = (Oas30Document) document;
+            final List<Server> servers = oas30Document.getServers();
 
-    public static RestDslSourceCodeGenerator<Filer> toFiler(final OasDocument openapi) {
-        return new FilerGenerator(openapi);
-    }
+            if (servers == null || servers.get(0) == null) {
+                return "";
+            }
 
-    public static RestDslSourceCodeGenerator<Path> toPath(final OasDocument openapi) {
-        return new PathGenerator(openapi);
-    }
-    
-    public static String getHostFromOasDocument(final OasDocument openapi) {
-        String host = null;
-        if (openapi instanceof Oas20Document) {
-            host = ((Oas20Document)openapi).host;
-        } else if (openapi instanceof Oas30Document) {
-            if (((Oas30Document)openapi).getServers() != null 
-                && ((Oas30Document)openapi).getServers().get(0) != null) {
-                try {
-                    URL serverUrl = new URL(parseVariables(((Oas30Document)openapi).getServers().get(0).url, (Oas30Server)((Oas30Document)openapi).getServers().get(0)));
-                    host = serverUrl.getHost();
-                
-                } catch (MalformedURLException e) {
-                    LOG.info("error when parsing OpenApi 3.0 doc server url", e);
-                }
+            final Oas30Server firstServer = (Oas30Server) servers.get(0);
+            final URI serverUrl = URI.create(resolveVariablesIn(firstServer.url, firstServer));
+            String basePath = serverUrl.getPath();
+            if (basePath == null || basePath.length() == 0) {
+                return "";
             }
-        }
-        return host;
-        
-    }
-    
-    public static String getBasePathFromOasDocument(final OasDocument openapi) {
-        String basePath = null;
-        if (openapi instanceof Oas20Document) {
-            basePath = ((Oas20Document)openapi).basePath;
-        } else if (openapi instanceof Oas30Document) {
-            if (((Oas30Document)openapi).getServers() != null 
-                && ((Oas30Document)openapi).getServers().get(0) != null) {
-                try {
-                    Oas30Server server = (Oas30Server)((Oas30Document)openapi).getServers().get(0);
-                    if (server.variables != null && server.variables.get("basePath") != null) {
-                        basePath = server.variables.get("basePath").default_;
-                    }
-                    if (basePath == null) {
-                        // parse server url as fallback
-                        URL serverUrl = new URL(parseVariables(((Oas30Document)openapi).getServers().get(0).url, server));
-                        basePath = serverUrl.getPath();
-                        if (basePath.indexOf("//") == 0) {
-                            // strip off the first "/" if double "/" exists
-                            basePath = basePath.substring(1);
-                        }
-                        if ("/".equals(basePath)) {
-                            basePath = "";
-                        }
-                    } 
-                                    
-                } catch (MalformedURLException e) {
-                    //not a valid whole url, just the basePath
-                    basePath = ((Oas30Document)openapi).getServers().get(0).url;
-                }
+
+            if (basePath.charAt(0) != '/') {
+                basePath = "/" + basePath;
             }
-            
+
+            if (basePath.indexOf("//") == 0) {
+                // strip off the first "/" if double "/" exists
+                basePath = basePath.substring(1);
+            }
+
+            if ("/".equals(basePath)) {
+                basePath = "";
+            }
+
+            return basePath;
         }
-        return basePath;
-        
-    }
- 
-    public static String parseVariables(String url, Oas30Server server) {
-        Pattern p = Pattern.compile("\\{(.*?)\\}");
-        Matcher m = p.matcher(url);
-        while (m.find()) {
-           
-            String var = m.group(1);
-            if (server != null && server.variables != null && server.variables.get(var) != null) {
-                String varValue = server.variables.get(var).default_;
-                url = url.replace("{" + var + "}", varValue);
+
+        throw new IllegalArgumentException("Unsupported document type: " + document.getClass().getName());
+    }
+
+    public static String determineHostFrom(final OasDocument document) {
+        if (document instanceof Oas20Document) {
+            return ((Oas20Document) document).host;
+        } else if (document instanceof Oas30Document) {
+            final Oas30Document oas30Document = (Oas30Document) document;
+            final List<Server> servers = oas30Document.getServers();
+
+            if (servers == null || servers.get(0) == null) {
+                return "";
             }
+
+            final Oas30Server firstServer = (Oas30Server) servers.get(0);
+
+            final URI serverUrl = URI.create(resolveVariablesIn(firstServer.url, firstServer));
+
+            return serverUrl.getHost();
         }
-        return url;
+
+        throw new IllegalArgumentException("Unsupported document type: " + document.getClass().getName());
+    }
+
+    public static String resolveVariablesIn(final String url, final Oas30Server server) {
+        final List<ServerVariable> variables = Objects.requireNonNull(server, "server").getServerVariables();
+        String withoutPlaceholders = url;
+        for (final ServerVariable variable : variables) {
+            final String name = "{" + variable.getName() + "}";
+            withoutPlaceholders = withoutPlaceholders.replace(name, variable.default_);
+        }
+
+        return withoutPlaceholders;
+    }
+
+    public static RestDslSourceCodeGenerator<Appendable> toAppendable(final OasDocument document) {
+        return new AppendableGenerator(document);
+    }
+
+    public static RestDslDefinitionGenerator toDefinition(final OasDocument document) {
+        return new RestDslDefinitionGenerator(document);
+    }
+
+    public static RestDslSourceCodeGenerator<Filer> toFiler(final OasDocument document) {
+        return new FilerGenerator(document);
+    }
+
+    public static RestDslSourceCodeGenerator<Path> toPath(final OasDocument document) {
+        return new PathGenerator(document);
+    }
+
+    public static RestDslXmlGenerator toXml(final OasDocument document) {
+        return new RestDslXmlGenerator(document);
     }
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslSourceCodeGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslSourceCodeGenerator.java
index 70d9aa7..5750954 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslSourceCodeGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslSourceCodeGenerator.java
@@ -43,7 +43,7 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
     static final String DEFAULT_CLASS_NAME = "RestDslRoute";
 
     static final String DEFAULT_PACKAGE_NAME = "rest.dsl.generated";
-    
+
     private static final String DEFAULT_INDENT = "    ";
 
     private Function<OasDocument, String> classNameGenerator = RestDslSourceCodeGenerator::generateClassName;
@@ -56,8 +56,8 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
 
     private boolean sourceCodeTimestamps;
 
-    RestDslSourceCodeGenerator(final OasDocument openapi) {
-        super(openapi);
+    RestDslSourceCodeGenerator(final OasDocument document) {
+        super(document);
     }
 
     public abstract void generate(T destination) throws IOException;
@@ -94,7 +94,7 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return this;
     }
 
-    MethodSpec generateConfigureMethod(final OasDocument openapi) {
+    MethodSpec generateConfigureMethod(final OasDocument document) {
         final MethodSpec.Builder configure = MethodSpec.methodBuilder("configure").addModifiers(Modifier.PUBLIC)
             .returns(void.class).addJavadoc("Defines Apache Camel routes using REST DSL fluent API.\n");
 
@@ -112,10 +112,10 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
             configure.addCode(";\n\n");
         }
 
-        String basePath = RestDslGenerator.getBasePathFromOasDocument(openapi); 
-            
+        final String basePath = RestDslGenerator.determineBasePathFrom(document);
+
         final PathVisitor<MethodSpec> restDslStatement = new PathVisitor<>(basePath, emitter, filter, destinationGenerator());
-        openapi.paths.getItems().forEach(restDslStatement::visit);
+        document.paths.getItems().forEach(restDslStatement::visit);
         return emitter.result();
     }
 
@@ -124,9 +124,9 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
     }
 
     JavaFile generateSourceCode() {
-        final MethodSpec methodSpec = generateConfigureMethod(openapi);
+        final MethodSpec methodSpec = generateConfigureMethod(document);
 
-        final String classNameToUse = classNameGenerator.apply(openapi);
+        final String classNameToUse = classNameGenerator.apply(document);
 
         final AnnotationSpec.Builder generatedAnnotation = AnnotationSpec.builder(Generated.class).addMember("value",
             "$S", getClass().getName());
@@ -134,7 +134,7 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
             generatedAnnotation.addMember("date", "$S", generated());
         }
 
-        TypeSpec.Builder builder = TypeSpec.classBuilder(classNameToUse).superclass(RouteBuilder.class)
+        final TypeSpec.Builder builder = TypeSpec.classBuilder(classNameToUse).superclass(RouteBuilder.class)
             .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(methodSpec)
             .addAnnotation(generatedAnnotation.build())
             .addJavadoc("Generated from OpenApi specification by Camel REST DSL generator.\n");
@@ -142,9 +142,9 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
             final AnnotationSpec.Builder springAnnotation = AnnotationSpec.builder(ClassName.bestGuess("org.springframework.stereotype.Component"));
             builder.addAnnotation(springAnnotation.build());
         }
-        TypeSpec generatedRouteBuilder = builder.build();
+        final TypeSpec generatedRouteBuilder = builder.build();
 
-        final String packageNameToUse = packageNameGenerator.apply(openapi);
+        final String packageNameToUse = packageNameGenerator.apply(document);
 
         return JavaFile.builder(packageNameToUse, generatedRouteBuilder).indent(indent).build();
     }
@@ -155,8 +155,8 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return this;
     }
 
-    static String generateClassName(final OasDocument openapi) {
-        final OasInfo info = (OasInfo)openapi.info;
+    static String generateClassName(final OasDocument document) {
+        final OasInfo info = (OasInfo) document.info;
         if (info == null) {
             return DEFAULT_CLASS_NAME;
         }
@@ -177,9 +177,8 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return className;
     }
 
-    static String generatePackageName(final OasDocument openapi) {
-        String host = RestDslGenerator.getHostFromOasDocument(openapi);
-        
+    static String generatePackageName(final OasDocument document) {
+        final String host = RestDslGenerator.determineHostFrom(document);
 
         if (ObjectHelper.isNotEmpty(host)) {
             final StringBuilder packageName = new StringBuilder();
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslXmlGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslXmlGenerator.java
index a1ce847..a0a4718 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslXmlGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslXmlGenerator.java
@@ -43,20 +43,20 @@ public class RestDslXmlGenerator extends RestDslGenerator<RestDslXmlGenerator> {
 
     private boolean blueprint;
 
-    RestDslXmlGenerator(final OasDocument openapi) {
-        super(openapi);
+    RestDslXmlGenerator(final OasDocument document) {
+        super(document);
     }
 
     public String generate(final CamelContext context) throws Exception {
         final RestDefinitionEmitter emitter = new RestDefinitionEmitter(context);
-        String basePath = RestDslGenerator.getBasePathFromOasDocument(openapi);
+        final String basePath = RestDslGenerator.determineBasePathFrom(document);
         final PathVisitor<RestsDefinition> restDslStatement = new PathVisitor<>(basePath, emitter, filter,
             destinationGenerator());
 
-        openapi.paths.getPathItems().forEach(restDslStatement::visit);
+        document.paths.getPathItems().forEach(restDslStatement::visit);
 
         final RestsDefinition rests = emitter.result();
-        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+        final ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
         final String xml = ecc.getModelToXMLDumper().dumpModelAsXml(context, rests);
 
         final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/SpringBootProjectSourceCodeGenerator.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/SpringBootProjectSourceCodeGenerator.java
index dfd2604..4cf536d 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/SpringBootProjectSourceCodeGenerator.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/SpringBootProjectSourceCodeGenerator.java
@@ -39,7 +39,7 @@ public class SpringBootProjectSourceCodeGenerator {
 
     private String packageName;
 
-    public void generate(Path destination) throws IOException {
+    public void generate(final Path destination) throws IOException {
         final JavaFile javaFile = generateSourceCode();
 
         javaFile.writeTo(destination);
@@ -56,30 +56,9 @@ public class SpringBootProjectSourceCodeGenerator {
         return this;
     }
 
-    JavaFile generateSourceCode() {
-        notEmpty(packageName, "packageName");
-
-        final MethodSpec methodSpec = generateRestMethod();
-
-        final String classNameToUse = "CamelRestController";
-
-        final AnnotationSpec.Builder generatedAnnotation = AnnotationSpec.builder(Generated.class).addMember("value",
-            "$S", getClass().getName());
-        final AnnotationSpec.Builder restAnnotation = AnnotationSpec.builder(ClassName.bestGuess("org.springframework.web.bind.annotation.RestController"));
-
-        TypeSpec.Builder builder = TypeSpec.classBuilder(classNameToUse)
-            .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(methodSpec)
-            .addAnnotation(generatedAnnotation.build())
-            .addAnnotation(restAnnotation.build())
-            .addJavadoc("Forward requests to the Camel servlet so it can service REST requests.\n");
-        TypeSpec generatedRestController = builder.build();
-
-        return JavaFile.builder(packageName, generatedRestController).indent(indent).build();
-    }
-
     MethodSpec generateRestMethod() {
-        ClassName req = ClassName.bestGuess("javax.servlet.http.HttpServletRequest");
-        ClassName res = ClassName.bestGuess("javax.servlet.http.HttpServletResponse");
+        final ClassName req = ClassName.bestGuess("javax.servlet.http.HttpServletRequest");
+        final ClassName res = ClassName.bestGuess("javax.servlet.http.HttpServletResponse");
 
         final AnnotationSpec.Builder reqAnnotation = AnnotationSpec.builder(ClassName.bestGuess("org.springframework.web.bind.annotation.RequestMapping"))
             .addMember("value", "\"/**\"");
@@ -100,6 +79,27 @@ public class SpringBootProjectSourceCodeGenerator {
         return forward.build();
     }
 
+    JavaFile generateSourceCode() {
+        notEmpty(packageName, "packageName");
+
+        final MethodSpec methodSpec = generateRestMethod();
+
+        final String classNameToUse = "CamelRestController";
+
+        final AnnotationSpec.Builder generatedAnnotation = AnnotationSpec.builder(Generated.class).addMember("value",
+            "$S", getClass().getName());
+        final AnnotationSpec.Builder restAnnotation = AnnotationSpec.builder(ClassName.bestGuess("org.springframework.web.bind.annotation.RestController"));
+
+        final TypeSpec.Builder builder = TypeSpec.classBuilder(classNameToUse)
+            .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(methodSpec)
+            .addAnnotation(generatedAnnotation.build())
+            .addAnnotation(restAnnotation.build())
+            .addJavadoc("Forward requests to the Camel servlet so it can service REST requests.\n");
+        final TypeSpec generatedRestController = builder.build();
+
+        return JavaFile.builder(packageName, generatedRestController).indent(indent).build();
+    }
+
     public static SpringBootProjectSourceCodeGenerator generator() {
         return new SpringBootProjectSourceCodeGenerator();
     }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/PathSpringBootProjectSourceGeneratorTest.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/PathSpringBootProjectSourceGeneratorTest.java
index e7d6a46..3c3e973 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/PathSpringBootProjectSourceGeneratorTest.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/PathSpringBootProjectSourceGeneratorTest.java
@@ -33,9 +33,10 @@ public class PathSpringBootProjectSourceGeneratorTest {
 
     @Test
     public void shouldGenerateSourceCodeWithDefaults() throws IOException, URISyntaxException {
-        Path path = new File("target/generated-sources").toPath();
+        final Path path = new File("target/generated-sources").toPath();
         SpringBootProjectSourceCodeGenerator.generator().withPackageName("com.foo").generate(path);
-        final String generatedContent = new String(Files.readAllBytes(Paths.get("target/generated-sources/com/foo/CamelRestController.java")), StandardCharsets.UTF_8);
+        final String generatedContent = new String(Files.readAllBytes(Paths.get("target/generated-sources/com/foo/CamelRestController.java")),
+            StandardCharsets.UTF_8);
 
         final URI file = PathSpringBootProjectSourceGeneratorTest.class.getResource("/SpringBootRestController.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDefinitionEmitterTest.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDefinitionEmitterTest.java
index 132c218..a863bb9 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDefinitionEmitterTest.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDefinitionEmitterTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.generator.openapi;
 
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.camel.impl.DefaultCamelContext;
@@ -30,41 +31,42 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestDefinitionEmitterTest {
     @Test
-    public void shouldGenerateObjects() {
-        final DefaultCamelContext context = new DefaultCamelContext();
+    public void shouldGenerateObjects() throws IOException {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
 
-        final RestDefinitionEmitter emitter = new RestDefinitionEmitter(context);
+            final RestDefinitionEmitter emitter = new RestDefinitionEmitter(context);
 
-        emitter.emit("rest");
-        emitter.emit("put", "/pet");
-        emitter.emit("consumes", new Object[] {new String[] {"application/json", "application/xml"}});
-        emitter.emit("produces", new Object[] {new String[] {"application/xml", "application/json"}});
-        emitter.emit("param");
-        emitter.emit("name", "body");
-        emitter.emit("type", RestParamType.body);
-        emitter.emit("required", true);
-        emitter.emit("endParam");
+            emitter.emit("rest");
+            emitter.emit("put", "/pet");
+            emitter.emit("consumes", new Object[] {new String[] {"application/json", "application/xml"}});
+            emitter.emit("produces", new Object[] {new String[] {"application/xml", "application/json"}});
+            emitter.emit("param");
+            emitter.emit("name", "body");
+            emitter.emit("type", RestParamType.body);
+            emitter.emit("required", true);
+            emitter.emit("endParam");
 
-        final RestsDefinition result = emitter.result();
-        final List<RestDefinition> rests = result.getRests();
-        assertThat(rests).hasSize(1);
+            final RestsDefinition result = emitter.result();
+            final List<RestDefinition> rests = result.getRests();
+            assertThat(rests).hasSize(1);
 
-        final RestDefinition rest = rests.get(0);
-        final List<VerbDefinition> verbs = rest.getVerbs();
-        assertThat(verbs).hasSize(1);
+            final RestDefinition rest = rests.get(0);
+            final List<VerbDefinition> verbs = rest.getVerbs();
+            assertThat(verbs).hasSize(1);
 
-        final VerbDefinition definition = verbs.get(0);
-        assertThat(definition.asVerb()).isEqualTo("put");
-        assertThat(definition.getUri()).isEqualTo("/pet");
-        assertThat(definition.getConsumes()).isEqualTo("application/json,application/xml");
-        assertThat(definition.getProduces()).isEqualTo("application/xml,application/json");
+            final VerbDefinition definition = verbs.get(0);
+            assertThat(definition.asVerb()).isEqualTo("put");
+            assertThat(definition.getUri()).isEqualTo("/pet");
+            assertThat(definition.getConsumes()).isEqualTo("application/json,application/xml");
+            assertThat(definition.getProduces()).isEqualTo("application/xml,application/json");
 
-        final List<RestOperationParamDefinition> params = definition.getParams();
-        assertThat(params).hasSize(1);
+            final List<RestOperationParamDefinition> params = definition.getParams();
+            assertThat(params).hasSize(1);
 
-        final RestOperationParamDefinition param = params.get(0);
-        assertThat(param.getName()).isEqualTo("body");
-        assertThat(param.getType()).isEqualTo(RestParamType.body);
-        assertThat(param.getRequired()).isEqualTo(true);
+            final RestOperationParamDefinition param = params.get(0);
+            assertThat(param.getName()).isEqualTo("body");
+            assertThat(param.getType()).isEqualTo(RestParamType.body);
+            assertThat(param.getRequired()).isEqualTo(true);
+        }
     }
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorTest.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorTest.java
index 9dcde26..1b84880 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorTest.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorTest.java
@@ -16,20 +16,24 @@
  */
 package org.apache.camel.generator.openapi;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.time.Instant;
+import java.util.Collections;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import io.apicurio.datamodels.Library;
 import io.apicurio.datamodels.openapi.models.OasDocument;
+import io.apicurio.datamodels.openapi.v2.models.Oas20Document;
+import io.apicurio.datamodels.openapi.v3.models.Oas30Document;
+import io.apicurio.datamodels.openapi.v3.models.Oas30Server;
+import io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable;
 import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.model.rest.RestsDefinition;
@@ -40,36 +44,74 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestDslGeneratorTest {
 
-    static OasDocument openapi;
-    
+    static OasDocument document;
+
     final Instant generated = Instant.parse("2017-10-17T00:00:00.000Z");
 
-       
-    @BeforeClass
-    public static void readOpenApiDoc() throws Exception {
-        ObjectMapper mapper = new ObjectMapper();
-        FileInputStream fis = new FileInputStream(new File("openapi-v2.json"));
-        JsonNode node = mapper.readTree(fis);
-        openapi = (OasDocument)Library.readDocument(node);
+    @Test
+    public void shouldCreateDefinitions() throws IOException {
+        try (CamelContext context = new DefaultCamelContext()) {
+            final RestsDefinition definition = RestDslGenerator.toDefinition(document).generate(context);
+            assertThat(definition).isNotNull();
+            assertThat(definition.getRests()).hasSize(1);
+            assertThat(definition.getRests().get(0).getPath()).isEqualTo("/v2");
+        }
+    }
+
+    @Test
+    public void shouldDetermineBasePathFromV2Document() {
+        final Oas20Document oas20Document = new Oas20Document();
+        oas20Document.basePath = "/api";
+        assertThat(RestDslGenerator.determineBasePathFrom(oas20Document)).isEqualTo("/api");
     }
 
     @Test
-    public void shouldCreateDefinitions() {
-        final CamelContext context = new DefaultCamelContext();
+    public void shouldDetermineBasePathFromV3DocumentsServerUrl() {
+        final Oas30Document oas30Document = new Oas30Document();
+        final Oas30Server server = new Oas30Server();
+        server.url = "https://example.com/api";
 
-        final RestsDefinition definition = RestDslGenerator.toDefinition(openapi).generate(context);
-        assertThat(definition).isNotNull();
-        assertThat(definition.getRests()).hasSize(1);
-        assertThat(definition.getRests().get(0).getPath()).isEqualTo("/v2");
-               
-       
+        oas30Document.servers = Collections.singletonList(server);
+        assertThat(RestDslGenerator.determineBasePathFrom(oas30Document)).isEqualTo("/api");
+    }
+
+    @Test
+    public void shouldDetermineBasePathFromV3DocumentsServerUrlWithTemplateVariables() {
+        final Oas30Document oas30Document = new Oas30Document();
+        final Oas30Server server = new Oas30Server();
+        addVariableTo(server, "base", "api");
+        addVariableTo(server, "path", "v3");
+        server.url = "https://example.com/{base}/{path}";
+
+        oas30Document.servers = Collections.singletonList(server);
+        assertThat(RestDslGenerator.determineBasePathFrom(oas30Document)).isEqualTo("/api/v3");
+    }
+
+    @Test
+    public void shouldDetermineBasePathFromV3DocumentsWhenServerUrlIsRelative() {
+        final Oas30Document oas30Document = new Oas30Document();
+        final Oas30Server server = new Oas30Server();
+        server.url = "/api/v3";
+
+        oas30Document.servers = Collections.singletonList(server);
+        assertThat(RestDslGenerator.determineBasePathFrom(oas30Document)).isEqualTo("/api/v3");
+    }
+
+    @Test
+    public void shouldDetermineBasePathFromV3DocumentsWhenServerUrlIsRelativeWithoutStartingSlash() {
+        final Oas30Document oas30Document = new Oas30Document();
+        final Oas30Server server = new Oas30Server();
+        server.url = "api/v3";
+
+        oas30Document.servers = Collections.singletonList(server);
+        assertThat(RestDslGenerator.determineBasePathFrom(oas30Document)).isEqualTo("/api/v3");
     }
 
     @Test
     public void shouldGenerateSourceCodeWithDefaults() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).generate(code);
+        RestDslGenerator.toAppendable(document).withGeneratedTime(generated).generate(code);
 
         final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstore.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
@@ -78,12 +120,20 @@ public class RestDslGeneratorTest {
     }
 
     @Test
-    public void shouldGenerateSourceCodeWithRestComponent() throws IOException, URISyntaxException {
+    public void shouldGenerateSourceCodeWithFilter() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).withRestComponent("servlet").withRestContextPath("/").generate(code);
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .withClassName("MyRestRoute")
+            .withPackageName("com.example")
+            .withIndent("\t")
+            .withSourceCodeTimestamps()
+            .withOperationFilter("find*,deletePet,updatePet")
+            .withDestinationGenerator(o -> "direct:rest-" + o.operationId)
+            .generate(code);
 
-        final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstoreWithRestComponent.txt").toURI();
+        final URI file = RestDslGeneratorTest.class.getResource("/MyRestRouteFilter.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
         assertThat(code.toString()).isEqualTo(expectedContent);
@@ -93,8 +143,12 @@ public class RestDslGeneratorTest {
     public void shouldGenerateSourceCodeWithOptions() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).withClassName("MyRestRoute")
-            .withPackageName("com.example").withIndent("\t").withSourceCodeTimestamps()
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .withClassName("MyRestRoute")
+            .withPackageName("com.example")
+            .withIndent("\t")
+            .withSourceCodeTimestamps()
             .withDestinationGenerator(o -> "direct:rest-" + o.operationId).generate(code);
 
         final URI file = RestDslGeneratorTest.class.getResource("/MyRestRoute.txt").toURI();
@@ -104,17 +158,64 @@ public class RestDslGeneratorTest {
     }
 
     @Test
-    public void shouldGenerateSourceCodeWithFilter() throws IOException, URISyntaxException {
+    public void shouldGenerateSourceCodeWithRestComponent() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).withClassName("MyRestRoute")
-            .withPackageName("com.example").withIndent("\t").withSourceCodeTimestamps()
-            .withOperationFilter("find*,deletePet,updatePet")
-            .withDestinationGenerator(o -> "direct:rest-" + o.operationId).generate(code);
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .withRestComponent("servlet")
+            .withRestContextPath("/")
+            .generate(code);
 
-        final URI file = RestDslGeneratorTest.class.getResource("/MyRestRouteFilter.txt").toURI();
+        final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstoreWithRestComponent.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
         assertThat(code.toString()).isEqualTo(expectedContent);
     }
+
+    @Test
+    public void shouldResolveEmptyVariables() {
+        assertThat(RestDslGenerator.resolveVariablesIn("", new Oas30Server())).isEmpty();
+    }
+
+    @Test
+    public void shouldResolveMultipleOccurancesOfVariables() {
+        final Oas30Server server = new Oas30Server();
+        addVariableTo(server, "var1", "value1");
+        addVariableTo(server, "var2", "value2");
+
+        assertThat(RestDslGenerator.resolveVariablesIn("{var2} before {var1} after {var2}", server)).isEqualTo("value2 before value1 after value2");
+    }
+
+    @Test
+    public void shouldResolveMultipleVariables() {
+        final Oas30Server server = new Oas30Server();
+        addVariableTo(server, "var1", "value1");
+        addVariableTo(server, "var2", "value2");
+
+        assertThat(RestDslGenerator.resolveVariablesIn("before {var1} after {var2}", server)).isEqualTo("before value1 after value2");
+    }
+
+    @Test
+    public void shouldResolveSingleVariable() {
+        final Oas30Server server = new Oas30Server();
+        addVariableTo(server, "var", "value");
+        assertThat(RestDslGenerator.resolveVariablesIn("before {var} after", server)).isEqualTo("before value after");
+    }
+
+    @BeforeClass
+    public static void readOpenApiDoc() throws Exception {
+        final ObjectMapper mapper = new ObjectMapper();
+        try (InputStream is = RestDslGeneratorTest.class.getResourceAsStream("openapi-v2.json")) {
+            final JsonNode node = mapper.readTree(is);
+            document = (OasDocument) Library.readDocument(node);
+        }
+    }
+
+    private static void addVariableTo(final Oas30Server server, final String name, final String value) {
+        final Oas30ServerVariable variable = new Oas30ServerVariable(name);
+        variable.default_ = value;
+
+        server.addServerVariable(name, variable);
+    }
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorV3Test.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorV3Test.java
index 645d0ad..6908cee 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorV3Test.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslGeneratorV3Test.java
@@ -16,9 +16,8 @@
  */
 package org.apache.camel.generator.openapi;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
@@ -40,50 +39,50 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestDslGeneratorV3Test {
 
-    static OasDocument openapi;
-    
-    final Instant generated = Instant.parse("2017-10-17T00:00:00.000Z");
+    static OasDocument document;
 
-       
-    @BeforeClass
-    public static void readOpenApiDoc() throws Exception {
-        ObjectMapper mapper = new ObjectMapper();
-        FileInputStream fis = new FileInputStream(new File("openapi-spec.json"));
-        JsonNode node = mapper.readTree(fis);
-        openapi = (OasDocument)Library.readDocument(node);
-    }
+    final Instant generated = Instant.parse("2017-10-17T00:00:00.000Z");
 
     @Test
-    public void shouldCreateDefinitions() {
-        final CamelContext context = new DefaultCamelContext();
-        final RestsDefinition definition = RestDslGenerator.toDefinition(openapi).generate(context);
-        assertThat(definition).isNotNull();
-        assertThat(definition.getRests()).hasSize(1);
-        assertThat(definition.getRests().get(0).getPath()).isEqualTo("/api/v3");
-        
+    public void shouldCreateDefinitions() throws IOException {
+        try (CamelContext context = new DefaultCamelContext()) {
+            final RestsDefinition definition = RestDslGenerator.toDefinition(document).generate(context);
+            assertThat(definition).isNotNull();
+            assertThat(definition.getRests()).hasSize(1);
+            assertThat(definition.getRests().get(0).getPath()).isEqualTo("/api/v3");
+        }
     }
 
     @Test
     public void shouldGenerateSourceCodeWithDefaults() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).generate(code);
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .generate(code);
 
         final URI file = RestDslGeneratorV3Test.class.getResource("/OpenApiV3Petstore.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
         assertThat(code.toString()).isEqualTo(expectedContent);
-        
+
     }
 
     @Test
-    public void shouldGenerateSourceCodeWithRestComponent() throws IOException, URISyntaxException {
+    public void shouldGenerateSourceCodeWithFilter() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).withRestComponent("servlet").withRestContextPath("/").generate(code);
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .withClassName("MyRestRoute")
+            .withPackageName("com.example")
+            .withIndent("\t")
+            .withSourceCodeTimestamps()
+            .withOperationFilter("find*,deletePet,updatePet")
+            .withDestinationGenerator(o -> "direct:rest-" + o.operationId)
+            .generate(code);
 
-        final URI file = RestDslGeneratorV3Test.class.getResource("/OpenApiV3PetstoreWithRestComponent.txt").toURI();
+        final URI file = RestDslGeneratorV3Test.class.getResource("/MyRestRouteFilterV3.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
-        
         assertThat(code.toString()).isEqualTo(expectedContent);
     }
 
@@ -91,9 +90,14 @@ public class RestDslGeneratorV3Test {
     public void shouldGenerateSourceCodeWithOptions() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).withClassName("MyRestRoute")
-            .withPackageName("com.example").withIndent("\t").withSourceCodeTimestamps()
-            .withDestinationGenerator(o -> "direct:rest-" + o.operationId).generate(code);
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .withClassName("MyRestRoute")
+            .withPackageName("com.example")
+            .withIndent("\t")
+            .withSourceCodeTimestamps()
+            .withDestinationGenerator(o -> "direct:rest-" + o.operationId)
+            .generate(code);
 
         final URI file = RestDslGeneratorV3Test.class.getResource("/MyRestRouteV3.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
@@ -101,16 +105,27 @@ public class RestDslGeneratorV3Test {
     }
 
     @Test
-    public void shouldGenerateSourceCodeWithFilter() throws IOException, URISyntaxException {
+    public void shouldGenerateSourceCodeWithRestComponent() throws IOException, URISyntaxException {
         final StringBuilder code = new StringBuilder();
 
-        RestDslGenerator.toAppendable(openapi).withGeneratedTime(generated).withClassName("MyRestRoute")
-            .withPackageName("com.example").withIndent("\t").withSourceCodeTimestamps()
-            .withOperationFilter("find*,deletePet,updatePet")
-            .withDestinationGenerator(o -> "direct:rest-" + o.operationId).generate(code);
+        RestDslGenerator.toAppendable(document)
+            .withGeneratedTime(generated)
+            .withRestComponent("servlet")
+            .withRestContextPath("/")
+            .generate(code);
 
-        final URI file = RestDslGeneratorV3Test.class.getResource("/MyRestRouteFilterV3.txt").toURI();
+        final URI file = RestDslGeneratorV3Test.class.getResource("/OpenApiV3PetstoreWithRestComponent.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
+
         assertThat(code.toString()).isEqualTo(expectedContent);
     }
+
+    @BeforeClass
+    public static void readOpenApiDoc() throws Exception {
+        final ObjectMapper mapper = new ObjectMapper();
+        try (InputStream is = RestDslGeneratorTest.class.getResourceAsStream("openapi-spec.json")) {
+            final JsonNode node = mapper.readTree(is);
+            document = (OasDocument) Library.readDocument(node);
+        }
+    }
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorTest.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorTest.java
index 77530cc..d2ba094 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorTest.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorTest.java
@@ -44,7 +44,7 @@ public class RestDslSourceCodeGeneratorTest {
     @Test
     public void shouldGenerateClassNameFromTitle() {
         final Oas20Document openapi = new Oas20Document();
-        OasInfo info = new Oas20Info();
+        final OasInfo info = new Oas20Info();
         info.title = "Example API";
         openapi.info = info;
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi)).isEqualTo("ExampleAPI");
@@ -53,7 +53,7 @@ public class RestDslSourceCodeGeneratorTest {
     @Test
     public void shouldGenerateClassNameFromTitleWithNonValidJavaIdentifiers() {
         final Oas20Document openapi = new Oas20Document();
-        OasInfo info = new Oas20Info();
+        final OasInfo info = new Oas20Info();
         info.title = "Example-API 2.0";
         openapi.info = info;
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi)).isEqualTo("ExampleAPI20");
@@ -65,6 +65,7 @@ public class RestDslSourceCodeGeneratorTest {
 
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_CLASS_NAME);
+
         openapi.info = new Oas20Info();
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_CLASS_NAME);
@@ -73,10 +74,10 @@ public class RestDslSourceCodeGeneratorTest {
     @Test
     public void shouldUseDefaultClassNameIfTitleContainsOnlyNonValidJavaIdentifiers() {
         final Oas20Document openapi = new Oas20Document();
-        OasInfo info = new Oas20Info();
+        final OasInfo info = new Oas20Info();
         info.title = "\\%/4";
         openapi.info = info;
-       
+
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_CLASS_NAME);
     }
@@ -85,7 +86,7 @@ public class RestDslSourceCodeGeneratorTest {
     public void shouldUseDefaultPackageNameForLocalhost() {
         final Oas20Document openapi = new Oas20Document();
         openapi.host = "localhost";
-        
+
         assertThat(RestDslSourceCodeGenerator.generatePackageName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_PACKAGE_NAME);
     }
@@ -94,7 +95,7 @@ public class RestDslSourceCodeGeneratorTest {
     public void shouldUseDefaultPackageNameForLocalhostWithPort() {
         final Oas20Document openapi = new Oas20Document();
         openapi.host = "localhost:8080";
-        
+
         assertThat(RestDslSourceCodeGenerator.generatePackageName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_PACKAGE_NAME);
     }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorV3Test.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorV3Test.java
index dee70d5..4b9707c 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorV3Test.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslSourceCodeGeneratorV3Test.java
@@ -29,7 +29,7 @@ public class RestDslSourceCodeGeneratorV3Test {
     public void shouldCreatePackageNamesFromHostnames() {
         final Oas30Document openapi = new Oas30Document();
         openapi.addServer("http://api.example.org/", "test server url");
-            
+
         assertThat(RestDslSourceCodeGenerator.generatePackageName(openapi)).isEqualTo("org.example.api");
     }
 
@@ -37,25 +37,27 @@ public class RestDslSourceCodeGeneratorV3Test {
     public void shouldCreatePackageNamesFromHostnamesWithPorts() {
         final Oas30Document openapi = new Oas30Document();
         openapi.addServer("http://api.example.org:8080/", "test server url");
-        
+
         assertThat(RestDslSourceCodeGenerator.generatePackageName(openapi)).isEqualTo("org.example.api");
     }
 
     @Test
     public void shouldGenerateClassNameFromTitle() {
         final Oas30Document openapi = new Oas30Document();
-        OasInfo info = new Oas30Info();
+        final OasInfo info = new Oas30Info();
         info.title = "Example API";
         openapi.info = info;
+
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi)).isEqualTo("ExampleAPI");
     }
 
     @Test
     public void shouldGenerateClassNameFromTitleWithNonValidJavaIdentifiers() {
         final Oas30Document openapi = new Oas30Document();
-        OasInfo info = new Oas30Info();
+        final OasInfo info = new Oas30Info();
         info.title = "Example-API 2.0";
         openapi.info = info;
+
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi)).isEqualTo("ExampleAPI20");
     }
 
@@ -65,6 +67,7 @@ public class RestDslSourceCodeGeneratorV3Test {
 
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_CLASS_NAME);
+
         openapi.info = new Oas30Info();
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_CLASS_NAME);
@@ -73,10 +76,10 @@ public class RestDslSourceCodeGeneratorV3Test {
     @Test
     public void shouldUseDefaultClassNameIfTitleContainsOnlyNonValidJavaIdentifiers() {
         final Oas30Document openapi = new Oas30Document();
-        OasInfo info = new Oas30Info();
+        final OasInfo info = new Oas30Info();
         info.title = "\\%/4";
         openapi.info = info;
-       
+
         assertThat(RestDslSourceCodeGenerator.generateClassName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_CLASS_NAME);
     }
@@ -85,7 +88,7 @@ public class RestDslSourceCodeGeneratorV3Test {
     public void shouldUseDefaultPackageNameForLocalhost() {
         final Oas30Document openapi = new Oas30Document();
         openapi.addServer("http://localhost", "test server url");
-                
+
         assertThat(RestDslSourceCodeGenerator.generatePackageName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_PACKAGE_NAME);
     }
@@ -94,7 +97,7 @@ public class RestDslSourceCodeGeneratorV3Test {
     public void shouldUseDefaultPackageNameForLocalhostWithPort() {
         final Oas30Document openapi = new Oas30Document();
         openapi.addServer("http://localhost:8080", "test server url");
-        
+
         assertThat(RestDslSourceCodeGenerator.generatePackageName(openapi))
             .isEqualTo(RestDslSourceCodeGenerator.DEFAULT_PACKAGE_NAME);
     }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorTest.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorTest.java
index 397b849..891d3db 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorTest.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorTest.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.generator.openapi;
 
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
 import java.io.StringReader;
 import java.net.URI;
 import java.nio.charset.StandardCharsets;
@@ -44,73 +43,74 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestDslXmlGeneratorTest {
 
-    static OasDocument openapi;
-    
-    @BeforeClass
-    public static void readOpenApiDoc() throws Exception {
-        ObjectMapper mapper = new ObjectMapper();
-        FileInputStream fis = new FileInputStream(new File("openapi-v2.json"));
-        JsonNode node = mapper.readTree(fis);
-        openapi = (OasDocument)Library.readDocument(node);
-    }
+    static OasDocument document;
 
     @Test
     public void shouldGenerateBlueprintXml() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
-
-        final String xml = RestDslGenerator.toXml(openapi).withBlueprint().generate(context);
-        assertThat(xml).isNotEmpty();
-        assertThat(xml.contains("http://camel.apache.org/schema/blueprint"));
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).withBlueprint().generate(context);
+            assertThat(xml).contains("http://camel.apache.org/schema/blueprint");
+        }
     }
 
     @Test
-    public void shouldGenerateXml() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
-
-        final String xml = RestDslGenerator.toXml(openapi).generate(context);
-        assertThat(xml).isNotEmpty();
-        assertThat(xml.contains("http://camel.apache.org/schema/spring"));
+    public void shouldGenerateSpringXml() throws Exception {
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).generate(context);
+            assertThat(xml).contains("http://camel.apache.org/schema/spring");
+        }
     }
 
     @Test
     public void shouldGenerateXmlWithDefaultnamespace() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).generate(context);
 
-        final String xml = RestDslGenerator.toXml(openapi).generate(context);
+            final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+            builderFactory.setNamespaceAware(true);
 
-        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-        builderFactory.setNamespaceAware(true);
+            final DocumentBuilder builder = builderFactory.newDocumentBuilder();
 
-        final DocumentBuilder builder = builderFactory.newDocumentBuilder();
+            final Document document = builder.parse(new InputSource(new StringReader(xml)));
 
-        final Document document = builder.parse(new InputSource(new StringReader(xml)));
-
-        assertThat(document.isDefaultNamespace("http://camel.apache.org/schema/spring")).isTrue();
+            assertThat(document.isDefaultNamespace("http://camel.apache.org/schema/spring")).isTrue();
+        }
     }
 
     @Test
     public void shouldGenerateXmlWithDefaults() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
-
-        final String xml = RestDslGenerator.toXml(openapi).generate(context);
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).generate(context);
 
-        final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstoreXml.txt").toURI();
-        final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
+            final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstoreXml.txt").toURI();
+            final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
-        assertThat(xml).isXmlEqualTo(expectedContent);
+            assertThat(xml).isXmlEqualTo(expectedContent);
+        }
     }
 
     @Test
     public void shouldGenerateXmlWithRestComponent() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document)
+                .withRestComponent("servlet")
+                .withRestContextPath("/foo")
+                .generate(context);
 
-        final String xml = RestDslGenerator.toXml(openapi).withRestComponent("servlet").withRestContextPath("/foo")
-            .generate(context);
+            final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstoreWithRestComponentXml.txt").toURI();
+            final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
-        final URI file = RestDslGeneratorTest.class.getResource("/OpenApiPetstoreWithRestComponentXml.txt").toURI();
-        final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
+            assertThat(xml).isXmlEqualTo(expectedContent);
+        }
+    }
 
-        assertThat(xml).isXmlEqualTo(expectedContent);
+    @BeforeClass
+    public static void readOpenApiDoc() throws Exception {
+        final ObjectMapper mapper = new ObjectMapper();
+        try (InputStream is = RestDslXmlGeneratorTest.class.getResourceAsStream("openapi-v2.json")) {
+            final JsonNode node = mapper.readTree(is);
+            document = (OasDocument) Library.readDocument(node);
+        }
     }
 
 }
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorV3Test.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorV3Test.java
index c3fa886..1a187ed 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorV3Test.java
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/RestDslXmlGeneratorV3Test.java
@@ -16,8 +16,7 @@
  */
 package org.apache.camel.generator.openapi;
 
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
 import java.io.StringReader;
 import java.net.URI;
 import java.nio.charset.StandardCharsets;
@@ -44,72 +43,73 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RestDslXmlGeneratorV3Test {
 
-    static OasDocument openapi;
-    
-    @BeforeClass
-    public static void readOpenApiDoc() throws Exception {
-        ObjectMapper mapper = new ObjectMapper();
-        FileInputStream fis = new FileInputStream(new File("openapi-spec.json"));
-        JsonNode node = mapper.readTree(fis);
-        openapi = (OasDocument)Library.readDocument(node);
-    }
+    static OasDocument document;
 
     @Test
     public void shouldGenerateBlueprintXml() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
-
-        final String xml = RestDslGenerator.toXml(openapi).withBlueprint().generate(context);
-        assertThat(xml).isNotEmpty();
-        assertThat(xml.contains("http://camel.apache.org/schema/blueprint"));
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).withBlueprint().generate(context);
+            assertThat(xml).contains("http://camel.apache.org/schema/blueprint");
+        }
     }
 
     @Test
-    public void shouldGenerateXml() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
-
-        final String xml = RestDslGenerator.toXml(openapi).generate(context);
-        assertThat(xml).isNotEmpty();
-        assertThat(xml.contains("http://camel.apache.org/schema/spring"));
+    public void shouldGenerateSpringXml() throws Exception {
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).generate(context);
+            assertThat(xml).contains("http://camel.apache.org/schema/spring");
+        }
     }
 
     @Test
     public void shouldGenerateXmlWithDefaultnamespace() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).generate(context);
 
-        final String xml = RestDslGenerator.toXml(openapi).generate(context);
+            final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+            builderFactory.setNamespaceAware(true);
 
-        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-        builderFactory.setNamespaceAware(true);
+            final DocumentBuilder builder = builderFactory.newDocumentBuilder();
 
-        final DocumentBuilder builder = builderFactory.newDocumentBuilder();
+            final Document document = builder.parse(new InputSource(new StringReader(xml)));
 
-        final Document document = builder.parse(new InputSource(new StringReader(xml)));
-
-        assertThat(document.isDefaultNamespace("http://camel.apache.org/schema/spring")).isTrue();
+            assertThat(document.isDefaultNamespace("http://camel.apache.org/schema/spring")).isTrue();
+        }
     }
 
     @Test
     public void shouldGenerateXmlWithDefaults() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document).generate(context);
 
-        final String xml = RestDslGenerator.toXml(openapi).generate(context);
+            final URI file = RestDslGeneratorTest.class.getResource("/OpenApiV3PetstoreXml.txt").toURI();
+            final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
-        final URI file = RestDslGeneratorTest.class.getResource("/OpenApiV3PetstoreXml.txt").toURI();
-        final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
-        
-        assertThat(xml).isXmlEqualTo(expectedContent);
+            assertThat(xml).isXmlEqualTo(expectedContent);
+        }
     }
 
     @Test
     public void shouldGenerateXmlWithRestComponent() throws Exception {
-        final CamelContext context = new DefaultCamelContext();
-
-        final String xml = RestDslGenerator.toXml(openapi).withRestComponent("servlet").withRestContextPath("/foo")
-            .generate(context);
+        try (CamelContext context = new DefaultCamelContext()) {
+            final String xml = RestDslGenerator.toXml(document)
+                .withRestComponent("servlet")
+                .withRestContextPath("/foo")
+                .generate(context);
+
+            final URI file = RestDslGeneratorTest.class.getResource("/OpenApiV3PetstoreWithRestComponentXml.txt").toURI();
+            final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
+            assertThat(xml).isXmlEqualTo(expectedContent);
+        }
+    }
 
-        final URI file = RestDslGeneratorTest.class.getResource("/OpenApiV3PetstoreWithRestComponentXml.txt").toURI();
-        final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
-        assertThat(xml).isXmlEqualTo(expectedContent);
+    @BeforeClass
+    public static void readOpenApiDoc() throws Exception {
+        final ObjectMapper mapper = new ObjectMapper();
+        try (InputStream is = RestDslXmlGeneratorV3Test.class.getResourceAsStream("openapi-spec.json")) {
+            final JsonNode node = mapper.readTree(is);
+            document = (OasDocument) Library.readDocument(node);
+        }
     }
 
 }
diff --git a/tooling/openapi-rest-dsl-generator/openapi-spec.json b/tooling/openapi-rest-dsl-generator/src/test/resources/org/apache/camel/generator/openapi/openapi-spec.json
similarity index 100%
rename from tooling/openapi-rest-dsl-generator/openapi-spec.json
rename to tooling/openapi-rest-dsl-generator/src/test/resources/org/apache/camel/generator/openapi/openapi-spec.json
diff --git a/tooling/openapi-rest-dsl-generator/openapi-v2.json b/tooling/openapi-rest-dsl-generator/src/test/resources/org/apache/camel/generator/openapi/openapi-v2.json
similarity index 100%
rename from tooling/openapi-rest-dsl-generator/openapi-v2.json
rename to tooling/openapi-rest-dsl-generator/src/test/resources/org/apache/camel/generator/openapi/openapi-v2.json


[camel] 01/03: CAMEL-14691: Remove versions from pom.xml

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fe5c7a2a6dc2e1c4738da58091d16af25b5de5cb
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Tue Mar 10 22:40:53 2020 +0100

    CAMEL-14691: Remove versions from pom.xml
    
    This removes versions of managed dependencies in pom.xml
---
 tooling/openapi-rest-dsl-generator/pom.xml | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tooling/openapi-rest-dsl-generator/pom.xml b/tooling/openapi-rest-dsl-generator/pom.xml
index b67683e..24805f5 100644
--- a/tooling/openapi-rest-dsl-generator/pom.xml
+++ b/tooling/openapi-rest-dsl-generator/pom.xml
@@ -52,7 +52,6 @@
         <dependency>
             <groupId>io.apicurio</groupId>
             <artifactId>apicurio-data-models</artifactId>
-            <version>1.0.16.Final</version>
         </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
@@ -70,7 +69,6 @@
         <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
-            <version>${assertj-version}</version>
             <scope>test</scope>
         </dependency>
 


[camel] 03/03: CAMEL-14691: dereference parameters

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1070ac8e0d44d8093ec3f8a5aa06475fbd42dd36
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Tue Mar 10 23:47:13 2020 +0100

    CAMEL-14691: dereference parameters
    
    If parameters are references then we need to dereference them.
---
 .../camel/generator/openapi/OperationVisitor.java  |  38 +++--
 .../generator/openapi/OperationVisitorTest.java    | 163 +++++++++++++++++++++
 2 files changed, 185 insertions(+), 16 deletions(-)

diff --git a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java
index 98e7d82..1223aac 100644
--- a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java
+++ b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/OperationVisitor.java
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map.Entry;
 
+import io.apicurio.datamodels.core.util.ReferenceUtil;
 import io.apicurio.datamodels.openapi.models.OasOperation;
 import io.apicurio.datamodels.openapi.models.OasParameter;
 import io.apicurio.datamodels.openapi.models.OasResponse;
@@ -69,14 +70,20 @@ class OperationVisitor<T> {
 
     CodeEmitter<T> emit(final OasParameter parameter) {
         emitter.emit("param");
-        emit("name", parameter.getName());
-        final String parameterType = parameter.in;
+
+        OasParameter toUse = parameter;
+        if (ObjectHelper.isNotEmpty(parameter.$ref)) {
+            toUse = (OasParameter) ReferenceUtil.resolveRef(parameter.$ref, parameter);
+        }
+
+        emit("name", toUse.getName());
+        final String parameterType = toUse.in;
         if (ObjectHelper.isNotEmpty(parameterType)) {
             emit("type", RestParamType.valueOf(parameterType));
         }
-        if (!parameterType.equals("body")) {
-            if (parameter instanceof Oas20Parameter) {
-                final Oas20Parameter serializableParameter = (Oas20Parameter) parameter;
+        if (!"body".equals(parameterType)) {
+            if (toUse instanceof Oas20Parameter) {
+                final Oas20Parameter serializableParameter = (Oas20Parameter) toUse;
 
                 final String dataType = serializableParameter.type;
                 emit("dataType", dataType);
@@ -94,8 +101,8 @@ class OperationVisitor<T> {
                 if ("array".equals(dataType) && items != null) {
                     emit("arrayType", items.type);
                 }
-            } else if (parameter instanceof Oas30Parameter) {
-                final Oas30Parameter serializableParameter = (Oas30Parameter) parameter;
+            } else if (toUse instanceof Oas30Parameter) {
+                final Oas30Parameter serializableParameter = (Oas30Parameter) toUse;
                 final Oas30Schema schema = (Oas30Schema) serializableParameter.schema;
                 if (schema != null) {
                     final String dataType = schema.type;
@@ -103,9 +110,9 @@ class OperationVisitor<T> {
                         emit("dataType", dataType);
                     }
                     emit("allowableValues", asStringList(schema.enum_));
-                    final String collectionFormat = serializableParameter.style;
-                    if (ObjectHelper.isNotEmpty(collectionFormat)) {
-                        if (collectionFormat.equals("form")) {
+                    final String style = serializableParameter.style;
+                    if (ObjectHelper.isNotEmpty(style)) {
+                        if (style.equals("form")) {
                             if (serializableParameter.explode) {
                                 emit("collectionFormat", CollectionFormat.multi);
                             } else {
@@ -125,12 +132,12 @@ class OperationVisitor<T> {
                 }
             }
         }
-        if (parameter.required != null) {
-            emit("required", parameter.required);
+        if (toUse.required != null) {
+            emit("required", toUse.required);
         } else {
             emit("required", Boolean.FALSE);
         }
-        emit("description", parameter.description);
+        emit("description", toUse.description);
         emitter.emit("endParam");
 
         return emitter;
@@ -190,9 +197,7 @@ class OperationVisitor<T> {
             emit("produces", operationLevelProduces);
 
             if (operation.getParameters() != null) {
-                operation.getParameters().forEach(parameter -> {
-                    emit(parameter);
-                });
+                operation.getParameters().forEach(this::emit);
             }
             if (operation instanceof Oas30Operation) {
                 emitOas30Operation((Oas30Operation) operation);
@@ -200,6 +205,7 @@ class OperationVisitor<T> {
 
             emitter.emit("to", destinationGenerator.generateDestinationFor(operation));
         }
+
     }
 
     private CodeEmitter<T> emitOas30Operation(final Oas30Operation operation) {
diff --git a/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/OperationVisitorTest.java b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/OperationVisitorTest.java
new file mode 100644
index 0000000..ad904b7
--- /dev/null
+++ b/tooling/openapi-rest-dsl-generator/src/test/java/org/apache/camel/generator/openapi/OperationVisitorTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.generator.openapi;
+
+import java.util.Arrays;
+
+import com.squareup.javapoet.MethodSpec;
+import com.squareup.javapoet.MethodSpec.Builder;
+import io.apicurio.datamodels.openapi.v2.models.Oas20Parameter;
+import io.apicurio.datamodels.openapi.v3.models.Oas30Document;
+import io.apicurio.datamodels.openapi.v3.models.Oas30Parameter;
+import io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition;
+import io.apicurio.datamodels.openapi.v3.models.Oas30Schema;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class OperationVisitorTest {
+
+    @Test
+    public void shouldEmitCodeForOas2ParameterInQuery() {
+        final Builder method = MethodSpec.methodBuilder("configure");
+        final MethodBodySourceCodeEmitter emitter = new MethodBodySourceCodeEmitter(method);
+        final OperationVisitor<?> visitor = new OperationVisitor<>(emitter, null, null, null);
+
+        final Oas20Parameter parameter = new Oas20Parameter("param");
+        parameter.in = "query";
+
+        visitor.emit(parameter);
+
+        assertThat(method.build().toString()).isEqualTo("void configure() {\n"
+            + "      param()\n"
+            + "        .name(\"param\")\n"
+            + "        .type(org.apache.camel.model.rest.RestParamType.query)\n"
+            + "        .required(false)\n"
+            + "      .endParam()}\n");
+    }
+
+    @Test
+    public void shouldEmitCodeForOas3ParameterInPath() {
+        final Builder method = MethodSpec.methodBuilder("configure");
+        final MethodBodySourceCodeEmitter emitter = new MethodBodySourceCodeEmitter(method);
+        final OperationVisitor<?> visitor = new OperationVisitor<>(emitter, null, null, null);
+
+        final Oas30Parameter parameter = new Oas30Parameter("param");
+        parameter.in = "path";
+
+        visitor.emit(parameter);
+
+        assertThat(method.build().toString()).isEqualTo("void configure() {\n"
+            + "      param()\n"
+            + "        .name(\"param\")\n"
+            + "        .type(org.apache.camel.model.rest.RestParamType.path)\n"
+            + "        .required(false)\n"
+            + "      .endParam()}\n");
+    }
+
+    @Test
+    public void shouldEmitCodeForOas3ParameterWithDefaultValue() {
+        final Builder method = MethodSpec.methodBuilder("configure");
+        final MethodBodySourceCodeEmitter emitter = new MethodBodySourceCodeEmitter(method);
+        final OperationVisitor<?> visitor = new OperationVisitor<>(emitter, null, null, null);
+
+        final Oas30Parameter parameter = new Oas30Parameter("param");
+        parameter.in = "path";
+        parameter.schema = parameter.createSchema();
+        ((Oas30Schema) parameter.schema).default_ = "default";
+
+        visitor.emit(parameter);
+
+        assertThat(method.build().toString()).isEqualTo("void configure() {\n"
+            + "      param()\n"
+            + "        .name(\"param\")\n"
+            + "        .type(org.apache.camel.model.rest.RestParamType.path)\n"
+            + "        .defaultValue(\"default\")\n"
+            + "        .required(false)\n"
+            + "      .endParam()}\n");
+    }
+
+    @Test
+    public void shouldEmitCodeForOas3ParameterWithEnum() {
+        final Builder method = MethodSpec.methodBuilder("configure");
+        final MethodBodySourceCodeEmitter emitter = new MethodBodySourceCodeEmitter(method);
+        final OperationVisitor<?> visitor = new OperationVisitor<>(emitter, null, null, null);
+
+        final Oas30Parameter parameter = new Oas30Parameter("param");
+        parameter.in = "query";
+        parameter.schema = parameter.createSchema();
+        ((Oas30Schema) parameter.schema).enum_ = Arrays.asList("one", "two", "three");
+
+        visitor.emit(parameter);
+
+        assertThat(method.build().toString()).isEqualTo("void configure() {\n"
+            + "      param()\n"
+            + "        .name(\"param\")\n"
+            + "        .type(org.apache.camel.model.rest.RestParamType.query)\n"
+            + "        .allowableValues(\"one,two,three\")\n"
+            + "        .required(false)\n"
+            + "      .endParam()}\n");
+    }
+
+    @Test
+    public void shouldEmitCodeForOas3ParameterWithType() {
+        final Builder method = MethodSpec.methodBuilder("configure");
+        final MethodBodySourceCodeEmitter emitter = new MethodBodySourceCodeEmitter(method);
+        final OperationVisitor<?> visitor = new OperationVisitor<>(emitter, null, null, null);
+
+        final Oas30Parameter parameter = new Oas30Parameter("param");
+        parameter.in = "query";
+        parameter.schema = parameter.createSchema();
+        ((Oas30Schema) parameter.schema).type = "integer";
+
+        visitor.emit(parameter);
+
+        assertThat(method.build().toString()).isEqualTo("void configure() {\n"
+            + "      param()\n"
+            + "        .name(\"param\")\n"
+            + "        .type(org.apache.camel.model.rest.RestParamType.query)\n"
+            + "        .dataType(\"integer\")\n"
+            + "        .required(false)\n"
+            + "      .endParam()}\n");
+    }
+
+    @Test
+    public void shouldEmitCodeForOas3RefParameters() {
+        final Builder method = MethodSpec.methodBuilder("configure");
+        final MethodBodySourceCodeEmitter emitter = new MethodBodySourceCodeEmitter(method);
+        final OperationVisitor<?> visitor = new OperationVisitor<>(emitter, null, null, null);
+
+        final Oas30Document document = new Oas30Document();
+        document.components = document.createComponents();
+        final Oas30ParameterDefinition parameterDefinition = new Oas30ParameterDefinition("param");
+        parameterDefinition.in = "query";
+        document.components.addParameterDefinition("param", parameterDefinition);
+
+        final Oas30Parameter parameter = new Oas30Parameter();
+        parameter._ownerDocument = document;
+        parameter.$ref = "#/components/parameters/param";
+
+        visitor.emit(parameter);
+
+        assertThat(method.build().toString()).isEqualTo("void configure() {\n"
+            + "      param()\n"
+            + "        .name(\"param\")\n"
+            + "        .type(org.apache.camel.model.rest.RestParamType.query)\n"
+            + "        .required(false)\n"
+            + "      .endParam()}\n");
+    }
+}