camel git commit: CAMEL-11163 Add @Generated annotation in REST D...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

camel git commit: CAMEL-11163 Add @Generated annotation in REST D...

zregvart
Repository: camel
Updated Branches:
  refs/heads/master 9cf875246 -> 30308c9f9


CAMEL-11163 Add @Generated annotation in REST D...

...SL Swagger generated code

This makes the `date` annotation member of `@Generated` annotation
optional and its generation turned off by default.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/30308c9f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/30308c9f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/30308c9f

Branch: refs/heads/master
Commit: 30308c9f9c453fb0731ca726a7821de839a4a1dd
Parents: 9cf8752
Author: Zoran Regvart <[hidden email]>
Authored: Wed Apr 19 10:47:43 2017 +0200
Committer: Zoran Regvart <[hidden email]>
Committed: Wed Apr 19 10:47:59 2017 +0200

----------------------------------------------------------------------
 .../swagger/RestDslSourceCodeGenerator.java     | 24 ++++++++++++++++++--
 .../generator/swagger/RestDslGeneratorTest.java |  2 +-
 .../src/test/resources/SwaggerPetstore.txt      |  5 +---
 3 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/30308c9f/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslSourceCodeGenerator.java
----------------------------------------------------------------------
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 bbc4b22..252bc40 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
@@ -52,6 +52,8 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
 
     private Function<Swagger, String> packageNameGenerator = RestDslSourceCodeGenerator::generatePackageName;
 
+    private boolean sourceCodeTimestamps;
+
     RestDslSourceCodeGenerator(final Swagger swagger) {
         super(swagger);
     }
@@ -71,6 +73,12 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return this;
     }
 
+    public RestDslSourceCodeGenerator<T> withoutSourceCodeTimestamps() {
+        sourceCodeTimestamps = false;
+
+        return this;
+    }
+
     public RestDslSourceCodeGenerator<T> withPackageName(final String packageName) {
         notEmpty(packageName, "packageName");
         this.packageNameGenerator = (s) -> packageName;
@@ -78,6 +86,12 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
         return this;
     }
 
+    public RestDslSourceCodeGenerator<T> withSourceCodeTimestamps() {
+        sourceCodeTimestamps = true;
+
+        return this;
+    }
+
     MethodSpec generateConfigureMethod(final Swagger swagger) {
         final MethodSpec.Builder configure = MethodSpec.methodBuilder("configure").addModifiers(Modifier.PUBLIC)
             .returns(void.class).addJavadoc("Defines Apache Camel routes using REST DSL fluent API.\n");
@@ -99,10 +113,16 @@ public abstract class RestDslSourceCodeGenerator<T> extends RestDslGenerator<Res
 
         final String classNameToUse = classNameGenerator.apply(swagger);
 
+        final AnnotationSpec.Builder generatedAnnotation = AnnotationSpec.builder(Generated.class).addMember("value",
+            "$S", getClass().getName());
+
+        if (sourceCodeTimestamps) {
+            generatedAnnotation.addMember("date", "$S", generated());
+        }
+
         final TypeSpec generatedRouteBulder = TypeSpec.classBuilder(classNameToUse).superclass(RouteBuilder.class)
             .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(methodSpec)
-            .addAnnotation(AnnotationSpec.builder(Generated.class).addMember("value", "$S", getClass().getName())
-                .addMember("date", "$S", generated()).build())
+            .addAnnotation(generatedAnnotation.build())
             .addJavadoc("Generated from Swagger specification by Camel REST DSL generator.\n").build();
 
         final String packageNameToUse = packageNameGenerator.apply(swagger);

http://git-wip-us.apache.org/repos/asf/camel/blob/30308c9f/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
----------------------------------------------------------------------
diff --git a/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java b/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
index 69aee57..ba0a553 100644
--- a/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
+++ b/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslGeneratorTest.java
@@ -66,7 +66,7 @@ public class RestDslGeneratorTest {
         final StringBuilder code = new StringBuilder();
 
         RestDslGenerator.toAppendable(swagger).withGeneratedTime(generated).withClassName("MyRestRoute")
-            .withPackageName("com.example").withIndent("\t")
+            .withPackageName("com.example").withIndent("\t").withSourceCodeTimestamps()
             .withDestinationGenerator(o -> "direct:rest-" + o.getOperationId()).generate(code);
 
         final URI file = RestDslGeneratorTest.class.getResource("/MyRestRoute.txt").toURI();

http://git-wip-us.apache.org/repos/asf/camel/blob/30308c9f/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
----------------------------------------------------------------------
diff --git a/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt b/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
index 6a4cb0f..ab99611 100644
--- a/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
+++ b/tooling/swagger-rest-dsl-generator/src/test/resources/SwaggerPetstore.txt
@@ -8,10 +8,7 @@ import org.apache.camel.model.rest.RestParamType;
 /**
  * Generated from Swagger specification by Camel REST DSL generator.
  */
-@Generated(
-        value = "org.apache.camel.generator.swagger.AppendableGenerator",
-        date = "2017-10-17T00:00:00Z"
-)
+@Generated("org.apache.camel.generator.swagger.AppendableGenerator")
 public final class SwaggerPetstore extends RouteBuilder {
     /**
      * Defines Apache Camel routes using REST DSL fluent API.

Loading...