[
https://issues.apache.org/jira/browse/CAMEL-12865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16689184#comment-16689184
]
ASF GitHub Bot commented on CAMEL-12865:
----------------------------------------
dmvolod closed pull request #2619: CAMEL-12865: camel-restdsl-swagger-plugin -
Allow for specifying apiContextPath
URL: https://github.com/apache/camel/pull/2619
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/pom.xml
b/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/pom.xml
index b91faba0b69..3aaad869f61 100644
--- a/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/pom.xml
+++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/pom.xml
@@ -53,6 +53,7 @@
<className>MyRestRoute</className>
<indent>\t</indent>
<destinationGenerator>com.example.MyDestinationGenerator</destinationGenerator>
+ <apiContextPath>/api-docs</apiContextPath>
</configuration>
</execution>
</executions>
diff --git
a/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/verify.groovy
b/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/verify.groovy
index f65964b72fe..3c154edeb5f 100644
--- a/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/verify.groovy
+++ b/tooling/maven/camel-restdsl-swagger-plugin/src/it/customized/verify.groovy
@@ -18,3 +18,7 @@
def File restdsl = new File(basedir,
"target/classes/generated/com/example/MyRestRoute.java")
assert restdsl.exists()
+
+def String data = restdsl.text
+
+assert
data.contains('restConfiguration().component("servlet").apiContextPath("/api-docs");')
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 58066dec416..356c0ba78eb 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
@@ -66,7 +66,8 @@ in the `<configuration>` tag.
| `indent` | `" "` | What identing character(s) to use,
by default four spaces, you can use `\t` to signify tab character
| `outputDirectory` | `generated-sources/restdsl-swagger` | Where to place the
generated source file, by default `generated-sources/restdsl-swagger` within
the project directory
| `destinationGenerator` | | Fully qualified class name of the class that
implements `org.apache.camel.generator.swagger.DestinationGenerator` interface
for customizing destination endpoint
-| `restConfiguration` | `true` | Whether to include generation of the rest
configuration with detected rest component to be used. |
+| `restConfiguration` | `true` | Whether to include generation of the rest
configuration with detected rest component to be used.
+| `apiContextPath` | | Define swagger endpoint path if `restConfiguration` is
set to `true`. |
|========================================
=== Spring Boot Project with Servlet component
@@ -138,7 +139,8 @@ in the `<configuration>` tag.
| `fileName` | `camel-rest.xml` | The name of the XML file as output.
| `blueprint` | `false` | If enabled generates OSGi Blueprint XML instead of
Spring XML.
| `destinationGenerator` | | Fully qualified class name of the class that
implements `org.apache.camel.generator.swagger.DestinationGenerator` interface
for customizing destination endpoint
-| `restConfiguration` | `true` | Whether to include generation of the rest
configuration with detected rest component to be used. |
+| `restConfiguration` | `true` | Whether to include generation of the rest
configuration with detected rest component to be used.
+| `apiContextPath` | | Define swagger endpoint path if `restConfiguration` is
set to `true`. |
|========================================
== camel-restdsl-swagger:generate-xml-with-dto
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 8dbbde73c03..7d1903dd3e1 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
@@ -97,6 +97,9 @@
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession mavenSession;
+
+ @Parameter
+ String apiContextPath;
@Component
private BuildPluginManager pluginManager;
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 41aaa9473fd..74b37028679 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
@@ -118,6 +118,10 @@ public void execute() throws MojoExecutionException {
generator.withRestComponent("servlet");
}
+
+ if (ObjectHelper.isNotEmpty(apiContextPath)) {
+ generator.withApiContextPath(apiContextPath);
+ }
// if its a spring boot project and we use servlet then we should
generate additional source code
if (detectSpringBootFromClasspath() && "servlet".equals(comp)) {
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 a96f2aa5e3a..a8969620525 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
@@ -36,6 +36,7 @@
OperationFilter filter = new OperationFilter();
String restComponent;
String restContextPath;
+ String apiContextPath;
boolean springComponent;
boolean springBootProject;
@@ -92,6 +93,15 @@ public G withRestContextPath(String contextPath) {
return that;
}
+
+ public G withApiContextPath(String contextPath) {
+ this.apiContextPath = contextPath;
+
+ @SuppressWarnings("unchecked")
+ final G that = (G) this;
+
+ return that;
+ }
public G asSpringComponent() {
this.springComponent = true;
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 a2fe715b35d..7ec89222b7a 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
@@ -108,6 +108,9 @@ MethodSpec generateConfigureMethod(final Swagger swagger) {
if (restContextPath != null) {
configure.addCode(".contextPath(\"" + restContextPath + "\")");
}
+ if (ObjectHelper.isNotEmpty(apiContextPath)) {
+ configure.addCode(".apiContextPath(\"" + apiContextPath +
"\")");
+ }
configure.addCode(";\n\n");
}
diff --git
a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
index 20b849032fd..36034d58bc7 100644
---
a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
+++
b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
@@ -20,6 +20,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.model.ModelHelper;
import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.util.ObjectHelper;
public class RestDslXmlGenerator extends RestDslGenerator<RestDslXmlGenerator>
{
@@ -51,10 +52,14 @@ public String generate(final CamelContext context) throws
Exception {
xml = xml.replaceAll(" customId=\"false\"", "");
if (restComponent != null) {
- String extra = "<restConfiguration component=\"" + restComponent +
"\"/>";
+ String extra = "<restConfiguration component=\"" + restComponent +
"\"";
if (restContextPath != null) {
- extra = "<restConfiguration component=\"" + restComponent +
"\" contextPath=\"" + restContextPath + "\"/>";
+ extra = extra.concat(" contextPath=\"" + restContextPath +
"\"");
}
+ if (ObjectHelper.isNotEmpty(apiContextPath)) {
+ extra = extra.concat(" apiContextPath=\"" + apiContextPath +
"\"");
+ }
+ extra = extra.concat("/>");
xml = xml.replaceFirst("<rest>", extra + "\n <rest>");
xml = xml.replaceFirst("<rest ", extra + "\n <rest ");
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> camel-restdsl-swagger-plugin - Allow for specifying apiContextPath
> ------------------------------------------------------------------
>
> Key: CAMEL-12865
> URL: https://issues.apache.org/jira/browse/CAMEL-12865
> Project: Camel
> Issue Type: Improvement
> Components: tooling
> Affects Versions: 2.22.1
> Reporter: Jochen Cordes
> Assignee: Dmitry Volodin
> Priority: Major
>
> The camel-restdsl-swagger-plugin should allow for specifying the
> apiContextPath for the generated code, i.e.
> restConfiguration().component("servlet").apiContextPath("/api-docs");
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)