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 2018/01/12 01:19:10 UTC

[incubator-servicecomb-java-chassis] branch master updated (de8b33b -> 1bb09be)

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/incubator-servicecomb-java-chassis.git.


    from de8b33b  SCB-221 merge vertx 3.5.0 BodyHandlerImpl changes
     new 1527707  SCB-179 support - as paramter name with RequestParam
     new 1bb09be  SCB-179 support -(identifier) as parameter name with RequestParam

The 2 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:
 .../codec/protobuf/utils/ProtobufSchemaUtils.java  |  6 +-
 .../demo/jaxrs/tests/JaxrsIntegrationTestBase.java | 18 +++++
 .../jaxrs/tests/endpoints/SchemaFirstJaxrs.java    |  2 +
 .../endpoints/SomeAbstractJaxrsRestEndpoint.java   |  6 ++
 .../resources/microservices/jaxrs/schemaFirst.yaml | 18 +++++
 .../swagger/generator/core/utils/ClassUtils.java   | 83 ++++++----------------
 6 files changed, 70 insertions(+), 63 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>'].

[incubator-servicecomb-java-chassis] 02/02: SCB-179 support -(identifier) as parameter name with RequestParam

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/incubator-servicecomb-java-chassis.git

commit 1bb09befa8e8f21c5c070a07f8edffca5fcb290c
Author: acsukesh <su...@huawei.com>
AuthorDate: Thu Jan 11 13:59:51 2018 +0530

    SCB-179 support -(identifier) as parameter name with RequestParam
---
 .../swagger/generator/core/utils/ClassUtils.java   | 60 +---------------------
 1 file changed, 1 insertion(+), 59 deletions(-)

diff --git a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java
index 4529607..ca666e0 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java
@@ -52,64 +52,6 @@ public final class ClassUtils {
   // reference:
   //  https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
   //  https://en.wikipedia.org/wiki/List_of_Java_keywords
-  private static final Set<String> JAVA_RESERVED_WORDS = new HashSet<>();
-
-  static {
-    JAVA_RESERVED_WORDS.addAll(Arrays.asList("true",
-        "false",
-        "null",
-        "abstract",
-        "continue",
-        "for",
-        "new",
-        "switch",
-        "assert",
-        "default",
-        "goto",
-        "package",
-        "synchronized",
-        "boolean",
-        "do",
-        "if",
-        "private",
-        "this",
-        "break",
-        "double",
-        "implements",
-        "protected",
-        "throw",
-        "byte",
-        "else",
-        "import",
-        "public",
-        "throws",
-        "case",
-        "enum",
-        "instanceof",
-        "return",
-        "transient",
-        "catch",
-        "extends",
-        "int",
-        "short",
-        "try",
-        "char",
-        "final",
-        "interface",
-        "static",
-        "void",
-        "class",
-        "finally",
-        "long",
-        "strictfp",
-        "volatile",
-        "const",
-        "float",
-        "native",
-        "super",
-        "while"));
-  }
-
   private ClassUtils() {
   }
 
@@ -312,7 +254,7 @@ public final class ClassUtils {
       }
 
       part = part.replace('-', '_');
-      if (Character.isDigit(part.charAt(0)) || JAVA_RESERVED_WORDS.contains(part)) {
+      if (Character.isDigit(part.charAt(0)) || SourceVersion.isKeyword(part)) {
         part = "_" + part;
       }
       parts[idx] = part;

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 01/02: SCB-179 support - as paramter name with RequestParam

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/incubator-servicecomb-java-chassis.git

commit 152770705e5b2e315ecd9c838b9db435f8fdcecf
Author: acsukesh <su...@huawei.com>
AuthorDate: Wed Jan 10 15:53:33 2018 +0530

    SCB-179 support - as paramter name with RequestParam
---
 .../codec/protobuf/utils/ProtobufSchemaUtils.java  |  6 ++++--
 .../demo/jaxrs/tests/JaxrsIntegrationTestBase.java | 18 +++++++++++++++++
 .../jaxrs/tests/endpoints/SchemaFirstJaxrs.java    |  2 ++
 .../endpoints/SomeAbstractJaxrsRestEndpoint.java   |  6 ++++++
 .../resources/microservices/jaxrs/schemaFirst.yaml | 18 +++++++++++++++++
 .../swagger/generator/core/utils/ClassUtils.java   | 23 ++++++++++++++++++++--
 6 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/common/common-protobuf/src/main/java/io/servicecomb/codec/protobuf/utils/ProtobufSchemaUtils.java b/common/common-protobuf/src/main/java/io/servicecomb/codec/protobuf/utils/ProtobufSchemaUtils.java
index eb02155..dd5911d 100644
--- a/common/common-protobuf/src/main/java/io/servicecomb/codec/protobuf/utils/ProtobufSchemaUtils.java
+++ b/common/common-protobuf/src/main/java/io/servicecomb/codec/protobuf/utils/ProtobufSchemaUtils.java
@@ -25,6 +25,8 @@ import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import javax.lang.model.SourceVersion;
+
 import org.springframework.util.ClassUtils;
 
 import com.fasterxml.jackson.databind.JavaType;
@@ -147,8 +149,8 @@ public final class ProtobufSchemaUtils {
       Parameter[] params = method.getParameters();
       for (int idx = 0; idx < params.length; idx++) {
         Parameter param = params[idx];
-        String paramName = operationMeta.getParamName(idx);
-
+        String paramName = io.servicecomb.swagger.generator.core.utils.ClassUtils
+            .correctMethodParameterName(operationMeta.getParamName(idx));
         config.addField(paramName, param.getParameterizedType());
       }
 
diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java
index 4487aef..3d5df3f 100644
--- a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java
+++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/JaxrsIntegrationTestBase.java
@@ -238,6 +238,24 @@ public class JaxrsIntegrationTestBase {
   }
 
   @Test
+  public void ableToPostWithHeaderWithIdentifier() {
+    Person person = new Person();
+    person.setName("person name");
+
+    HttpHeaders headers = new HttpHeaders();
+    headers.setContentType(APPLICATION_JSON);
+    headers.add("prefix-test", "prefix  prefix");
+
+    HttpEntity<Person> requestEntity = new HttpEntity<>(person, headers);
+    for (String url : urls) {
+      ResponseEntity<String> responseEntity = restTemplate
+          .postForEntity(url + "saysomething1", requestEntity, String.class);
+
+      assertEquals("prefix  prefix person name", jsonBodyOf(responseEntity, String.class));
+    }
+  }
+
+  @Test
   public void ableToPostObjectAsJson() {
     Map<String, String> personFieldMap = new HashMap<>();
     personFieldMap.put("name", "person name from map");
diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SchemaFirstJaxrs.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SchemaFirstJaxrs.java
index b13d94a..5e92645 100644
--- a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SchemaFirstJaxrs.java
+++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SchemaFirstJaxrs.java
@@ -35,6 +35,8 @@ public interface SchemaFirstJaxrs {
 
   String saySomething(String prefix, Person user);
 
+  String saySomething1(String prefix_test, Person user);
+
   String sayHi(String name);
 
   String sayHi2(String name);
diff --git a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SomeAbstractJaxrsRestEndpoint.java b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SomeAbstractJaxrsRestEndpoint.java
index 796ee7e..a639700 100644
--- a/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SomeAbstractJaxrsRestEndpoint.java
+++ b/integration-tests/jaxrs-tests/src/test/java/io/servicecomb/demo/jaxrs/tests/endpoints/SomeAbstractJaxrsRestEndpoint.java
@@ -106,6 +106,12 @@ public class SomeAbstractJaxrsRestEndpoint {
     return prefix + " " + user.getName();
   }
 
+  @Path("/saysomething1")
+  @POST
+  public String saySomething1(@HeaderParam("prefix-test") String prefix_test, Person user) {
+    return prefix_test + " " + user.getName();
+  }
+
   @Path("/sayhi/{name}")
   @PUT
   public String sayHi(@PathParam("name") String name) {
diff --git a/integration-tests/jaxrs-tests/src/test/resources/microservices/jaxrs/schemaFirst.yaml b/integration-tests/jaxrs-tests/src/test/resources/microservices/jaxrs/schemaFirst.yaml
index 11ff68a..3d23f71 100644
--- a/integration-tests/jaxrs-tests/src/test/resources/microservices/jaxrs/schemaFirst.yaml
+++ b/integration-tests/jaxrs-tests/src/test/resources/microservices/jaxrs/schemaFirst.yaml
@@ -111,6 +111,24 @@ paths:
           description: say something
           schema:
             type: string
+  /saysomething1:
+    post:
+      operationId: saySomething1
+      parameters:
+        - name: prefix-test
+          in: header
+          required: true
+          type: string
+        - name: user
+          in: body
+          required: true
+          schema:
+            $ref: '#/definitions/Person'
+      responses:
+        200:
+          description: say something
+          schema:
+            type: string
   /sayhi/{name}:
     put:
       operationId: sayHi
diff --git a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java
index d433c3e..4529607 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/utils/ClassUtils.java
@@ -24,6 +24,9 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+
+import javax.lang.model.SourceVersion;
+
 import java.util.Set;
 
 import org.springframework.util.StringUtils;
@@ -279,11 +282,27 @@ public final class ClassUtils {
     return JavassistUtils.createClass(classLoader, classConfig);
   }
 
-  public static String correctMethodParameterName(String name) {
-    return name.replace(".", "_").replace("-", "_");
+  public static String correctMethodParameterName(String paramName) {
+    if (SourceVersion.isName(paramName)) {
+      return paramName;
+    }
+    StringBuffer newParam = new StringBuffer();
+    char tempChar;
+    for (int index = 0; index < paramName.length(); index++) {
+      tempChar = paramName.charAt(index);
+      if (Character.isJavaIdentifierPart(tempChar)) {
+        newParam.append(paramName.charAt(index));
+      } else if (tempChar == '.' || tempChar == '-') {
+        newParam.append('_');
+      }
+    }
+    return newParam.toString();
   }
 
   public static String correctClassName(String name) {
+    if (SourceVersion.isIdentifier(name) && !SourceVersion.isKeyword(name)) {
+      return name;
+    }
     String parts[] = name.split("\\.", -1);
     for (int idx = 0; idx < parts.length; idx++) {
       String part = parts[idx];

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.