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/16 12:51:59 UTC
[camel] 02/06: CAMEL-15478: Generated component json for API
components to include expected information
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 1df029ed5cb0254bf6dd00c06ec97347420d2124
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Sep 16 12:39:21 2020 +0200
CAMEL-15478: Generated component json for API components to include expected information
---
.../apache/camel/tooling/model/ApiMethodModel.java | 16 ++++++++++
.../org/apache/camel/tooling/model/ApiModel.java | 21 ++++++++++++-
.../org/apache/camel/tooling/model/JsonMapper.java | 4 +--
.../packaging/EndpointSchemaGeneratorMojo.java | 35 +++++++++++++++++-----
4 files changed, 64 insertions(+), 12 deletions(-)
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java
index 06119f2..d2d57d0 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiMethodModel.java
@@ -1,3 +1,19 @@
+/*
+ * 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.tooling.model;
import java.util.ArrayList;
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java
index d67cdd6..6f4ea28 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/ApiModel.java
@@ -1,3 +1,19 @@
+/*
+ * 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.tooling.model;
import java.util.ArrayList;
@@ -29,7 +45,10 @@ public final class ApiModel {
return methods;
}
- public void addMethod(ApiMethodModel method) {
+ public ApiMethodModel newMethod(String methodName) {
+ ApiMethodModel method = new ApiMethodModel();
+ method.setName(methodName);
this.methods.add(method);
+ return method;
}
}
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
index 4daf25f..4cd06f4 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/JsonMapper.java
@@ -110,9 +110,7 @@ public final class JsonMapper {
if (mm != null) {
for (Map.Entry<String, Object> mentry : mprap.entrySet()) {
JsonObject mmp = (JsonObject) mentry.getValue();
- ApiMethodModel amm = new ApiMethodModel();
- am.addMethod(amm);
- amm.setName(mmp.getString("apiMethodName"));
+ ApiMethodModel amm = am.newMethod(mmp.getString("apiMethodName"));
amm.setDescription(mmp.getString("description"));
JsonObject properties = (JsonObject) obj.get("properties");
if (properties != null) {
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
index 4263ca3..1433df9 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
@@ -1100,17 +1100,37 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
componentModel.addComponentOption((ComponentOptionModel) option);
} else if (apiOption && apiParam != null) {
option.setKind("parameter");
- ApiModel api = new ApiModel();
+ final String targetApiName = apiName;
+ ApiModel api;
+ Optional<ApiModel> op = componentModel.getApiOptions().stream()
+ .filter(o -> o.getName().equals(targetApiName))
+ .findFirst();
+ if (!op.isPresent()) {
+ api = new ApiModel();
+ componentModel.getApiOptions().add(api);
+ } else {
+ api = op.get();
+ }
api.setName(apiName);
for (ApiMethod method : apiParam.apiMethods()) {
- ApiMethodModel apiMethod = new ApiMethodModel();
- api.addMethod(apiMethod);
- apiMethod.setName(method.methodName());
+ ApiMethodModel apiMethod = null;
+ for (ApiMethodModel m : api.getMethods()) {
+ if (m.getName().equals(method.methodName())) {
+ apiMethod = m;
+ break;
+ }
+ }
+ if (apiMethod == null) {
+ apiMethod = api.newMethod(method.methodName());
+ }
// the method description is stored on @ApiParams
if (apiParams != null) {
- Arrays.stream(apiParams.apiMethods())
- .filter(m -> m.methodName().equals(method.methodName()))
- .findFirst().ifPresent(m -> apiMethod.setDescription(m.description()));
+ for (ApiMethod m : apiParams.apiMethods()) {
+ if (m.methodName().equals(method.methodName())) {
+ apiMethod.setDescription(m.description());
+ break;
+ }
+ }
}
// copy the option and override with the correct description
ApiOptionModel copy = ((ApiOptionModel) option).copy();
@@ -1118,7 +1138,6 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
// the option description is stored on @ApiMethod
copy.setDescription(method.description());
}
- componentModel.getApiOptions().add(api);
} else {
option.setKind("parameter");
if (componentModel.getEndpointOptions().stream().noneMatch(opt -> name.equals(opt.getName()))) {