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:06 UTC
[camel] 17/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 7b957335e9b58056b4941e9231f9ad57366feadc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Sep 15 14:19:32 2020 +0200
CAMEL-15478: api-component should generate @ApiParam with more fine grained details so we know which parameter is for which api method.
---
components/camel-fhir/camel-fhir-component/pom.xml | 10 ++++----
.../signatures/capabilities-sig-api.txt | 18 --------------
.../signatures/history-sig-api.txt | 19 --------------
.../signatures/load-page-sig-api.txt | 19 --------------
.../signatures/meta-sig-api.txt | 21 ----------------
.../signatures/operation-sig-api.txt | 21 ----------------
.../org/apache/camel/maven/JavaSourceParser.java | 29 +++++++++++-----------
.../apache/camel/maven/JavaSourceParserTest.java | 10 ++++----
8 files changed, 25 insertions(+), 122 deletions(-)
diff --git a/components/camel-fhir/camel-fhir-component/pom.xml b/components/camel-fhir/camel-fhir-component/pom.xml
index 9fc277a..dabb4b0 100644
--- a/components/camel-fhir/camel-fhir-component/pom.xml
+++ b/components/camel-fhir/camel-fhir-component/pom.xml
@@ -156,7 +156,7 @@
<api>
<apiName>capabilities</apiName>
<proxyClass>org.apache.camel.component.fhir.api.FhirCapabilities</proxyClass>
- <fromSignatureFile>signatures/capabilities-sig-api.txt</fromSignatureFile>
+ <fromJavasource/>
<nullableOptions>
<nullableOption>extraParameters</nullableOption>
</nullableOptions>
@@ -182,7 +182,7 @@
<api>
<apiName>history</apiName>
<proxyClass>org.apache.camel.component.fhir.api.FhirHistory</proxyClass>
- <fromSignatureFile>signatures/history-sig-api.txt</fromSignatureFile>
+ <fromJavasource/>
<nullableOptions>
<nullableOption>count</nullableOption>
<nullableOption>cutoff</nullableOption>
@@ -193,7 +193,7 @@
<api>
<apiName>load-page</apiName>
<proxyClass>org.apache.camel.component.fhir.api.FhirLoadPage</proxyClass>
- <fromSignatureFile>signatures/load-page-sig-api.txt</fromSignatureFile>
+ <fromJavasource/>
<nullableOptions>
<nullableOption>extraParameters</nullableOption>
</nullableOptions>
@@ -201,7 +201,7 @@
<api>
<apiName>meta</apiName>
<proxyClass>org.apache.camel.component.fhir.api.FhirMeta</proxyClass>
- <fromSignatureFile>signatures/meta-sig-api.txt</fromSignatureFile>
+ <fromJavasource/>
<nullableOptions>
<nullableOption>extraParameters</nullableOption>
</nullableOptions>
@@ -209,7 +209,7 @@
<api>
<apiName>operation</apiName>
<proxyClass>org.apache.camel.component.fhir.api.FhirOperation</proxyClass>
- <fromSignatureFile>signatures/operation-sig-api.txt</fromSignatureFile>
+ <fromJavasource/>
<nullableOptions>
<nullableOption>extraParameters</nullableOption>
<nullableOption>parameters</nullableOption>
diff --git a/components/camel-fhir/camel-fhir-component/signatures/capabilities-sig-api.txt b/components/camel-fhir/camel-fhir-component/signatures/capabilities-sig-api.txt
deleted file mode 100644
index a1bfe8e..0000000
--- a/components/camel-fhir/camel-fhir-component/signatures/capabilities-sig-api.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-## ------------------------------------------------------------------------
-## 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.
-## ------------------------------------------------------------------------
-
-<T extends org.hl7.fhir.instance.model.api.IBaseConformance> T ofType(Class<T> type, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
\ No newline at end of file
diff --git a/components/camel-fhir/camel-fhir-component/signatures/history-sig-api.txt b/components/camel-fhir/camel-fhir-component/signatures/history-sig-api.txt
deleted file mode 100644
index d50a5f3..0000000
--- a/components/camel-fhir/camel-fhir-component/signatures/history-sig-api.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-## ------------------------------------------------------------------------
-## 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.
-## ------------------------------------------------------------------------
-<T extends org.hl7.fhir.instance.model.api.IBaseBundle> T onServer(Class<T> returnType, Integer count, java.util.Date cutoff, org.hl7.fhir.instance.model.api.IPrimitiveType<java.util.Date> iCutoff, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseBundle> T onType(Class<org.hl7.fhir.instance.model.api.IBaseResource> resourceType, Class<T> returnType, Integer count, java.util.Date cutoff, org.hl7.fhir.instance.model.api.IPrimitiveType<java.util.Date> iCutoff, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseBundle> T onInstance(org.hl7.fhir.instance.model.api.IIdType id, Class<T> returnType, Integer count, java.util.Date cutoff, org.hl7.fhir.instance.model.api.IPrimitiveType<java.util.Date> iCutoff, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
\ No newline at end of file
diff --git a/components/camel-fhir/camel-fhir-component/signatures/load-page-sig-api.txt b/components/camel-fhir/camel-fhir-component/signatures/load-page-sig-api.txt
deleted file mode 100644
index 505e088..0000000
--- a/components/camel-fhir/camel-fhir-component/signatures/load-page-sig-api.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-## ------------------------------------------------------------------------
-## 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.
-## ------------------------------------------------------------------------
-<T extends org.hl7.fhir.instance.model.api.IBaseBundle> T next(T bundle, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseBundle> T previous(T bundle, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseBundle> T byUrl(String url, Class<T> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
diff --git a/components/camel-fhir/camel-fhir-component/signatures/meta-sig-api.txt b/components/camel-fhir/camel-fhir-component/signatures/meta-sig-api.txt
deleted file mode 100644
index ac901bd..0000000
--- a/components/camel-fhir/camel-fhir-component/signatures/meta-sig-api.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-## ------------------------------------------------------------------------
-## 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.
-## ------------------------------------------------------------------------
-<T extends org.hl7.fhir.instance.model.api.IBaseMetaType> T getFromServer(Class<T> metaType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseMetaType> T getFromResource(Class<T> metaType, org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseMetaType> T getFromType(Class<T> metaType, String theResourceName, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseMetaType> T add(T meta, org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
-<T extends org.hl7.fhir.instance.model.api.IBaseMetaType> T delete(T meta, org.hl7.fhir.instance.model.api.IIdType id, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
diff --git a/components/camel-fhir/camel-fhir-component/signatures/operation-sig-api.txt b/components/camel-fhir/camel-fhir-component/signatures/operation-sig-api.txt
deleted file mode 100644
index e6ec415..0000000
--- a/components/camel-fhir/camel-fhir-component/signatures/operation-sig-api.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-## ------------------------------------------------------------------------
-## 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.
-## ------------------------------------------------------------------------
- <T extends org.hl7.fhir.instance.model.api.IBaseParameters> org.hl7.fhir.instance.model.api.IBaseResource onType(Class<org.hl7.fhir.instance.model.api.IBaseResource> resourceType, String name, T parameters, Class<T> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
- <T extends org.hl7.fhir.instance.model.api.IBaseParameters> org.hl7.fhir.instance.model.api.IBaseResource onServer(String name, T parameters, Class<T> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
- <T extends org.hl7.fhir.instance.model.api.IBaseParameters> org.hl7.fhir.instance.model.api.IBaseResource onInstance(org.hl7.fhir.instance.model.api.IIdType id, String name, T parameters, Class<T> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
- <T extends org.hl7.fhir.instance.model.api.IBaseParameters> org.hl7.fhir.instance.model.api.IBaseResource onInstanceVersion(org.hl7.fhir.instance.model.api.IIdType id, String name, T parameters, Class<T> outputParameterType, boolean useHttpGet, Class<org.hl7.fhir.instance.model.api.IBaseResource> returnType, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
- <T extends org.hl7.fhir.instance.model.api.IBaseBundle> T processMessage(String respondToUri, org.hl7.fhir.instance.model.api.IBaseBundle msgBundle, boolean asynchronous, Class<T> responseClass, java.util.Map<org.apache.camel.component.fhir.api.ExtraParameters,java.lang.Object> extraParameters);
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
index 50530a7..356e73f 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java
@@ -96,19 +96,20 @@ public class JavaSourceParser {
methodDescriptions.put(ms.getName(), doc);
}
- String signature = ms.toSignature();
- // roaster signatures has return values at end
- // public create(String, AddressRequest) : Result
-
- int pos = signature.indexOf(':');
- String result = signature.substring(pos + 1).trim();
- // lets use FQN types
- if (!"void".equals(result)) {
- result = resolveType(rootClazz, clazz, result);
- }
- if (result.isEmpty()) {
- result = "void";
+ String result;
+ Type rt = ms.getReturnType();
+ boolean hasTypeVariables = ms.hasTypeVariable(rt.getName()) || clazz.hasTypeVariable(rt.getName());
+ if (hasTypeVariables) {
+ // okay this gets to complex then remove the generics
+ result = "Object";
+ } else {
+ result = resolveType(rootClazz, clazz, ms, rt);
+ if (result == null || result.isEmpty()) {
+ result = "void";
+ }
}
+ // remove java.lang. prefix as it should not be there
+ result = result.replaceAll("java.lang.", "");
List<JavaDocTag> params = ms.getJavaDoc().getTags("@param");
@@ -131,7 +132,7 @@ public class JavaSourceParser {
if (ps.getType().isParameterized()) {
// for parameterized types then it can get complex if they are variables (T, T extends Foo etc)
List<Type> types = ps.getType().getTypeArguments();
- boolean hasTypeVariables = false;
+ hasTypeVariables = false;
for (Type t : types) {
hasTypeVariables |= ms.hasTypeVariable(t.getName()) || clazz.hasTypeVariable(t.getName());
}
@@ -161,8 +162,8 @@ public class JavaSourceParser {
} else {
parameters.put(ms.getName(), docs);
}
- signature = sb.toString();
+ String signature = sb.toString();
methods.add(signature);
signaturesArguments.put(signature, args);
methodText.put(ms.getName(), signature);
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java
index 0395604..52b7125 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/maven/JavaSourceParserTest.java
@@ -35,7 +35,7 @@ public class JavaSourceParserTest {
assertEquals(4, parser.getMethods().size());
assertEquals(
- "public com.braintreegateway.Result create(String customerId, com.braintreegateway.AddressRequest request)",
+ "public com.braintreegateway.Result<com.braintreegateway.Address> create(String customerId, com.braintreegateway.AddressRequest request)",
parser.getMethods().get(0));
assertEquals(2, parser.getParameters().get("create").size());
assertEquals("The id of the Customer", parser.getParameters().get("create").get("customerId"));
@@ -50,7 +50,7 @@ public class JavaSourceParserTest {
assertEquals(7, parser.getMethods().size());
assertEquals(
- "public com.braintreegateway.Result create(com.braintreegateway.CustomerRequest request)",
+ "public com.braintreegateway.Result<com.braintreegateway.Customer> create(com.braintreegateway.CustomerRequest request)",
parser.getMethods().get(1));
assertEquals(1, parser.getParameters().get("create").size());
assertEquals("The request", parser.getParameters().get("create").get("request"));
@@ -64,7 +64,7 @@ public class JavaSourceParserTest {
assertEquals(9, parser.getMethods().size());
assertEquals(
- "public com.braintreegateway.Result addFileEvidence(String disputeId, String documentId)",
+ "public com.braintreegateway.Result<com.braintreegateway.DisputeEvidence> addFileEvidence(String disputeId, String documentId)",
parser.getMethods().get(1));
assertEquals(3, parser.getParameters().get("addFileEvidence").size());
assertEquals("The dispute id to add text evidence to", parser.getParameters().get("addFileEvidence").get("disputeId"));
@@ -81,7 +81,7 @@ public class JavaSourceParserTest {
// varargs is transformed to an array type as that is what works
assertEquals(
- "public java.lang.String greetWildcard(String[] wildcardNames)",
+ "public String greetWildcard(String[] wildcardNames)",
parser.getMethods().get(6));
}
@@ -93,7 +93,7 @@ public class JavaSourceParserTest {
assertEquals(1, parser.getMethods().size());
assertEquals(
- "public java.lang.String getOrderById(int id)",
+ "public String getOrderById(int id)",
parser.getMethods().get(0));
assertEquals(1, parser.getParameters().get("getOrderById").size());
assertEquals("The order id", parser.getParameters().get("getOrderById").get("id"));