You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2019/01/16 08:37:18 UTC

[servicecomb-java-chassis] branch master updated (14d6fb0 -> 15b0657)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git.


    from 14d6fb0  [SCB-1114]upgrade zipkin
     new ad0ee20  [SCB-945] use annotation format to declare additional information
     new b1fe42d  [SCB-945] wrap composite of list and map types to proto message
     new 15b0657  [SCB-945] update protostuff license

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 LICENSE                                            |   2 +-
 .../protobuf/internal/converter/ProtoMethod.java   |  10 -
 .../protobuf/internal/converter/ProtoResponse.java |  10 -
 .../internal/converter/ProtoToStringGenerator.java |  21 +-
 .../converter/SwaggerToProtoGenerator.java         | 116 ++++--
 .../internal/converter/SwaggerTypeAdapter.java     |   4 +
 .../converter/TestSwaggerToProtoGenerator.java     | 161 +-------
 .../internal/converter/model/FieldNeedWrap.java    |  31 +-
 .../internal/converter/model/ProtoSchema.java      |  79 ++++
 .../src/test/resources/ProtoSchema.proto           | 430 +++++++++++++++++++++
 .../foundation/protobuf/internal/ProtoConst.java   |   4 +-
 java-chassis-distribution/src/release/LICENSE      |   2 +-
 12 files changed, 652 insertions(+), 218 deletions(-)
 copy swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/schema/ArrayType.java => common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/FieldNeedWrap.java (55%)
 create mode 100644 common/common-protobuf/src/test/resources/ProtoSchema.proto


[servicecomb-java-chassis] 02/03: [SCB-945] wrap composite of list and map types to proto message

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit b1fe42d8a4ed293b034f1d3fb44d773d8708c478
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Nov 30 22:32:50 2018 +0800

    [SCB-945] wrap composite of list and map types to proto message
---
 .../converter/SwaggerToProtoGenerator.java         |  63 ++-
 .../converter/TestSwaggerToProtoGenerator.java     | 167 +-------
 .../internal/converter/model/FieldNeedWrap.java    |  44 +++
 .../internal/converter/model/ProtoSchema.java      |  79 ++++
 .../src/test/resources/ProtoSchema.proto           | 430 +++++++++++++++++++++
 5 files changed, 615 insertions(+), 168 deletions(-)

diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java
index 8980c1f..c200917 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java
@@ -61,7 +61,7 @@ public class SwaggerToProtoGenerator {
 
   private final Set<String> messages = new HashSet<>();
 
-  private final List<Runnable> pending = new ArrayList<>();
+  private List<Runnable> pending = new ArrayList<>();
 
   // not java package
   // better to be: app_${app}.mid_{microservice}.sid_{schemaId}
@@ -73,8 +73,15 @@ public class SwaggerToProtoGenerator {
   public Proto convert() {
     convertDefinitions();
     convertOperations();
-    for (Runnable runnable : pending) {
-      runnable.run();
+    for (; ; ) {
+      List<Runnable> oldPending = pending;
+      pending = new ArrayList<>();
+      for (Runnable runnable : oldPending) {
+        runnable.run();
+      }
+      if (pending.isEmpty()) {
+        break;
+      }
     }
 
     return createProto();
@@ -153,14 +160,14 @@ public class SwaggerToProtoGenerator {
       return type;
     }
 
-    Property property = adapter.getArrayItem();
-    if (property != null) {
-      return "repeated " + convertSwaggerType(property);
+    Property itemProperty = adapter.getArrayItem();
+    if (itemProperty != null) {
+      return "repeated " + convertArrayOrMapItem(itemProperty);
     }
 
-    property = adapter.getMapItem();
-    if (property != null) {
-      return String.format("map<string, %s>", convertSwaggerType(property));
+    itemProperty = adapter.getMapItem();
+    if (itemProperty != null) {
+      return String.format("map<string, %s>", convertArrayOrMapItem(itemProperty));
     }
 
     if (adapter.isObject()) {
@@ -173,6 +180,40 @@ public class SwaggerToProtoGenerator {
             Json.encode(swaggerType)));
   }
 
+  private String convertArrayOrMapItem(Property itemProperty) {
+    SwaggerTypeAdapter itemAdapter = SwaggerTypeAdapter.create(itemProperty);
+    // List<List<>>, need to wrap
+    if (itemAdapter.getArrayItem() != null) {
+      String protoName = generateWrapPropertyName(List.class.getSimpleName(), itemAdapter.getArrayItem());
+      pending.add(() -> wrapPropertyToMessage(protoName, itemProperty));
+      return protoName;
+    }
+
+    // List<Map<>>, need to wrap
+    if (itemAdapter.getMapItem() != null) {
+      String protoName = generateWrapPropertyName(Map.class.getSimpleName(), itemAdapter.getMapItem());
+      pending.add(() -> wrapPropertyToMessage(protoName, itemProperty));
+      return protoName;
+    }
+
+    return convertSwaggerType(itemProperty);
+  }
+
+  private String generateWrapPropertyName(String prefix, Property property) {
+    SwaggerTypeAdapter adapter = SwaggerTypeAdapter.create(property);
+    // List<List<>>, need to wrap
+    if (adapter.getArrayItem() != null) {
+      return generateWrapPropertyName(prefix + List.class.getSimpleName(), adapter.getArrayItem());
+    }
+
+    // List<Map<>>, need to wrap
+    if (adapter.getMapItem() != null) {
+      return generateWrapPropertyName(prefix + Map.class.getSimpleName(), adapter.getMapItem());
+    }
+
+    return prefix + StringUtils.capitalize(convertSwaggerType(adapter));
+  }
+
   private void wrapPropertyToMessage(String protoName, Property property) {
     createMessage(protoName, Collections.singletonMap("value", property), ProtoConst.ANNOTATION_WRAP_PROPERTY);
   }
@@ -276,7 +317,7 @@ public class SwaggerToProtoGenerator {
       }
     }
 
-    String wrapName = operation.getOperationId() + "RequestWrap";
+    String wrapName = StringUtils.capitalize(operation.getOperationId()) + "RequestWrap";
     createWrapArgs(wrapName, parameters);
 
     protoMethod.setArgTypeName(wrapName);
@@ -291,7 +332,7 @@ public class SwaggerToProtoGenerator {
       protoResponse.setTypeName(type);
 
       if (wrapped) {
-        String wrapName = operation.getOperationId() + "ResponseWrap" + entry.getKey();
+        String wrapName = StringUtils.capitalize(operation.getOperationId()) + "ResponseWrap" + entry.getKey();
         wrapPropertyToMessage(wrapName, entry.getValue().getSchema());
 
         protoResponse.setTypeName(wrapName);
diff --git a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java
index be61f2f..5e3ba28 100644
--- a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java
+++ b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java
@@ -16,6 +16,10 @@
  */
 package org.apache.servicecomb.codec.protobuf.internal.converter;
 
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
 import org.apache.servicecomb.codec.protobuf.internal.converter.model.ProtoSchema;
 import org.apache.servicecomb.swagger.generator.core.SwaggerGenerator;
 import org.apache.servicecomb.swagger.generator.core.SwaggerGeneratorContext;
@@ -27,164 +31,13 @@ import io.protostuff.compiler.model.Proto;
 import io.swagger.models.Swagger;
 
 public class TestSwaggerToProtoGenerator {
-  static String protoContent = "syntax = \"proto3\";\n"
-      + "import \"google/protobuf/empty.proto\";\n"
-      + "import \"google/protobuf/any.proto\";\n"
-      + "package a.b;\n"
-      + "\n"
-      + "message Empty {\n"
-      + "}\n"
-      + "\n"
-      + "message User {\n"
-      + "  string name = 1;\n"
-      + "  repeated User friends = 2;\n"
-      + "}\n"
-      + "\n"
-      + "message Ref1 {\n"
-      + "  Ref2 ref = 1;\n"
-      + "}\n"
-      + "\n"
-      + "message Ref2 {\n"
-      + "  Ref1 ref = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message baseRequestWrap {\n"
-      + "  bool boolValue = 1;\n"
-      + "  int32 iValue = 2;\n"
-      + "  int64 lValue = 3;\n"
-      + "  float fValue = 4;\n"
-      + "  double dValue = 5;\n"
-      + "  string sValue = 6;\n"
-      + "  repeated int32 iArray = 7;\n"
-      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 color = 8;\n"
-      + "  int64 localDate = 9;\n"
-      + "  int64 date = 10;\n"
-      + "  Empty empty = 11;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message baseResponseWrap444 {\n"
-      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message baseResponseWrap200 {\n"
-      + "  int32 value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message bytesRequestWrap {\n"
-      + "  bytes value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message bytesResponseWrap200 {\n"
-      + "  bytes value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message colorBodyRequestWrap {\n"
-      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 color = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message colorBodyResponseWrap200 {\n"
-      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message listObjRequestWrap {\n"
-      + "  repeated google.protobuf.Any objs = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message listObjResponseWrap200 {\n"
-      + "  repeated google.protobuf.Any value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message listUserRequestWrap {\n"
-      + "  repeated User users = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message listUserResponseWrap200 {\n"
-      + "  repeated User value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message mapObjRequestWrap {\n"
-      + "  map<string, google.protobuf.Any> objs = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message mapObjResponseWrap200 {\n"
-      + "  map<string, google.protobuf.Any> value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message mapUserRequestWrap {\n"
-      + "  map<string, User> users = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapProperty\n"
-      + "message mapUserResponseWrap200 {\n"
-      + "  map<string, User> value = 1;\n"
-      + "}\n"
-      + "\n"
-      + "//@WrapArguments\n"
-      + "message userWrapInProtobufRequestWrap {\n"
-      + "  User user = 1;\n"
-      + "  int32 ivalue = 2;\n"
-      + "}\n"
-      + "\n"
-      + "enum Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 {\n"
-      + "  RED = 0;\n"
-      + "  YELLOW = 1;\n"
-      + "  BLUE = 2;\n"
-      + "}\n"
-      + "\n"
-      + "service MainService {\n"
-      + "  //@Rpc{\"argTypeName\":\"baseRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"baseResponseWrap200\"},\"444\":{\"typeName\":\"baseResponseWrap444\"}}}\n"
-      + "  rpc base (baseRequestWrap) returns (baseResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"bytesRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"bytesResponseWrap200\"}}}\n"
-      + "  rpc bytes (bytesRequestWrap) returns (bytesResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"colorBodyRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"colorBodyResponseWrap200\"}}}\n"
-      + "  rpc colorBody (colorBodyRequestWrap) returns (colorBodyResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"listObjRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"listObjResponseWrap200\"}}}\n"
-      + "  rpc listObj (listObjRequestWrap) returns (listObjResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"listUserRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"listUserResponseWrap200\"}}}\n"
-      + "  rpc listUser (listUserRequestWrap) returns (listUserResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"mapObjRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"mapObjResponseWrap200\"}}}\n"
-      + "  rpc mapObj (mapObjRequestWrap) returns (mapObjResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"mapUserRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"mapUserResponseWrap200\"}}}\n"
-      + "  rpc mapUser (mapUserRequestWrap) returns (mapUserResponseWrap200);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"google.protobuf.Empty\",\"responses\":{\"200\":{\"typeName\":\"google.protobuf.Empty\"}}}\n"
-      + "  rpc noParamVoid (google.protobuf.Empty) returns (google.protobuf.Empty);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"google.protobuf.Any\",\"responses\":{\"200\":{\"typeName\":\"google.protobuf.Any\"}}}\n"
-      + "  rpc obj (google.protobuf.Any) returns (google.protobuf.Any);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"Ref1\",\"responses\":{\"200\":{\"typeName\":\"Ref2\"}}}\n"
-      + "  rpc ref (Ref1) returns (Ref2);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"User\",\"responses\":{\"200\":{\"typeName\":\"User\"}}}\n"
-      + "  rpc user (User) returns (User);\n"
-      + "\n"
-      + "  //@Rpc{\"argTypeName\":\"userWrapInProtobufRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"User\"}}}\n"
-      + "  rpc userWrapInProtobuf (userWrapInProtobufRequestWrap) returns (User);\n"
-      + "}\n";
-
   @Test
-  public void convert() {
+  public void convert() throws IOException {
+    URL url = TestSwaggerToProtoGenerator.class.getClassLoader().getResource("ProtoSchema.proto");
+    String protoContent = IOUtils.toString(url);
+    int idx = protoContent.indexOf("syntax = ");
+    protoContent = protoContent.substring(idx);
+
     SwaggerGeneratorContext context = new SpringmvcSwaggerGeneratorContext();
     SwaggerGenerator swaggerGenerator = new SwaggerGenerator(context, ProtoSchema.class);
     Swagger swagger = swaggerGenerator.generate();
diff --git a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/FieldNeedWrap.java b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/FieldNeedWrap.java
new file mode 100644
index 0000000..f97b6b5
--- /dev/null
+++ b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/FieldNeedWrap.java
@@ -0,0 +1,44 @@
+/*
+ * 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.servicecomb.codec.protobuf.internal.converter.model;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.test.scaffolding.model.User;
+
+public class FieldNeedWrap {
+  public List<List<User>> listListUser;
+
+  public List<Map<String, User>> listMapUser;
+
+  public Map<String, List<User>> mapListUser;
+
+  public Map<String, Map<String, User>> mapMapUser;
+
+  public List<List<List<User>>> listListListUser;
+
+  public List<List<Map<String, User>>> listListMapUser;
+
+  public List<Map<String, List<User>>> listMapListUser;
+
+  public List<Map<String, Map<String, User>>> listMapMapUser;
+
+  public Map<String, Map<String, List<User>>> mapMapListUser;
+
+  public Map<String, Map<String, Map<String, User>>> mapMapMapUser;
+}
diff --git a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/ProtoSchema.java b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/ProtoSchema.java
index 3b046ec..64afea6 100644
--- a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/ProtoSchema.java
+++ b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/model/ProtoSchema.java
@@ -26,6 +26,7 @@ import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
 import org.apache.servicecomb.foundation.test.scaffolding.model.Empty;
 import org.apache.servicecomb.foundation.test.scaffolding.model.User;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
@@ -95,4 +96,82 @@ public class ProtoSchema {
   @GetMapping(path = "/noParamVoid")
   public void noParamVoid() {
   }
+
+  @PostMapping(path = "/listListString")
+  public List<List<String>> listListString(@RequestBody List<List<String>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listListUser")
+  public List<List<User>> listListUser(@RequestBody List<List<User>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listMapString")
+  public List<Map<String, String>> listMapString(@RequestBody List<Map<String, String>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listMapUser")
+  public List<Map<String, User>> listMapUser(@RequestBody List<Map<String, User>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/mapListString")
+  public Map<String, List<String>> mapListString(@RequestBody Map<String, List<String>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/mapListUser")
+  public Map<String, List<User>> mapListUser(@RequestBody Map<String, List<User>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/mapMapString")
+  public Map<String, Map<String, String>> mapMapString(@RequestBody Map<String, Map<String, String>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/mapMapUser")
+  public Map<String, Map<String, User>> mapMapUser(@RequestBody Map<String, Map<String, User>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listListListString")
+  public List<List<List<String>>> listListListString(@RequestBody List<List<List<String>>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listListMapString")
+  public List<List<Map<String, String>>> listListMapString(@RequestBody List<List<Map<String, String>>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listMapListString")
+  public List<Map<String, List<String>>> listMapListString(@RequestBody List<Map<String, List<String>>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/listMapMapString")
+  public List<Map<String, Map<String, String>>> listMapMapString(
+      @RequestBody List<Map<String, Map<String, String>>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/mapMapListString")
+  public Map<String, Map<String, List<String>>> mapMapListString(
+      @RequestBody Map<String, Map<String, List<String>>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/mapMapMapString")
+  public Map<String, Map<String, Map<String, String>>> mapMapMapString(
+      @RequestBody Map<String, Map<String, Map<String, String>>> value) {
+    return value;
+  }
+
+  @PostMapping(path = "/fieldNeedWrap")
+  public FieldNeedWrap fieldNeedWrap(@RequestBody FieldNeedWrap fieldNeedWrap) {
+    return fieldNeedWrap;
+  }
 }
diff --git a/common/common-protobuf/src/test/resources/ProtoSchema.proto b/common/common-protobuf/src/test/resources/ProtoSchema.proto
new file mode 100644
index 0000000..cb78e18
--- /dev/null
+++ b/common/common-protobuf/src/test/resources/ProtoSchema.proto
@@ -0,0 +1,430 @@
+/*
+  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.
+ */
+
+syntax = "proto3";
+import "google/protobuf/empty.proto";
+import "google/protobuf/any.proto";
+package a.b;
+
+message Empty {
+}
+
+message FieldNeedWrap {
+  repeated ListUser listListUser = 1;
+  repeated MapUser listMapUser = 2;
+  map<string, ListUser> mapListUser = 3;
+  map<string, MapUser> mapMapUser = 4;
+  repeated ListListUser listListListUser = 5;
+  repeated ListMapUser listListMapUser = 6;
+  repeated MapListUser listMapListUser = 7;
+  repeated MapMapUser listMapMapUser = 8;
+  map<string, MapListUser> mapMapListUser = 9;
+  map<string, MapMapUser> mapMapMapUser = 10;
+}
+
+message User {
+  string name = 1;
+  repeated User friends = 2;
+}
+
+message Ref1 {
+  Ref2 ref = 1;
+}
+
+message Ref2 {
+  Ref1 ref = 1;
+}
+
+//@WrapArguments
+message BaseRequestWrap {
+  bool boolValue = 1;
+  int32 iValue = 2;
+  int64 lValue = 3;
+  float fValue = 4;
+  double dValue = 5;
+  string sValue = 6;
+  repeated int32 iArray = 7;
+  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 color = 8;
+  int64 localDate = 9;
+  int64 date = 10;
+  Empty empty = 11;
+}
+
+//@WrapProperty
+message BaseResponseWrap444 {
+  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 value = 1;
+}
+
+//@WrapProperty
+message BaseResponseWrap200 {
+  int32 value = 1;
+}
+
+//@WrapArguments
+message BytesRequestWrap {
+  bytes value = 1;
+}
+
+//@WrapProperty
+message BytesResponseWrap200 {
+  bytes value = 1;
+}
+
+//@WrapArguments
+message ColorBodyRequestWrap {
+  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 color = 1;
+}
+
+//@WrapProperty
+message ColorBodyResponseWrap200 {
+  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 value = 1;
+}
+
+//@WrapArguments
+message ListListListStringRequestWrap {
+  repeated ListListString value = 1;
+}
+
+//@WrapProperty
+message ListListListStringResponseWrap200 {
+  repeated ListListString value = 1;
+}
+
+//@WrapArguments
+message ListListMapStringRequestWrap {
+  repeated ListMapString value = 1;
+}
+
+//@WrapProperty
+message ListListMapStringResponseWrap200 {
+  repeated ListMapString value = 1;
+}
+
+//@WrapArguments
+message ListListStringRequestWrap {
+  repeated ListString value = 1;
+}
+
+//@WrapProperty
+message ListListStringResponseWrap200 {
+  repeated ListString value = 1;
+}
+
+//@WrapArguments
+message ListListUserRequestWrap {
+  repeated ListUser value = 1;
+}
+
+//@WrapProperty
+message ListListUserResponseWrap200 {
+  repeated ListUser value = 1;
+}
+
+//@WrapArguments
+message ListMapListStringRequestWrap {
+  repeated MapListString value = 1;
+}
+
+//@WrapProperty
+message ListMapListStringResponseWrap200 {
+  repeated MapListString value = 1;
+}
+
+//@WrapArguments
+message ListMapMapStringRequestWrap {
+  repeated MapMapString value = 1;
+}
+
+//@WrapProperty
+message ListMapMapStringResponseWrap200 {
+  repeated MapMapString value = 1;
+}
+
+//@WrapArguments
+message ListMapStringRequestWrap {
+  repeated MapString value = 1;
+}
+
+//@WrapProperty
+message ListMapStringResponseWrap200 {
+  repeated MapString value = 1;
+}
+
+//@WrapArguments
+message ListMapUserRequestWrap {
+  repeated MapUser value = 1;
+}
+
+//@WrapProperty
+message ListMapUserResponseWrap200 {
+  repeated MapUser value = 1;
+}
+
+//@WrapArguments
+message ListObjRequestWrap {
+  repeated google.protobuf.Any objs = 1;
+}
+
+//@WrapProperty
+message ListObjResponseWrap200 {
+  repeated google.protobuf.Any value = 1;
+}
+
+//@WrapArguments
+message ListUserRequestWrap {
+  repeated User users = 1;
+}
+
+//@WrapProperty
+message ListUserResponseWrap200 {
+  repeated User value = 1;
+}
+
+//@WrapArguments
+message MapListStringRequestWrap {
+  map<string, ListString> value = 1;
+}
+
+//@WrapProperty
+message MapListStringResponseWrap200 {
+  map<string, ListString> value = 1;
+}
+
+//@WrapArguments
+message MapListUserRequestWrap {
+  map<string, ListUser> value = 1;
+}
+
+//@WrapProperty
+message MapListUserResponseWrap200 {
+  map<string, ListUser> value = 1;
+}
+
+//@WrapArguments
+message MapMapListStringRequestWrap {
+  map<string, MapListString> value = 1;
+}
+
+//@WrapProperty
+message MapMapListStringResponseWrap200 {
+  map<string, MapListString> value = 1;
+}
+
+//@WrapArguments
+message MapMapMapStringRequestWrap {
+  map<string, MapMapString> value = 1;
+}
+
+//@WrapProperty
+message MapMapMapStringResponseWrap200 {
+  map<string, MapMapString> value = 1;
+}
+
+//@WrapArguments
+message MapMapStringRequestWrap {
+  map<string, MapString> value = 1;
+}
+
+//@WrapProperty
+message MapMapStringResponseWrap200 {
+  map<string, MapString> value = 1;
+}
+
+//@WrapArguments
+message MapMapUserRequestWrap {
+  map<string, MapUser> value = 1;
+}
+
+//@WrapProperty
+message MapMapUserResponseWrap200 {
+  map<string, MapUser> value = 1;
+}
+
+//@WrapArguments
+message MapObjRequestWrap {
+  map<string, google.protobuf.Any> objs = 1;
+}
+
+//@WrapProperty
+message MapObjResponseWrap200 {
+  map<string, google.protobuf.Any> value = 1;
+}
+
+//@WrapArguments
+message MapUserRequestWrap {
+  map<string, User> users = 1;
+}
+
+//@WrapProperty
+message MapUserResponseWrap200 {
+  map<string, User> value = 1;
+}
+
+//@WrapArguments
+message UserWrapInProtobufRequestWrap {
+  User user = 1;
+  int32 ivalue = 2;
+}
+
+//@WrapProperty
+message ListUser {
+  repeated User value = 1;
+}
+
+//@WrapProperty
+message MapUser {
+  map<string, User> value = 1;
+}
+
+//@WrapProperty
+message ListListUser {
+  repeated ListUser value = 1;
+}
+
+//@WrapProperty
+message ListMapUser {
+  repeated MapUser value = 1;
+}
+
+//@WrapProperty
+message MapListUser {
+  map<string, ListUser> value = 1;
+}
+
+//@WrapProperty
+message MapMapUser {
+  map<string, MapUser> value = 1;
+}
+
+//@WrapProperty
+message ListListString {
+  repeated ListString value = 1;
+}
+
+//@WrapProperty
+message ListMapString {
+  repeated MapString value = 1;
+}
+
+//@WrapProperty
+message ListString {
+  repeated string value = 1;
+}
+
+//@WrapProperty
+message MapListString {
+  map<string, ListString> value = 1;
+}
+
+//@WrapProperty
+message MapMapString {
+  map<string, MapString> value = 1;
+}
+
+//@WrapProperty
+message MapString {
+  map<string, string> value = 1;
+}
+
+enum Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 {
+  RED = 0;
+  YELLOW = 1;
+  BLUE = 2;
+}
+
+service MainService {
+  //@Rpc{"argTypeName":"BaseRequestWrap","responses":{"200":{"typeName":"BaseResponseWrap200"},"444":{"typeName":"BaseResponseWrap444"}}}
+  rpc base (BaseRequestWrap) returns (BaseResponseWrap200);
+
+  //@Rpc{"argTypeName":"BytesRequestWrap","responses":{"200":{"typeName":"BytesResponseWrap200"}}}
+  rpc bytes (BytesRequestWrap) returns (BytesResponseWrap200);
+
+  //@Rpc{"argTypeName":"ColorBodyRequestWrap","responses":{"200":{"typeName":"ColorBodyResponseWrap200"}}}
+  rpc colorBody (ColorBodyRequestWrap) returns (ColorBodyResponseWrap200);
+
+  //@Rpc{"argTypeName":"FieldNeedWrap","responses":{"200":{"typeName":"FieldNeedWrap"}}}
+  rpc fieldNeedWrap (FieldNeedWrap) returns (FieldNeedWrap);
+
+  //@Rpc{"argTypeName":"ListListListStringRequestWrap","responses":{"200":{"typeName":"ListListListStringResponseWrap200"}}}
+  rpc listListListString (ListListListStringRequestWrap) returns (ListListListStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListListMapStringRequestWrap","responses":{"200":{"typeName":"ListListMapStringResponseWrap200"}}}
+  rpc listListMapString (ListListMapStringRequestWrap) returns (ListListMapStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListListStringRequestWrap","responses":{"200":{"typeName":"ListListStringResponseWrap200"}}}
+  rpc listListString (ListListStringRequestWrap) returns (ListListStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListListUserRequestWrap","responses":{"200":{"typeName":"ListListUserResponseWrap200"}}}
+  rpc listListUser (ListListUserRequestWrap) returns (ListListUserResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListMapListStringRequestWrap","responses":{"200":{"typeName":"ListMapListStringResponseWrap200"}}}
+  rpc listMapListString (ListMapListStringRequestWrap) returns (ListMapListStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListMapMapStringRequestWrap","responses":{"200":{"typeName":"ListMapMapStringResponseWrap200"}}}
+  rpc listMapMapString (ListMapMapStringRequestWrap) returns (ListMapMapStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListMapStringRequestWrap","responses":{"200":{"typeName":"ListMapStringResponseWrap200"}}}
+  rpc listMapString (ListMapStringRequestWrap) returns (ListMapStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListMapUserRequestWrap","responses":{"200":{"typeName":"ListMapUserResponseWrap200"}}}
+  rpc listMapUser (ListMapUserRequestWrap) returns (ListMapUserResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListObjRequestWrap","responses":{"200":{"typeName":"ListObjResponseWrap200"}}}
+  rpc listObj (ListObjRequestWrap) returns (ListObjResponseWrap200);
+
+  //@Rpc{"argTypeName":"ListUserRequestWrap","responses":{"200":{"typeName":"ListUserResponseWrap200"}}}
+  rpc listUser (ListUserRequestWrap) returns (ListUserResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapListStringRequestWrap","responses":{"200":{"typeName":"MapListStringResponseWrap200"}}}
+  rpc mapListString (MapListStringRequestWrap) returns (MapListStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapListUserRequestWrap","responses":{"200":{"typeName":"MapListUserResponseWrap200"}}}
+  rpc mapListUser (MapListUserRequestWrap) returns (MapListUserResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapMapListStringRequestWrap","responses":{"200":{"typeName":"MapMapListStringResponseWrap200"}}}
+  rpc mapMapListString (MapMapListStringRequestWrap) returns (MapMapListStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapMapMapStringRequestWrap","responses":{"200":{"typeName":"MapMapMapStringResponseWrap200"}}}
+  rpc mapMapMapString (MapMapMapStringRequestWrap) returns (MapMapMapStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapMapStringRequestWrap","responses":{"200":{"typeName":"MapMapStringResponseWrap200"}}}
+  rpc mapMapString (MapMapStringRequestWrap) returns (MapMapStringResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapMapUserRequestWrap","responses":{"200":{"typeName":"MapMapUserResponseWrap200"}}}
+  rpc mapMapUser (MapMapUserRequestWrap) returns (MapMapUserResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapObjRequestWrap","responses":{"200":{"typeName":"MapObjResponseWrap200"}}}
+  rpc mapObj (MapObjRequestWrap) returns (MapObjResponseWrap200);
+
+  //@Rpc{"argTypeName":"MapUserRequestWrap","responses":{"200":{"typeName":"MapUserResponseWrap200"}}}
+  rpc mapUser (MapUserRequestWrap) returns (MapUserResponseWrap200);
+
+  //@Rpc{"argTypeName":"google.protobuf.Empty","responses":{"200":{"typeName":"google.protobuf.Empty"}}}
+  rpc noParamVoid (google.protobuf.Empty) returns (google.protobuf.Empty);
+
+  //@Rpc{"argTypeName":"google.protobuf.Any","responses":{"200":{"typeName":"google.protobuf.Any"}}}
+  rpc obj (google.protobuf.Any) returns (google.protobuf.Any);
+
+  //@Rpc{"argTypeName":"Ref1","responses":{"200":{"typeName":"Ref2"}}}
+  rpc ref (Ref1) returns (Ref2);
+
+  //@Rpc{"argTypeName":"User","responses":{"200":{"typeName":"User"}}}
+  rpc user (User) returns (User);
+
+  //@Rpc{"argTypeName":"UserWrapInProtobufRequestWrap","responses":{"200":{"typeName":"User"}}}
+  rpc userWrapInProtobuf (UserWrapInProtobufRequestWrap) returns (User);
+}


[servicecomb-java-chassis] 01/03: [SCB-945] use annotation format to declare additional information

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit ad0ee204b593c75fe5b22480b78b8e397170503e
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Nov 30 22:12:57 2018 +0800

    [SCB-945] use annotation format to declare additional information
---
 .../protobuf/internal/converter/ProtoMethod.java   | 10 ----
 .../protobuf/internal/converter/ProtoResponse.java | 10 ----
 .../internal/converter/ProtoToStringGenerator.java | 21 ++++++-
 .../converter/SwaggerToProtoGenerator.java         | 53 +++++++++--------
 .../internal/converter/SwaggerTypeAdapter.java     |  4 ++
 .../converter/TestSwaggerToProtoGenerator.java     | 66 ++++++++++++----------
 .../foundation/protobuf/internal/ProtoConst.java   |  4 +-
 7 files changed, 92 insertions(+), 76 deletions(-)

diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoMethod.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoMethod.java
index 4ae87ae..e8d8a09 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoMethod.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoMethod.java
@@ -28,8 +28,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 public class ProtoMethod {
   private String argTypeName;
 
-  private boolean argWrapped;
-
   @JsonProperty
   // key is status
   private Map<Integer, ProtoResponse> responses = new HashMap<>();
@@ -44,14 +42,6 @@ public class ProtoMethod {
     this.argTypeName = argTypeName;
   }
 
-  public boolean isArgWrapped() {
-    return argWrapped;
-  }
-
-  public void setArgWrapped(boolean argWrapped) {
-    this.argWrapped = argWrapped;
-  }
-
   public void addResponse(String status, ProtoResponse response) {
     if (status.equals("default")) {
       defaultResponse = response;
diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoResponse.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoResponse.java
index feaa406..19510f6 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoResponse.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoResponse.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.codec.protobuf.internal.converter;
 public class ProtoResponse {
   private String typeName;
 
-  private boolean wrapped;
-
   public String getTypeName() {
     return typeName;
   }
@@ -28,12 +26,4 @@ public class ProtoResponse {
   public void setTypeName(String typeName) {
     this.typeName = typeName;
   }
-
-  public boolean isWrapped() {
-    return wrapped;
-  }
-
-  public void setWrapped(boolean wrapped) {
-    this.wrapped = wrapped;
-  }
 }
diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoToStringGenerator.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoToStringGenerator.java
index 4e1b9ed..589cad8 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoToStringGenerator.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/ProtoToStringGenerator.java
@@ -18,6 +18,10 @@ package org.apache.servicecomb.codec.protobuf.internal.converter;
 
 import static org.apache.servicecomb.foundation.common.utils.StringBuilderUtils.appendLine;
 
+import java.util.List;
+
+import com.google.common.base.Strings;
+
 import io.protostuff.compiler.model.Enum;
 import io.protostuff.compiler.model.EnumConstant;
 import io.protostuff.compiler.model.Field;
@@ -59,9 +63,7 @@ public class ProtoToStringGenerator {
   private void serviceToString(Service service, StringBuilder sb) {
     appendLine(sb, "service %s {", service.getName());
     for (ServiceMethod serviceMethod : service.getMethods()) {
-      if (!serviceMethod.getCommentLines().isEmpty()) {
-        appendLine(sb, "  //" + serviceMethod.getComments());
-      }
+      commentsToString(serviceMethod.getCommentLines(), sb, 2);
       appendLine(sb, "  rpc %s (%s) returns (%s);\n", serviceMethod.getName(), serviceMethod.getArgTypeName(),
           serviceMethod.getReturnTypeName());
     }
@@ -79,7 +81,20 @@ public class ProtoToStringGenerator {
     sb.append("}\n\n");
   }
 
+  private void commentsToString(List<String> comments, StringBuilder sb, int padLeft) {
+    if (comments.isEmpty()) {
+      return;
+    }
+
+    String pad = Strings.repeat(" ", padLeft) + "//";
+    for (String comment : comments) {
+      sb.append(pad);
+      appendLine(sb, comment);
+    }
+  }
+
   private void messageToString(Message message, StringBuilder sb) {
+    commentsToString(message.getCommentLines(), sb, 0);
     appendLine(sb, "message %s {", message.getName());
     for (Field field : message.getFields()) {
       sb.append("  ");
diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java
index cd8942a..8980c1f 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerToProtoGenerator.java
@@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -89,6 +90,7 @@ public class SwaggerToProtoGenerator {
     }
   }
 
+  @SuppressWarnings("unchecked")
   private void convertDefinition(String modelName, ModelImpl model) {
     Map<String, Property> properties = model.getProperties();
     if (properties == null) {
@@ -96,12 +98,23 @@ public class SwaggerToProtoGenerator {
       properties = Collections.emptyMap();
     }
 
-    // complex
-    messages.add(modelName);
-    appendLine(msgStringBuilder, "message %s {", modelName);
+    createMessage(modelName, (Map<String, Object>) (Object) properties);
+  }
+
+  private void createMessage(String protoName, Map<String, Object> properties, String... annotations) {
+    if (!messages.add(protoName)) {
+      // already created
+      return;
+    }
+
+    for (String annotation : annotations) {
+      msgStringBuilder.append("//");
+      appendLine(msgStringBuilder, annotation);
+    }
+    appendLine(msgStringBuilder, "message %s {", protoName);
     int tag = 1;
-    for (Entry<String, Property> entry : properties.entrySet()) {
-      Property property = entry.getValue();
+    for (Entry<String, Object> entry : properties.entrySet()) {
+      Object property = entry.getValue();
       String propertyType = convertSwaggerType(property);
 
       appendLine(msgStringBuilder, "  %s %s = %d;", propertyType, entry.getKey(), tag);
@@ -160,6 +173,10 @@ public class SwaggerToProtoGenerator {
             Json.encode(swaggerType)));
   }
 
+  private void wrapPropertyToMessage(String protoName, Property property) {
+    createMessage(protoName, Collections.singletonMap("value", property), ProtoConst.ANNOTATION_WRAP_PROPERTY);
+  }
+
   private String tryFindEnumType(List<String> enums) {
     if (enums != null && !enums.isEmpty()) {
       String strEnums = enums.toString();
@@ -225,19 +242,19 @@ public class SwaggerToProtoGenerator {
     appendLine(serviceBuilder, "service MainService {");
     for (Path path : paths.values()) {
       for (Operation operation : path.getOperationMap().values()) {
-        convertOpeation(operation);
+        convertOperation(operation);
       }
     }
     serviceBuilder.setLength(serviceBuilder.length() - 1);
     appendLine(serviceBuilder, "}");
   }
 
-  private void convertOpeation(Operation operation) {
+  private void convertOperation(Operation operation) {
     ProtoMethod protoMethod = new ProtoMethod();
     fillRequestType(operation, protoMethod);
     fillResponseType(operation, protoMethod);
 
-    appendLine(serviceBuilder, "  //%s%s", ProtoConst.OP_HINT, Json.encode(protoMethod));
+    appendLine(serviceBuilder, "  //%s%s", ProtoConst.ANNOTATION_RPC, Json.encode(protoMethod));
     appendLine(serviceBuilder, "  rpc %s (%s) returns (%s);\n", operation.getOperationId(),
         protoMethod.getArgTypeName(),
         protoMethod.findResponse(Status.OK.getStatusCode()).getTypeName());
@@ -262,23 +279,20 @@ public class SwaggerToProtoGenerator {
     String wrapName = operation.getOperationId() + "RequestWrap";
     createWrapArgs(wrapName, parameters);
 
-    protoMethod.setArgWrapped(true);
     protoMethod.setArgTypeName(wrapName);
   }
 
   private void fillResponseType(Operation operation, ProtoMethod protoMethod) {
     for (Entry<String, Response> entry : operation.getResponses().entrySet()) {
       String type = convertSwaggerType(entry.getValue().getSchema());
+      boolean wrapped = !messages.contains(type);
 
       ProtoResponse protoResponse = new ProtoResponse();
-      protoResponse.setWrapped(!messages.contains(type));
       protoResponse.setTypeName(type);
 
-      if (protoResponse.isWrapped()) {
+      if (wrapped) {
         String wrapName = operation.getOperationId() + "ResponseWrap" + entry.getKey();
-        appendLine(msgStringBuilder, "message %s {", wrapName);
-        appendLine(msgStringBuilder, "  %s response = 1;", type);
-        appendLine(msgStringBuilder, "}");
+        wrapPropertyToMessage(wrapName, entry.getValue().getSchema());
 
         protoResponse.setTypeName(wrapName);
       }
@@ -287,16 +301,11 @@ public class SwaggerToProtoGenerator {
   }
 
   private void createWrapArgs(String wrapName, List<Parameter> parameters) {
-    appendLine(msgStringBuilder, "message %s {", wrapName);
-
-    int idx = 1;
+    Map<String, Object> properties = new LinkedHashMap<>();
     for (Parameter parameter : parameters) {
-      String type = convertSwaggerType(parameter);
-      appendLine(msgStringBuilder, "  %s %s = %d;", type, parameter.getName(), idx);
-      idx++;
+      properties.put(parameter.getName(), parameter);
     }
-
-    appendLine(msgStringBuilder, "}");
+    createMessage(wrapName, properties, ProtoConst.ANNOTATION_WRAP_ARGUMENTS);
   }
 
   protected Proto createProto() {
diff --git a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerTypeAdapter.java b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerTypeAdapter.java
index 235ebe8..dacaf6d 100644
--- a/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerTypeAdapter.java
+++ b/common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/internal/converter/SwaggerTypeAdapter.java
@@ -24,6 +24,10 @@ import io.swagger.models.properties.Property;
 
 public interface SwaggerTypeAdapter {
   static SwaggerTypeAdapter create(Object swaggerType) {
+    if (swaggerType instanceof SwaggerTypeAdapter) {
+      return (SwaggerTypeAdapter) swaggerType;
+    }
+
     if (swaggerType instanceof Property) {
       return new PropertyAdapter((Property) swaggerType);
     }
diff --git a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java
index 4b604a4..be61f2f 100644
--- a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java
+++ b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/internal/converter/TestSwaggerToProtoGenerator.java
@@ -17,7 +17,6 @@
 package org.apache.servicecomb.codec.protobuf.internal.converter;
 
 import org.apache.servicecomb.codec.protobuf.internal.converter.model.ProtoSchema;
-import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
 import org.apache.servicecomb.swagger.generator.core.SwaggerGenerator;
 import org.apache.servicecomb.swagger.generator.core.SwaggerGeneratorContext;
 import org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGeneratorContext;
@@ -26,7 +25,6 @@ import org.junit.Test;
 
 import io.protostuff.compiler.model.Proto;
 import io.swagger.models.Swagger;
-import io.vertx.core.json.Json;
 
 public class TestSwaggerToProtoGenerator {
   static String protoContent = "syntax = \"proto3\";\n"
@@ -50,6 +48,7 @@ public class TestSwaggerToProtoGenerator {
       + "  Ref1 ref = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message baseRequestWrap {\n"
       + "  bool boolValue = 1;\n"
       + "  int32 iValue = 2;\n"
@@ -64,62 +63,77 @@ public class TestSwaggerToProtoGenerator {
       + "  Empty empty = 11;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message baseResponseWrap444 {\n"
-      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 response = 1;\n"
+      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message baseResponseWrap200 {\n"
-      + "  int32 response = 1;\n"
+      + "  int32 value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message bytesRequestWrap {\n"
       + "  bytes value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message bytesResponseWrap200 {\n"
-      + "  bytes response = 1;\n"
+      + "  bytes value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message colorBodyRequestWrap {\n"
       + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 color = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message colorBodyResponseWrap200 {\n"
-      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 response = 1;\n"
+      + "  Enum_2610aa5dc6cd086cf20168892802c9c765a557f4951557340ad9f0982c53e055 value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message listObjRequestWrap {\n"
       + "  repeated google.protobuf.Any objs = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message listObjResponseWrap200 {\n"
-      + "  repeated google.protobuf.Any response = 1;\n"
+      + "  repeated google.protobuf.Any value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message listUserRequestWrap {\n"
       + "  repeated User users = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message listUserResponseWrap200 {\n"
-      + "  repeated User response = 1;\n"
+      + "  repeated User value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message mapObjRequestWrap {\n"
       + "  map<string, google.protobuf.Any> objs = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message mapObjResponseWrap200 {\n"
-      + "  map<string, google.protobuf.Any> response = 1;\n"
+      + "  map<string, google.protobuf.Any> value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message mapUserRequestWrap {\n"
       + "  map<string, User> users = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapProperty\n"
       + "message mapUserResponseWrap200 {\n"
-      + "  map<string, User> response = 1;\n"
+      + "  map<string, User> value = 1;\n"
       + "}\n"
       + "\n"
+      + "//@WrapArguments\n"
       + "message userWrapInProtobufRequestWrap {\n"
       + "  User user = 1;\n"
       + "  int32 ivalue = 2;\n"
@@ -132,40 +146,40 @@ public class TestSwaggerToProtoGenerator {
       + "}\n"
       + "\n"
       + "service MainService {\n"
-      + "  //scb:{\"argTypeName\":\"baseRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"baseResponseWrap200\",\"wrapped\":true},\"444\":{\"typeName\":\"baseResponseWrap444\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"baseRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"baseResponseWrap200\"},\"444\":{\"typeName\":\"baseResponseWrap444\"}}}\n"
       + "  rpc base (baseRequestWrap) returns (baseResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"bytesRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"bytesResponseWrap200\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"bytesRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"bytesResponseWrap200\"}}}\n"
       + "  rpc bytes (bytesRequestWrap) returns (bytesResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"colorBodyRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"colorBodyResponseWrap200\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"colorBodyRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"colorBodyResponseWrap200\"}}}\n"
       + "  rpc colorBody (colorBodyRequestWrap) returns (colorBodyResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"listObjRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"listObjResponseWrap200\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"listObjRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"listObjResponseWrap200\"}}}\n"
       + "  rpc listObj (listObjRequestWrap) returns (listObjResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"listUserRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"listUserResponseWrap200\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"listUserRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"listUserResponseWrap200\"}}}\n"
       + "  rpc listUser (listUserRequestWrap) returns (listUserResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"mapObjRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"mapObjResponseWrap200\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"mapObjRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"mapObjResponseWrap200\"}}}\n"
       + "  rpc mapObj (mapObjRequestWrap) returns (mapObjResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"mapUserRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"mapUserResponseWrap200\",\"wrapped\":true}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"mapUserRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"mapUserResponseWrap200\"}}}\n"
       + "  rpc mapUser (mapUserRequestWrap) returns (mapUserResponseWrap200);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"google.protobuf.Empty\",\"argWrapped\":false,\"responses\":{\"200\":{\"typeName\":\"google.protobuf.Empty\",\"wrapped\":false}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"google.protobuf.Empty\",\"responses\":{\"200\":{\"typeName\":\"google.protobuf.Empty\"}}}\n"
       + "  rpc noParamVoid (google.protobuf.Empty) returns (google.protobuf.Empty);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"google.protobuf.Any\",\"argWrapped\":false,\"responses\":{\"200\":{\"typeName\":\"google.protobuf.Any\",\"wrapped\":false}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"google.protobuf.Any\",\"responses\":{\"200\":{\"typeName\":\"google.protobuf.Any\"}}}\n"
       + "  rpc obj (google.protobuf.Any) returns (google.protobuf.Any);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"Ref1\",\"argWrapped\":false,\"responses\":{\"200\":{\"typeName\":\"Ref2\",\"wrapped\":false}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"Ref1\",\"responses\":{\"200\":{\"typeName\":\"Ref2\"}}}\n"
       + "  rpc ref (Ref1) returns (Ref2);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"User\",\"argWrapped\":false,\"responses\":{\"200\":{\"typeName\":\"User\",\"wrapped\":false}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"User\",\"responses\":{\"200\":{\"typeName\":\"User\"}}}\n"
       + "  rpc user (User) returns (User);\n"
       + "\n"
-      + "  //scb:{\"argTypeName\":\"userWrapInProtobufRequestWrap\",\"argWrapped\":true,\"responses\":{\"200\":{\"typeName\":\"User\",\"wrapped\":false}}}\n"
+      + "  //@Rpc{\"argTypeName\":\"userWrapInProtobufRequestWrap\",\"responses\":{\"200\":{\"typeName\":\"User\"}}}\n"
       + "  rpc userWrapInProtobuf (userWrapInProtobufRequestWrap) returns (User);\n"
       + "}\n";
 
@@ -180,12 +194,4 @@ public class TestSwaggerToProtoGenerator {
 
     Assert.assertEquals(protoContent, new ProtoToStringGenerator(proto).protoToString());
   }
-
-  public static void main(String[] args) {
-    String json = Json.encode(Color.BLUE);
-    System.out.println(json);
-    System.out.println(Json.decodeValue(json, Color.class));
-    System.out.println(Json.decodeValue("2", Color.class));
-    System.out.println(Json.mapper.convertValue("BLUE", Color.class));
-  }
 }
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java
index 8d5b1d6..cc2c0ba 100644
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java
@@ -31,9 +31,11 @@ public final class ProtoConst {
   private ProtoConst() {
   }
 
+  public static String ANNOTATION_WRAP_ARGUMENTS = "@WrapArguments";
+
   public static String ANNOTATION_WRAP_PROPERTY = "@WrapProperty";
 
-  public static String OP_HINT = " scb:";
+  public static String ANNOTATION_RPC = "@Rpc";
 
   public static String PACK_SCHEMA = "type.googleapis.com/";
 


[servicecomb-java-chassis] 03/03: [SCB-945] update protostuff license

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit 15b0657e84026a68969ae9cef28d3fe8be0c5104
Author: wujimin <wu...@huawei.com>
AuthorDate: Mon Jan 14 16:56:01 2019 +0800

    [SCB-945] update protostuff license
---
 LICENSE                                       | 2 +-
 java-chassis-distribution/src/release/LICENSE | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/LICENSE b/LICENSE
index 3ab3057..a1e780b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -240,7 +240,7 @@ For foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/ArrayFie
     foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/FieldSchema.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/FieldTypeUtils.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/HashFieldMapEx.java
-    foundations/foundation-protobuf/src/main/java/io/protostuff/ByteBufferInputEx.java
+    foundations/foundation-protobuf/src/main/java/io/protostuff/ByteArrayInputEx.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/InputEx.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/OutputEx.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/package-info.java
diff --git a/java-chassis-distribution/src/release/LICENSE b/java-chassis-distribution/src/release/LICENSE
index ed05846..5e1070c 100644
--- a/java-chassis-distribution/src/release/LICENSE
+++ b/java-chassis-distribution/src/release/LICENSE
@@ -392,7 +392,7 @@ For foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/ArrayFie
     foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/FieldSchema.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/FieldTypeUtils.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/runtime/HashFieldMapEx.java
-    foundations/foundation-protobuf/src/main/java/io/protostuff/ByteBufferInputEx.java
+    foundations/foundation-protobuf/src/main/java/io/protostuff/ByteArrayInputEx.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/InputEx.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/OutputEx.java
     foundations/foundation-protobuf/src/main/java/io/protostuff/package-info.java