You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/09/15 15:57:00 UTC
[camel] 11/22: CAMEL-15478: api-component should generate @ApiParam
with more fine grained details so we know which parameter is for which api
method.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch api
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5981233474303187fe720a2f2dea12bd7e733b7b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Sep 14 12:13:53 2020 +0200
CAMEL-15478: api-component should generate @ApiParam with more fine grained details so we know which parameter is for which api method.
---
.../java/org/apache/camel/spi/ApiMethod.java | 7 ++++---
.../java/org/apache/camel/spi/ApiParam.java | 9 ++------
.../maven/AbstractApiMethodGeneratorMojo.java | 24 ++++++++++++++--------
.../src/main/resources/api-endpoint-config.vm | 7 +------
.../main/java/org/apache/camel/spi/ApiMethod.java | 7 ++++---
.../main/java/org/apache/camel/spi/ApiParam.java | 9 ++------
6 files changed, 29 insertions(+), 34 deletions(-)
diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java b/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java
index 008f875..2eaead7 100644
--- a/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java
+++ b/core/camel-api/src/generated/java/org/apache/camel/spi/ApiMethod.java
@@ -36,14 +36,15 @@ public @interface ApiMethod {
String methodName();
/**
- * Returns the method signature of this api method.
+ * Returns the method signature(s) of this api method. A method may have one or more signatures, such as for
+ * overloaded methhods.
* <p/>
* This is used for documentation and tooling only.
*/
- String signature() default "";
+ String[] signatures() default "";
/**
- * Returns a description of this api method.
+ * Returns a description of this api method or api parameter.
* <p/>
* This is used for documentation and tooling only.
*/
diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/ApiParam.java b/core/camel-api/src/generated/java/org/apache/camel/spi/ApiParam.java
index a6287b9..984dd10 100644
--- a/core/camel-api/src/generated/java/org/apache/camel/spi/ApiParam.java
+++ b/core/camel-api/src/generated/java/org/apache/camel/spi/ApiParam.java
@@ -34,14 +34,9 @@ import java.lang.annotation.Target;
public @interface ApiParam {
/**
- * The API methods (separated by comma) that the API provides of this configuration class.
- *
- * This is only applicable for API based components where configurations are separated by API names and methods
- * (grouping).
+ * The API methods that the API provides of this configuration class.
*/
- String apiMethods();
-
- // TODO: We need an array of api methods and description
+ ApiMethod[] apiMethods();
/**
* Returns a description of this parameter.
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
index 5a0467a..6d6bb75 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
@@ -24,7 +24,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.StringJoiner;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -297,19 +296,28 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
}
}
- public static String getApiMethods(List<ApiMethodParser.ApiMethodModel> models, ApiMethodArg argument) {
+ public static String getApiMethodsForParam(List<ApiMethodParser.ApiMethodModel> models, ApiMethodArg argument) {
+ StringBuilder sb = new StringBuilder();
+
String key = argument.getName();
- StringJoiner sj = new StringJoiner(",");
models.forEach(p -> {
- boolean match = p.getArguments().stream().anyMatch(a -> a.getName().equals(key));
- if (match) {
- if (sj.length() == 0 || !sj.toString().contains(p.getName())) {
- sj.add(p.getName());
+ ApiMethodArg match = p.getArguments().stream().filter(a -> a.getName().equals(key)).findFirst().orElse(null);
+ if (match != null) {
+ String desc = match.getDescription();
+ sb.append("@ApiMethod(methodName = \"").append(p.getName()).append("\"");
+ if (desc != null) {
+ sb.append(", description=\"").append(desc).append("\"");
}
+ sb.append(")");
+ sb.append(", ");
}
});
+ String answer = sb.toString();
+ if (answer.endsWith(", ")) {
+ answer = answer.substring(0, answer.length() - 2);
+ }
// TODO: if no explicit then it should maybe match all methods?
- return sj.toString();
+ return "{" + answer + "}";
}
public static String getTestName(ApiMethodParser.ApiMethodModel model) {
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
index ba9babc..5dd8b2f 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-endpoint-config.vm
@@ -52,13 +52,8 @@ import org.apache.camel.spi.UriParams;
@Configurer
public final class $configName extends ${componentName}Configuration {
#foreach( $parameter in $parameters.entrySet() )
-#if( $helper.hasDoc($parameter.Value) )
@UriParam
- @ApiParam(apiMethods = "$helper.getApiMethods($models, $parameter.Value)", description = "$helper.getDoc($parameter.Value)")
-#else
- @UriParam
- @ApiParam(apiMethods = "$helper.getApiMethods($models, $parameter.Value)")
-#end
+ @ApiParam(apiMethods = $helper.getApiMethodsForParam($models, $parameter.Value))
private $helper.getCanonicalName($parameter.Value) $parameter.Key;
#end
## getters and setters
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java
index 008f875..2eaead7 100644
--- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiMethod.java
@@ -36,14 +36,15 @@ public @interface ApiMethod {
String methodName();
/**
- * Returns the method signature of this api method.
+ * Returns the method signature(s) of this api method. A method may have one or more signatures, such as for
+ * overloaded methhods.
* <p/>
* This is used for documentation and tooling only.
*/
- String signature() default "";
+ String[] signatures() default "";
/**
- * Returns a description of this api method.
+ * Returns a description of this api method or api parameter.
* <p/>
* This is used for documentation and tooling only.
*/
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiParam.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiParam.java
index a6287b9..984dd10 100644
--- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiParam.java
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/ApiParam.java
@@ -34,14 +34,9 @@ import java.lang.annotation.Target;
public @interface ApiParam {
/**
- * The API methods (separated by comma) that the API provides of this configuration class.
- *
- * This is only applicable for API based components where configurations are separated by API names and methods
- * (grouping).
+ * The API methods that the API provides of this configuration class.
*/
- String apiMethods();
-
- // TODO: We need an array of api methods and description
+ ApiMethod[] apiMethods();
/**
* Returns a description of this parameter.