camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] 05/05: CAMEL-12841: camel-restdsl-swagger:generate - Add restConfiguration with common defaults
Date Sun, 30 Sep 2018 15:23:51 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit e84bbddaf77856d5f2cbe356464320052d37e01b
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Sun Sep 30 17:19:48 2018 +0200

    CAMEL-12841: camel-restdsl-swagger:generate - Add restConfiguration with common defaults
---
 .../main/docs/camel-restdsl-swagger-plugin.adoc    | 28 ++++++++++++++++++++++
 .../maven/generator/swagger/GenerateMojo.java      |  4 ++++
 .../camel/generator/swagger/RestDslGenerator.java  | 10 ++++++++
 .../swagger/RestDslSourceCodeGenerator.java        | 11 ++++++---
 4 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/docs/camel-restdsl-swagger-plugin.adoc
b/tooling/maven/camel-restdsl-swagger-plugin/src/main/docs/camel-restdsl-swagger-plugin.adoc
index 30f691a..f8f3ded 100644
--- a/tooling/maven/camel-restdsl-swagger-plugin/src/main/docs/camel-restdsl-swagger-plugin.adoc
+++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/docs/camel-restdsl-swagger-plugin.adoc
@@ -16,6 +16,34 @@ The Camel REST DSL Swagger Maven Plugin supports the following goals
  XML source code from Swagger specification  and with DTO model
  classes generated via the swagger-codegen-maven-plugin.
 
+== Adding plugin to Maven pom.xml
+
+This plugin can be added to your Maven pom.xml file by adding it to the `<plugins>`
section,
+for example in a Spring Boot application:
+
+[source,xml]
+----
+<build>
+  <plugins>
+    <plugin>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-maven-plugin</artifactId>
+    </plugin>
+
+    <plugin>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-restdsl-swagger-plugin</artifactId>
+      <version>2.23.0</version>
+    </plugin>
+
+  </plugins>
+</build>
+----
+
+The plugin can then be executed via its prefix `camel-restdsl-swagger` as shown
+
+    $mvn camel-restdsl-swagger generate
+
 == camel-restdsl-swagger:generate
 
 The `camel-restdsl-swagger:generate` goal of the Camel REST DSL
diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateMojo.java
b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateMojo.java
index ef363fc..d8e62ed 100644
--- a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateMojo.java
+++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateMojo.java
@@ -115,6 +115,10 @@ public class GenerateMojo extends AbstractGenerateMojo {
             }
         }
 
+        if (detectSpringBootFromClasspath()) {
+            generator.asSpringComponent();
+        }
+
         final Path outputPath = new File(outputDirectory).toPath();
 
         try {
diff --git a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslGenerator.java
b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslGenerator.java
index df32d5f..cc21ec6 100644
--- a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslGenerator.java
+++ b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslGenerator.java
@@ -35,6 +35,7 @@ public abstract class RestDslGenerator<G> {
     DestinationGenerator destinationGenerator = new DirectToOperationId();
     OperationFilter filter = new OperationFilter();
     String restComponent;
+    boolean springComponent;
 
     RestDslGenerator(final Swagger swagger) {
         this.swagger = notNull(swagger, "swagger");
@@ -81,6 +82,15 @@ public abstract class RestDslGenerator<G> {
         return that;
     }
 
+    public G asSpringComponent() {
+        this.springComponent = true;
+
+        @SuppressWarnings("unchecked")
+        final G that = (G) this;
+
+        return that;
+    }
+
     public static RestDslSourceCodeGenerator<Appendable> toAppendable(final Swagger
swagger) {
         return new AppendableGenerator(swagger);
     }
diff --git a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
index 67150a2..c534e66 100644
--- a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
+++ b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
@@ -25,6 +25,7 @@ import javax.annotation.Generated;
 import javax.lang.model.element.Modifier;
 
 import com.squareup.javapoet.AnnotationSpec;
+import com.squareup.javapoet.ClassName;
 import com.squareup.javapoet.JavaFile;
 import com.squareup.javapoet.MethodSpec;
 import com.squareup.javapoet.TypeSpec;
@@ -123,15 +124,19 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
 
         final AnnotationSpec.Builder generatedAnnotation = AnnotationSpec.builder(Generated.class).addMember("value",
             "$S", getClass().getName());
-
         if (sourceCodeTimestamps) {
             generatedAnnotation.addMember("date", "$S", generated());
         }
 
-        final TypeSpec generatedRouteBuilder = TypeSpec.classBuilder(classNameToUse).superclass(RouteBuilder.class)
+        TypeSpec.Builder builder = TypeSpec.classBuilder(classNameToUse).superclass(RouteBuilder.class)
             .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(methodSpec)
             .addAnnotation(generatedAnnotation.build())
-            .addJavadoc("Generated from Swagger specification by Camel REST DSL generator.\n").build();
+            .addJavadoc("Generated from Swagger specification by Camel REST DSL generator.\n");
+        if (springComponent) {
+            final AnnotationSpec.Builder springAnnotation = AnnotationSpec.builder(ClassName.bestGuess("org.springframework.stereotype.Component"));
+            builder.addAnnotation(springAnnotation.build());
+        }
+        TypeSpec generatedRouteBuilder = builder.build();
 
         final String packageNameToUse = packageNameGenerator.apply(swagger);
 


Mime
View raw message