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/05/11 07:01:41 UTC
[incubator-servicecomb-java-chassis] 01/06: [scb-533] avoid treat
genericSignature of byte[] to be "L[B; ", it should be "[B; "
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 2e06aef92a4bf8f481f55932d298db01907b18f5
Author: wujimin <wu...@huawei.com>
AuthorDate: Mon May 7 14:37:35 2018 +0800
[scb-533] avoid treat genericSignature of byte[] to be "L[B;", it should be "[B;"
---
.../swagger/converter/ConverterMgr.java | 29 +++++-----
.../swagger/converter/TestConverterMgr.java | 65 ++++++++++++++++++++++
2 files changed, 79 insertions(+), 15 deletions(-)
diff --git a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/converter/ConverterMgr.java b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/converter/ConverterMgr.java
index a70907e..05177db 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/converter/ConverterMgr.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/converter/ConverterMgr.java
@@ -40,7 +40,6 @@ import org.apache.servicecomb.swagger.extend.property.ByteProperty;
import org.apache.servicecomb.swagger.extend.property.ShortProperty;
import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import io.swagger.models.ArrayModel;
@@ -108,28 +107,28 @@ public final class ConverterMgr {
}
private static void initPropertyMap() {
- PROPERTY_MAP.put(BooleanProperty.class, SimpleType.constructUnsafe(Boolean.class));
+ PROPERTY_MAP.put(BooleanProperty.class, TypeFactory.defaultInstance().constructType(Boolean.class));
- PROPERTY_MAP.put(FloatProperty.class, SimpleType.constructUnsafe(Float.class));
- PROPERTY_MAP.put(DoubleProperty.class, SimpleType.constructUnsafe(Double.class));
- PROPERTY_MAP.put(DecimalProperty.class, SimpleType.constructUnsafe(BigDecimal.class));
+ PROPERTY_MAP.put(FloatProperty.class, TypeFactory.defaultInstance().constructType(Float.class));
+ PROPERTY_MAP.put(DoubleProperty.class, TypeFactory.defaultInstance().constructType(Double.class));
+ PROPERTY_MAP.put(DecimalProperty.class, TypeFactory.defaultInstance().constructType(BigDecimal.class));
- PROPERTY_MAP.put(ByteProperty.class, SimpleType.constructUnsafe(Byte.class));
- PROPERTY_MAP.put(ShortProperty.class, SimpleType.constructUnsafe(Short.class));
- PROPERTY_MAP.put(IntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
- PROPERTY_MAP.put(BaseIntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
- PROPERTY_MAP.put(LongProperty.class, SimpleType.constructUnsafe(Long.class));
+ PROPERTY_MAP.put(ByteProperty.class, TypeFactory.defaultInstance().constructType(Byte.class));
+ PROPERTY_MAP.put(ShortProperty.class, TypeFactory.defaultInstance().constructType(Short.class));
+ PROPERTY_MAP.put(IntegerProperty.class, TypeFactory.defaultInstance().constructType(Integer.class));
+ PROPERTY_MAP.put(BaseIntegerProperty.class, TypeFactory.defaultInstance().constructType(Integer.class));
+ PROPERTY_MAP.put(LongProperty.class, TypeFactory.defaultInstance().constructType(Long.class));
// stringProperty包含了enum的场景,并不一定是转化为string
// 但是,如果统一走StringPropertyConverter则可以处理enum的场景
- PROPERTY_MAP.put(StringProperty.class, SimpleType.constructUnsafe(String.class));
+ PROPERTY_MAP.put(StringProperty.class, TypeFactory.defaultInstance().constructType(String.class));
- PROPERTY_MAP.put(DateProperty.class, SimpleType.constructUnsafe(LocalDate.class));
- PROPERTY_MAP.put(DateTimeProperty.class, SimpleType.constructUnsafe(Date.class));
+ PROPERTY_MAP.put(DateProperty.class, TypeFactory.defaultInstance().constructType(LocalDate.class));
+ PROPERTY_MAP.put(DateTimeProperty.class, TypeFactory.defaultInstance().constructType(Date.class));
- PROPERTY_MAP.put(ByteArrayProperty.class, SimpleType.constructUnsafe(byte[].class));
+ PROPERTY_MAP.put(ByteArrayProperty.class, TypeFactory.defaultInstance().constructType(byte[].class));
- PROPERTY_MAP.put(FileProperty.class, SimpleType.constructUnsafe(Part.class));
+ PROPERTY_MAP.put(FileProperty.class, TypeFactory.defaultInstance().constructType(Part.class));
}
private static void initConverters() {
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/converter/TestConverterMgr.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/converter/TestConverterMgr.java
new file mode 100644
index 0000000..d3b793c
--- /dev/null
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/converter/TestConverterMgr.java
@@ -0,0 +1,65 @@
+/*
+ * 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.swagger.converter;
+
+import java.util.Map;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.servicecomb.swagger.extend.property.ByteProperty;
+import org.apache.servicecomb.swagger.extend.property.ShortProperty;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.swagger.models.properties.BaseIntegerProperty;
+import io.swagger.models.properties.BooleanProperty;
+import io.swagger.models.properties.ByteArrayProperty;
+import io.swagger.models.properties.DateProperty;
+import io.swagger.models.properties.DateTimeProperty;
+import io.swagger.models.properties.DecimalProperty;
+import io.swagger.models.properties.DoubleProperty;
+import io.swagger.models.properties.FileProperty;
+import io.swagger.models.properties.FloatProperty;
+import io.swagger.models.properties.IntegerProperty;
+import io.swagger.models.properties.LongProperty;
+import io.swagger.models.properties.Property;
+import io.swagger.models.properties.StringProperty;
+
+public class TestConverterMgr {
+ @Test
+ public void propertyMapGenericSignature() throws IllegalAccessException {
+ @SuppressWarnings("unchecked")
+ Map<Class<? extends Property>, JavaType> propertyMap = (Map<Class<? extends Property>, JavaType>) FieldUtils
+ .readStaticField(ConverterMgr.class, "PROPERTY_MAP", true);
+
+ Assert.assertEquals("Ljava/lang/Boolean;", propertyMap.get(BooleanProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Float;", propertyMap.get(FloatProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Double;", propertyMap.get(DoubleProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/math/BigDecimal;", propertyMap.get(DecimalProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Byte;", propertyMap.get(ByteProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Short;", propertyMap.get(ShortProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Integer;", propertyMap.get(IntegerProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Integer;", propertyMap.get(BaseIntegerProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/Long;", propertyMap.get(LongProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/lang/String;", propertyMap.get(StringProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/time/LocalDate;", propertyMap.get(DateProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljava/util/Date;", propertyMap.get(DateTimeProperty.class).getGenericSignature());
+ Assert.assertEquals("[B;", propertyMap.get(ByteArrayProperty.class).getGenericSignature());
+ Assert.assertEquals("Ljavax/servlet/http/Part;", propertyMap.get(FileProperty.class).getGenericSignature());
+ }
+}
--
To stop receiving notification emails like this one, please contact
liubao@apache.org.