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 4410c80ad849643eb3c0803d9bf0b1d83b7b571e Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Sep 27 11:36:47 2018 +0200 CAMEL-12828: camel-restdsl-swagger:generate - Add option to generate dto objects --- .../src/it/{simple => simple-dto}/pom.xml | 6 ++-- .../src/it/simple-dto/src/spec/swagger.json | 1 + .../src/it/simple-dto/verify.groovy | 24 +++++++++++++ .../src/it/{simple-xml => simple-xml-dto}/pom.xml | 4 +-- .../src/it/simple-xml-dto/src/spec/swagger.json | 1 + .../src/it/simple-xml-dto/verify.groovy | 24 +++++++++++++ .../src/it/simple-xml/pom.xml | 25 +------------- .../src/it/simple/pom.xml | 23 ------------- .../main/docs/camel-restdsl-swagger-plugin.adoc | 39 ++++++++++++++++++++++ .../generator/swagger/AbstractGenerateMojo.java | 3 -- .../maven/generator/swagger/GenerateMojo.java | 5 +-- .../generator/swagger/GenerateWithDtoMojo.java | 38 +++++++++++++++++++++ .../maven/generator/swagger/GenerateXmlMojo.java | 7 +--- .../generator/swagger/GenerateXmlWithDtoMojo.java | 39 ++++++++++++++++++++++ 14 files changed, 174 insertions(+), 65 deletions(-) diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/pom.xml similarity index 95% copy from tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml copy to tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/pom.xml index 4da5d91..29d0953 100644 --- a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/pom.xml @@ -22,7 +22,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.camel.maven.generator.swagger.it</groupId> - <artifactId>simple</artifactId> + <artifactId>simple-dto</artifactId> <version>1-SNAPSHOT</version> <description>A simple IT verifying the basic use case.</description> @@ -64,9 +64,9 @@ <version>@project.version@</version> <executions> <execution> - <id>simple</id> + <id>simple-dto</id> <goals> - <goal>generate</goal> + <goal>generate-with-dto</goal> </goals> </execution> </executions> diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/src/spec/swagger.json b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/src/spec/swagger.json new file mode 100644 index 0000000..816847f --- /dev/null +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/src/spec/swagger.json @@ -0,0 +1 @@ +{"swagger":"2.0","info":{"description":"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.","version":"1.0.0","title":"Swagger Petstore","termsOfService":"http://swagger.io/terms/","contact":{"email":"apit...@swagger.io"},"license":{"name":"Apache 2.0","url":"http://www.a [...] \ No newline at end of file diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/verify.groovy b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/verify.groovy new file mode 100644 index 0000000..8d0e667 --- /dev/null +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-dto/verify.groovy @@ -0,0 +1,24 @@ +/** + * 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. + */ + +def File restdsl = new File(basedir, "target/generated-sources/restdsl-swagger/io/swagger/petstore/SwaggerPetstore.java") + +assert restdsl.exists() + +def File restdto = new File(basedir, "target/generated-sources/swagger/src/main/java/io/swagger/client/model/Order.java") + +assert restdto.exists() diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/pom.xml similarity index 96% copy from tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml copy to tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/pom.xml index dce6e63..9b4b5a3 100644 --- a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/pom.xml @@ -22,7 +22,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.camel.maven.generator.swagger.it</groupId> - <artifactId>simple</artifactId> + <artifactId>simple-xml-dto</artifactId> <version>1-SNAPSHOT</version> <description>A simple IT verifying the basic use case.</description> @@ -66,7 +66,7 @@ <execution> <id>simple</id> <goals> - <goal>generate-xml</goal> + <goal>generate-xml-with-dto</goal> </goals> <configuration> <blueprint>true</blueprint> diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/src/spec/swagger.json b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/src/spec/swagger.json new file mode 100644 index 0000000..816847f --- /dev/null +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/src/spec/swagger.json @@ -0,0 +1 @@ +{"swagger":"2.0","info":{"description":"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.","version":"1.0.0","title":"Swagger Petstore","termsOfService":"http://swagger.io/terms/","contact":{"email":"apit...@swagger.io"},"license":{"name":"Apache 2.0","url":"http://www.a [...] \ No newline at end of file diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/verify.groovy b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/verify.groovy new file mode 100644 index 0000000..0efda6a --- /dev/null +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml-dto/verify.groovy @@ -0,0 +1,24 @@ +/** + * 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. + */ + +def File restdsl = new File(basedir, "target/generated-sources/restdsl-swagger/camel-rest.xml") + +assert restdsl.exists() + +def File restdto = new File(basedir, "target/generated-sources/swagger/src/main/java/io/swagger/client/model/Order.java") + +assert restdto.exists() diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml index dce6e63..7b1c657 100644 --- a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple-xml/pom.xml @@ -22,7 +22,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.camel.maven.generator.swagger.it</groupId> - <artifactId>simple</artifactId> + <artifactId>simple-xml</artifactId> <version>1-SNAPSHOT</version> <description>A simple IT verifying the basic use case.</description> @@ -33,29 +33,6 @@ <maven.compiler.target>1.8</maven.compiler.target> </properties> - <dependencies> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - <version>@project.version@</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-swagger-java</artifactId> - <version>@project.version@</version> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.5</version> - </dependency> - <dependency> - <groupId>org.threeten</groupId> - <artifactId>threetenbp</artifactId> - <version>1.3.7</version> - </dependency> - </dependencies> - <build> <plugins> <plugin> diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml index 4da5d91..41216a6 100644 --- a/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/simple/pom.xml @@ -33,29 +33,6 @@ <maven.compiler.target>1.8</maven.compiler.target> </properties> - <dependencies> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - <version>@project.version@</version> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-swagger-java</artifactId> - <version>@project.version@</version> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.5</version> - </dependency> - <dependency> - <groupId>org.threeten</groupId> - <artifactId>threetenbp</artifactId> - <version>1.3.7</version> - </dependency> - </dependencies> - <build> <plugins> <plugin> 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 e0fef24..542f0d4 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 @@ -5,9 +5,17 @@ The Camel REST DSL Swagger Maven Plugin supports the following goals - camel-restdsl-swagger:generate - To generate consumer REST DSL RouteBuilder source code from Swagger specification + - camel-restdsl-swagger:generate-with-dto - To generate consumer REST DSL + RouteBuilder source code from Swagger specification and with DTO model + classes generated via the swagger-codegen-maven-plugin. + - camel-restdsl-swagger:generate-xml - To generate consumer REST DSL XML source code from Swagger specification + - camel-restdsl-swagger:generate-xml-with-dto - To generate consumer REST DSL + XML source code from Swagger specification and with DTO model + classes generated via the swagger-codegen-maven-plugin. + == camel-restdsl-swagger:generate The `camel-restdsl-swagger:generate` goal of the Camel REST DSL @@ -32,6 +40,22 @@ in the `<configuration>` tag. | `destinationGenerator` | | Fully qualified class name of the class that implements `org.apache.camel.generator.swagger.DestinationGenerator` interface for customizing destination endpoint |======================================== +== camel-restdsl-swagger:generate-with-dto + +Works as `generate` goal but also generates DTO model classes by automatic executing +the swagger-codegen-maven-plugin to generate java source code of the DTO model classes +from the swagger specification. + +=== Options + +The plugin supports the following *additional* options + +|======================================== +| Parameter | Default Value | Description +| `swaggerCodegenMavenPluginVersion` | 2.3.1 | The version of the `io.swagger:swagger-codegen-maven-plugin` maven plugin to be used. +|======================================== + + == camel-restdsl-swagger:generate-xml The `camel-restdsl-swagger:generate-xml` goal of the Camel REST DSL @@ -55,3 +79,18 @@ in the `<configuration>` tag. | `destinationGenerator` | | Fully qualified class name of the class that implements `org.apache.camel.generator.swagger.DestinationGenerator` interface for customizing destination endpoint |======================================== +== camel-restdsl-swagger:generate-xml-with-dto + +Works as `generate-xml` goal but also generates DTO model classes by automatic executing +the swagger-codegen-maven-plugin to generate java source code of the DTO model classes +from the swagger specification. + +=== Options + +The plugin supports the following *additional* options + +|======================================== +| Parameter | Default Value | Description +| `swaggerCodegenMavenPluginVersion` | 2.3.1 | The version of the `io.swagger:swagger-codegen-maven-plugin` maven plugin to be used. +|======================================== + diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java index bd993cd..4eb403f 100644 --- a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java @@ -59,9 +59,6 @@ abstract class AbstractGenerateMojo extends AbstractMojo { @Parameter(defaultValue = "${project.basedir}/src/spec/swagger.json", required = true) String specificationUri; - @Parameter(defaultValue = "true") - boolean dto; - @Parameter(defaultValue = "2.3.1") String swaggerCodegenMavenPluginVersion; 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 1cd48e6..1a15f98 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 @@ -90,15 +90,12 @@ public class GenerateMojo extends AbstractGenerateMojo { final Path outputPath = new File(outputDirectory).toPath(); try { + getLog().info("Generating Camel DSL source in directory: " + outputPath); generator.generate(outputPath); } catch (final IOException e) { throw new MojoExecutionException( "Unable to generate REST DSL Swagger sources from specification: " + specificationUri, e); } - - if (dto) { - generateDto(); - } } } diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateWithDtoMojo.java b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateWithDtoMojo.java new file mode 100644 index 0000000..42e491f --- /dev/null +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateWithDtoMojo.java @@ -0,0 +1,38 @@ +/** + * 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.maven.generator.swagger; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name = "generate-with-dto", inheritByDefault = false, defaultPhase = LifecyclePhase.GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) +public class GenerateWithDtoMojo extends GenerateMojo { + + @Override + public void execute() throws MojoExecutionException { + if (skip) { + return; + } + super.execute(); + + generateDto(); + } + +} diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java index a8b7ed9..67f74ac 100644 --- a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java @@ -28,7 +28,6 @@ import org.apache.camel.generator.swagger.RestDslXmlGenerator; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.util.ObjectHelper; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -48,7 +47,7 @@ public class GenerateXmlMojo extends AbstractGenerateMojo { private boolean blueprint; @Override - public void execute() throws MojoExecutionException, MojoFailureException { + public void execute() throws MojoExecutionException { if (skip) { return; } @@ -94,10 +93,6 @@ public class GenerateXmlMojo extends AbstractGenerateMojo { throw new MojoExecutionException( "Unable to generate REST DSL Swagger sources from specification: " + specificationUri, e); } - - if (dto) { - generateDto(); - } } } diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlWithDtoMojo.java b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlWithDtoMojo.java new file mode 100644 index 0000000..8ba601b --- /dev/null +++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlWithDtoMojo.java @@ -0,0 +1,39 @@ +/** + * 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.maven.generator.swagger; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +@Mojo(name = "generate-xml-with-dto", inheritByDefault = false, defaultPhase = LifecyclePhase.GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) +public class GenerateXmlWithDtoMojo extends GenerateXmlMojo { + + @Override + public void execute() throws MojoExecutionException { + if (skip) { + return; + } + super.execute(); + + generateDto(); + } + +}