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 2020/01/11 10:02:59 UTC
[servicecomb-java-chassis] 07/08: [SCB-1709]restore arguments
mappers and refactor to invocation argument types
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 1422a57210da2476e891216c52da56cdd8fd02bb
Author: liubao <bi...@qq.com>
AuthorDate: Thu Jan 9 14:34:23 2020 +0800
[SCB-1709]restore arguments mappers and refactor to invocation argument types
---
.../servicecomb/common/rest/codec/RestCodec.java | 28 +---
.../rest/filter/inner/ClientRestArgsFilter.java | 4 +-
.../rest/filter/inner/ServerRestArgsFilter.java | 3 +-
.../servicecomb/core/definition/OperationMeta.java | 6 +-
.../rest/common/ProducerHttpRequestArgMapper.java | 4 +-
.../ProducerHttpRequestArgMapperFactory.java | 4 +-
.../common/TestProducerHttpRequestArgMapper.java | 2 +-
.../springmvc/reference/CseClientHttpRequest.java | 1 +
.../swagger/generator/ParameterGenerator.java | 17 +-
.../swagger/generator/core/TestSwaggerUtils.java | 5 +-
.../swagger/engine/SwaggerEnvironment.java | 21 +++
.../swagger/engine/SwaggerProducerOperation.java | 70 +++++---
.../arguments/AbstractArgumentsMapperCreator.java | 62 ++++---
.../invocation/arguments/ArgumentMapper.java | 8 +-
.../arguments/ContextArgumentMapperFactory.java | 2 +-
...ntextMapper.java => ArgumentsMapperCommon.java} | 28 ++--
.../ArgumentsMapperDirectReuse.java} | 14 +-
...perFactory.java => ConsumerArgumentMapper.java} | 18 +--
...ontextMapper.java => ConsumerArgumentSame.java} | 23 +--
.../consumer/ConsumerArgumentToBodyField.java | 58 +++++++
.../consumer/ConsumerArgumentsMapper.java | 6 +-
.../consumer/ConsumerArgumentsMapperCreator.java | 122 ++++++++++++++
.../consumer/ConsumerBeanParamMapper.java | 73 +++++++++
.../consumer/ConsumerInvocationContextMapper.java | 17 +-
.../ConsumerInvocationContextMapperFactory.java | 4 +-
.../producer/AbstractProducerContextArgMapper.java | 19 ++-
...perFactory.java => ProducerArgumentMapper.java} | 18 +--
...extArgMapper.java => ProducerArgumentSame.java} | 22 +--
.../producer/ProducerArgumentsMapper.java | 17 +-
.../producer/ProducerArgumentsMapperCreator.java | 117 ++++++++++++++
.../producer/ProducerBeanParamMapper.java | 69 ++++++++
.../producer/ProducerInvocationContextMapper.java | 4 +-
.../ProducerInvocationContextMapperFactory.java | 4 +-
.../SwaggerBodyFieldToProducerArgument.java | 55 +++++++
.../arguments/consumer/TestJaxrsV1V1.java | 178 +++++++++++++++++++++
.../arguments/consumer/TestJaxrsV1V2.java | 159 ++++++++++++++++++
.../arguments/consumer/TestJaxrsV2V1.java | 156 ++++++++++++++++++
.../arguments/consumer/TestJaxrsV2V2.java | 161 +++++++++++++++++++
.../arguments/consumer/TestPojoOneArg.java | 93 +++++++++++
.../arguments/consumer/TestPojoV1V1.java | 157 ++++++++++++++++++
.../arguments/consumer/TestPojoV1V2.java | 115 +++++++++++++
.../arguments/consumer/TestPojoV2V1.java | 116 ++++++++++++++
.../arguments/consumer/TestPojoV2V2.java | 119 ++++++++++++++
.../arguments/consumer/TestSpringmvcV1V1.java | 154 ++++++++++++++++++
.../arguments/consumer/TestSpringmvcV1V2.java | 159 ++++++++++++++++++
.../arguments/consumer/TestSpringmvcV2V1.java | 158 ++++++++++++++++++
.../arguments/consumer/TestSpringmvcV2V2.java | 163 +++++++++++++++++++
.../invocation/arguments/producer/TestJaxrs.java | 84 ++++++++++
.../invocation/arguments/producer/TestPojo.java | 86 ++++++++++
.../arguments/producer/TestPojoOneArg.java | 52 ++++++
.../arguments/producer/TestSpringmvc.java | 84 ++++++++++
51 files changed, 2923 insertions(+), 196 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
index ce0ef92..afd487d 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
@@ -27,7 +27,6 @@ import javax.ws.rs.core.Response.Status;
import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
import org.apache.servicecomb.common.rest.definition.RestParam;
-import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,33 +48,10 @@ public final class RestCodec {
for (int idx = 0; idx < paramSize; idx++) {
RestParam param = restOperation.getParamList().get(idx);
- param.getParamProcessor().setValue(clientRequest, getRestParamValue(param, args));
+ param.getParamProcessor().setValue(clientRequest, args.get(param.getParamName()));
}
}
- private static Object getRestParamValue(RestParam param, Map<String, Object> args) {
- // TODO : WEAK handle BEAN query param and POJO wrapped arguments.
- if (args.containsKey(param.getParamName())) {
- return args.get(param.getParamName());
- } else {
- return args;
- }
- }
-
- @SuppressWarnings("unchecked")
- private static Map<String, Object> getActualArgs(RestOperationMeta restOperation, Map<String, Object> args) {
- if (restOperation.getParamList().size() == 1) {
- if (restOperation.getOperationMeta().isPojoWrappedArguments(restOperation.getParamList().get(0).getParamName())) {
- Map<String, Object> argumentsMap = (Map<String, Object>) args.entrySet().iterator().next().getValue();
- Map<String, Object> result = new HashMap<>(argumentsMap.size());
- argumentsMap.forEach((k, v) -> result
- .put(k, JsonUtils.OBJ_MAPPER.convertValue(v, restOperation.getOperationMeta().getArgumentType(k))));
- return result;
- }
- }
- return args;
- }
-
public static Map<String, Object> restToArgs(HttpServletRequest request,
RestOperationMeta restOperation) throws InvocationException {
List<RestParam> paramList = restOperation.getParamList();
@@ -104,6 +80,6 @@ public final class RestCodec {
}
}
- return getActualArgs(restOperation, paramValues);
+ return paramValues;
}
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
index 97049a7..95f2d14 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
@@ -43,7 +43,9 @@ public class ClientRestArgsFilter implements HttpClientFilter {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
try {
- RestCodec.argsToRest(invocation.getArguments(), swaggerRestOperation, restClientRequest);
+ RestCodec.argsToRest(swaggerRestOperation.getOperationMeta().getSwaggerConsumerOperation().getArgumentsMapper()
+ .invocationArgumentToSwaggerArguments(invocation, invocation.getArguments()), swaggerRestOperation,
+ restClientRequest);
requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
} catch (Throwable e) {
throw ExceptionFactory.convertConsumerException(e);
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
index 7935520..6ee4893 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
@@ -60,7 +60,8 @@ public class ServerRestArgsFilter implements HttpServerFilter {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Map<String, Object> args = RestCodec.restToArgs(requestEx, restOperationMeta);
- invocation.setArguments(args);
+ invocation.setArguments(restOperationMeta.getOperationMeta().getSwaggerProducerOperation().getArgumentsMapper()
+ .swaggerArgumentToInvocationArguments(invocation, args));
return null;
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/definition/OperationMeta.java b/core/src/main/java/org/apache/servicecomb/core/definition/OperationMeta.java
index a880e8e..2987f3d 100644
--- a/core/src/main/java/org/apache/servicecomb/core/definition/OperationMeta.java
+++ b/core/src/main/java/org/apache/servicecomb/core/definition/OperationMeta.java
@@ -82,9 +82,9 @@ public class OperationMeta {
this.argumentsTypes.clear();
if (getSwaggerProducerOperation() != null) {
SwaggerProducerOperation swaggerProducerOperation = getSwaggerProducerOperation();
- for (java.lang.reflect.Parameter parameter : swaggerProducerOperation.getProducerMethod().getParameters()) {
- this.argumentsTypes.put(parameter.getName(), TypeFactory.defaultInstance().constructType(parameter.getType()));
- }
+ swaggerProducerOperation.getMethodParameterTypesBySwaggerName().forEach((k, v) -> {
+ this.argumentsTypes.put(k, TypeFactory.defaultInstance().constructType(v));
+ });
}
}
diff --git a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapper.java b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapper.java
index 3c4680a..8fd4d0a 100644
--- a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapper.java
+++ b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapper.java
@@ -25,8 +25,8 @@ import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
import org.apache.servicecomb.swagger.invocation.arguments.producer.AbstractProducerContextArgMapper;
public class ProducerHttpRequestArgMapper extends AbstractProducerContextArgMapper {
- public ProducerHttpRequestArgMapper(int producerArgIdx) {
- super(producerArgIdx);
+ public ProducerHttpRequestArgMapper(String invocationArgumentName, String swaggerArgumentName) {
+ super(invocationArgumentName, swaggerArgumentName);
}
@Override
diff --git a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapperFactory.java b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapperFactory.java
index a18bb3b..cc28319 100644
--- a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapperFactory.java
+++ b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/ProducerHttpRequestArgMapperFactory.java
@@ -30,7 +30,7 @@ public class ProducerHttpRequestArgMapperFactory implements ProducerContextArgum
}
@Override
- public ArgumentMapper create(int providerArgIdx) {
- return new ProducerHttpRequestArgMapper(providerArgIdx);
+ public ArgumentMapper create(String invocationArgumentName, String swaggerArgumentName) {
+ return new ProducerHttpRequestArgMapper(invocationArgumentName, swaggerArgumentName);
}
}
diff --git a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestProducerHttpRequestArgMapper.java b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestProducerHttpRequestArgMapper.java
index 2883139..8d3626f 100644
--- a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestProducerHttpRequestArgMapper.java
+++ b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestProducerHttpRequestArgMapper.java
@@ -36,7 +36,7 @@ public class TestProducerHttpRequestArgMapper {
@Mocked
Invocation invocation;
- ProducerHttpRequestArgMapper mapper = new ProducerHttpRequestArgMapper(0);
+ ProducerHttpRequestArgMapper mapper = new ProducerHttpRequestArgMapper("test", "test");
@Test
public void testGetFromContext(@Mocked HttpServletRequest request) {
diff --git a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
index f0810a1..86ad64e 100644
--- a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
+++ b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
@@ -252,6 +252,7 @@ public class CseClientHttpRequest implements ClientHttpRequest {
HttpServletRequest mockRequest = new CommonToHttpServletRequest(requestMeta.getPathParams(), queryParams,
httpHeaders, requestBody, requestMeta.getSwaggerRestOperation().isFormData(),
requestMeta.getSwaggerRestOperation().getFileKeys());
+ // no types info, so will not convert any parameters
return RestCodec.restToArgs(mockRequest, requestMeta.getSwaggerRestOperation());
}
}
diff --git a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/ParameterGenerator.java b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/ParameterGenerator.java
index 0c3a4bf..e1a1ccf 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/ParameterGenerator.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/ParameterGenerator.java
@@ -16,11 +16,6 @@
*/
package org.apache.servicecomb.swagger.generator;
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectGenericType;
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectHttpParameterType;
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterAnnotations;
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterName;
-
import java.lang.annotation.Annotation;
import java.lang.reflect.Executable;
import java.lang.reflect.Type;
@@ -57,13 +52,13 @@ public class ParameterGenerator {
public ParameterGenerator(Executable executable, Map<String, List<Annotation>> methodAnnotationMap,
String defaultName,
Annotation[] parameterAnnotations, Type genericType) {
- this.parameterName = collectParameterName(executable, parameterAnnotations,
+ this.parameterName = SwaggerGeneratorUtils.collectParameterName(executable, parameterAnnotations,
defaultName);
- this.annotations = collectParameterAnnotations(parameterAnnotations,
+ this.annotations = SwaggerGeneratorUtils.collectParameterAnnotations(parameterAnnotations,
methodAnnotationMap,
parameterName);
- this.genericType = collectGenericType(annotations, genericType);
- this.httpParameterType = collectHttpParameterType(annotations, genericType);
+ this.genericType = SwaggerGeneratorUtils.collectGenericType(annotations, genericType);
+ this.httpParameterType = SwaggerGeneratorUtils.collectHttpParameterType(annotations, genericType);
}
public ParameterGenerator(Executable executable, Map<String, List<Annotation>> methodAnnotationMap,
@@ -78,8 +73,8 @@ public class ParameterGenerator {
public ParameterGenerator(String parameterName, List<Annotation> annotations) {
this.parameterName = parameterName;
this.annotations = annotations;
- this.genericType = collectGenericType(annotations, null);
- this.httpParameterType = collectHttpParameterType(annotations, genericType);
+ this.genericType = SwaggerGeneratorUtils.collectGenericType(annotations, null);
+ this.httpParameterType = SwaggerGeneratorUtils.collectHttpParameterType(annotations, genericType);
}
public String getParameterName() {
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
index f7f191e..1c1e435 100644
--- a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/TestSwaggerUtils.java
@@ -17,12 +17,11 @@
package org.apache.servicecomb.swagger.generator.core;
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterName;
-
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
+import org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils;
import org.apache.servicecomb.swagger.generator.core.schema.InvalidResponseHeader;
import org.apache.servicecomb.swagger.generator.core.schema.RepeatOperation;
import org.apache.servicecomb.swagger.generator.core.schema.Schema;
@@ -261,6 +260,6 @@ public class TestSwaggerUtils {
+ " <compilerArgument>-parameters</compilerArgument>\n"
+ " </configuration>\n"
+ " </plugin>");
- collectParameterName(parameter);
+ SwaggerGeneratorUtils.collectParameterName(parameter);
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
index d04f2fa..cd0d509 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
@@ -29,7 +29,11 @@ import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
import org.apache.servicecomb.swagger.generator.core.utils.MethodUtils;
import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
+import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapper;
+import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperCreator;
import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerContextArgumentMapperFactory;
+import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper;
+import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperCreator;
import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory;
import org.apache.servicecomb.swagger.invocation.response.ResponseMapperFactorys;
import org.apache.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper;
@@ -40,6 +44,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.models.Swagger;
+import io.swagger.util.Json;
public class SwaggerEnvironment {
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerEnvironment.class);
@@ -68,12 +73,19 @@ public class SwaggerEnvironment {
continue;
}
+ ConsumerArgumentsMapperCreator creator = new ConsumerArgumentsMapperCreator(
+ Json.mapper().getSerializationConfig(),
+ contextFactorys,
+ consumerMethod,
+ swaggerOperation);
+ ConsumerArgumentsMapper argsMapper = creator.createArgumentsMapper();
ConsumerResponseMapper responseMapper = consumerResponseMapperFactorys
.createResponseMapper(consumerMethod.getGenericReturnType());
SwaggerConsumerOperation op = new SwaggerConsumerOperation();
op.setConsumerMethod(consumerMethod);
op.setSwaggerOperation(swaggerOperation);
+ op.setArgumentsMapper(argsMapper);
op.setResponseMapper(responseMapper);
consumer.addOperation(op);
@@ -120,6 +132,12 @@ public class SwaggerEnvironment {
throw new IllegalStateException(msg);
}
+ ProducerArgumentsMapperCreator creator = new ProducerArgumentsMapperCreator(
+ Json.mapper().getSerializationConfig(),
+ contextFactorys,
+ producerMethod,
+ swaggerOperation);
+ ProducerArgumentsMapper argsMapper = creator.createArgumentsMapper();
ProducerResponseMapper responseMapper = producerResponseMapperFactorys.createResponseMapper(
producerMethod.getGenericReturnType());
@@ -128,7 +146,10 @@ public class SwaggerEnvironment {
op.setProducerInstance(producerInstance);
op.setProducerMethod(producerMethod);
op.setSwaggerOperation(swaggerOperation);
+ op.setSwaggerParameterTypes(creator.getSwaggerParameterTypes());
+ op.setArgumentsMapper(argsMapper);
op.setResponseMapper(responseMapper);
+
producer.addOperation(op);
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
index 387ba8e..82c49a6 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
@@ -19,10 +19,14 @@ package org.apache.servicecomb.swagger.engine;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
+import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper;
import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper;
import org.slf4j.Logger;
@@ -42,11 +46,20 @@ public class SwaggerProducerOperation {
private SwaggerOperation swaggerOperation;
+ // swagger parameter types relate to producer
+ // because features of @BeanParam/query wrapper/rpc mode parameter wrapper
+ // types is not direct equals to producerMethod parameter types
+ private Map<String, Type> swaggerParameterTypes;
+
+ private ProducerArgumentsMapper argumentsMapper;
+
private ProducerResponseMapper responseMapper;
private List<ProducerInvokeExtension> producerInvokeExtenstionList =
SPIServiceUtils.getSortedService(ProducerInvokeExtension.class);
+ private Map<String, Type> methodParameterTypesBySwaggerName = new HashMap<>();
+
public String getOperationId() {
return swaggerOperation.getOperationId();
}
@@ -73,6 +86,7 @@ public class SwaggerProducerOperation {
public void setProducerMethod(Method producerMethod) {
this.producerMethod = producerMethod;
+ this.buildMethodSwaggerParameterName();
}
public SwaggerOperation getSwaggerOperation() {
@@ -83,6 +97,23 @@ public class SwaggerProducerOperation {
this.swaggerOperation = swaggerOperation;
}
+
+ public Map<String, Type> getSwaggerParameterTypes() {
+ return swaggerParameterTypes;
+ }
+
+ public void setSwaggerParameterTypes(Map<String, Type> swaggerParameterTypes) {
+ this.swaggerParameterTypes = swaggerParameterTypes;
+ }
+
+ public ProducerArgumentsMapper getArgumentsMapper() {
+ return argumentsMapper;
+ }
+
+ public void setArgumentsMapper(ProducerArgumentsMapper argumentsMapper) {
+ this.argumentsMapper = argumentsMapper;
+ }
+
public ProducerResponseMapper getResponseMapper() {
return responseMapper;
}
@@ -98,11 +129,10 @@ public class SwaggerProducerOperation {
public boolean isPojoWrappedArguments(String name) {
List<io.swagger.models.parameters.Parameter> swaggerParameters = this.swaggerOperation.getOperation()
.getParameters();
- Parameter[] methodParameters = this.producerMethod.getParameters();
io.swagger.models.parameters.Parameter swaggerParameter = findParameterByName(swaggerParameters, name);
if (swaggerParameter instanceof BodyParameter) {
- Parameter methodParameter = findParameterByName(methodParameters, name);
+ Type methodParameter = findMethodParameterTypesBySwaggerName(name);
if (methodParameter == null) {
return true;
}
@@ -110,28 +140,18 @@ public class SwaggerProducerOperation {
return false;
}
- public Type getMethodParameterType(String name) {
- Parameter[] methodParameters = this.producerMethod.getParameters();
- Parameter methodParameter = findParameterByName(methodParameters, name);
- if (methodParameter != null) {
- return methodParameter.getParameterizedType();
- }
- throw new IllegalStateException("not implemented now, name=" + name);
- }
-
public Type getSwaggerParameterType(String name) {
List<io.swagger.models.parameters.Parameter> swaggerParameters = this.swaggerOperation.getOperation()
.getParameters();
- Parameter[] methodParameters = this.producerMethod.getParameters();
io.swagger.models.parameters.Parameter swaggerParameter = findParameterByName(swaggerParameters, name);
- Parameter methodParameter = findParameterByName(methodParameters, name);
- if (methodParameter == null) {
+ Type methodParameterType = findMethodParameterTypesBySwaggerName(name);
+ if (methodParameterType == null) {
if (swaggerParameter instanceof BodyParameter) {
return Object.class;
}
} else {
- return methodParameter.getParameterizedType();
+ return methodParameterType;
}
throw new IllegalStateException("not implemented now, name=" + name);
@@ -147,13 +167,19 @@ public class SwaggerProducerOperation {
throw new IllegalStateException("not found parameter name in swagger, name=" + name);
}
- private static Parameter findParameterByName(
- Parameter[] methodParameters, String name) {
- for (Parameter p : methodParameters) {
- if (p.getName().equals(name)) {
- return p;
- }
+ private Type findMethodParameterTypesBySwaggerName(String name) {
+ return this.methodParameterTypesBySwaggerName.get(name);
+ }
+
+ public Map<String, Type> getMethodParameterTypesBySwaggerName() {
+ return this.methodParameterTypesBySwaggerName;
+ }
+
+ private void buildMethodSwaggerParameterName() {
+ Parameter[] methodParameters = this.producerMethod.getParameters();
+ for (Parameter parameter : methodParameters) {
+ String name = SwaggerGeneratorUtils.collectParameterName(parameter);
+ this.methodParameterTypesBySwaggerName.put(name, parameter.getParameterizedType());
}
- return null;
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/AbstractArgumentsMapperCreator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/AbstractArgumentsMapperCreator.java
index 9c17912..240be62 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/AbstractArgumentsMapperCreator.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/AbstractArgumentsMapperCreator.java
@@ -136,11 +136,10 @@ public abstract class AbstractArgumentsMapperCreator {
return null;
}
- protected Integer findAndClearSwaggerParameterIndex(String name) {
+ protected Integer findSwaggerParameterIndex(String name) {
for (int idx = 0; idx < swaggerParameters.size(); idx++) {
Parameter parameter = swaggerParameters.get(idx);
if (parameter != null && name.equals(parameter.getName())) {
- swaggerParameters.set(idx, null);
return idx;
}
}
@@ -156,25 +155,22 @@ public abstract class AbstractArgumentsMapperCreator {
continue;
}
- ArgumentMapper mapper = createKnownParameterMapper(providerParamIdx, providerParamIdx);
- mappers.add(mapper);
- // TODO: WEAK delete this code
-// if (processSwaggerBodyField(providerParamIdx, providerParameter, parameterName)) {
-// continue;
-// }
-
-// String parameterName = collectParameterName(providerParameter);
-// if (processKnownParameter(providerParamIdx, providerParameter, parameterName)) {
-// continue;
-// }
-//
-// JavaType providerType = TypeFactory.defaultInstance().constructType(providerParameter.getParameterizedType());
-// if (SwaggerUtils.isBean(providerType)) {
-// processBeanParameter(providerParamIdx, providerParameter);
-// continue;
-// }
-//
-// processUnknownParameter(parameterName);
+ String parameterName = collectParameterName(providerParameter);
+ if (processKnownParameter(providerParamIdx, providerParameter, parameterName)) {
+ continue;
+ }
+
+ if (processSwaggerBodyField(providerParamIdx, providerParameter, parameterName)) {
+ continue;
+ }
+
+ JavaType providerType = TypeFactory.defaultInstance().constructType(providerParameter.getParameterizedType());
+ if (SwaggerUtils.isBean(providerType)) {
+ processBeanParameter(providerParamIdx, providerParameter);
+ continue;
+ }
+
+ processUnknownParameter(parameterName);
}
}
@@ -190,7 +186,8 @@ public abstract class AbstractArgumentsMapperCreator {
return false;
}
- mappers.add(contextFactory.create(providerParamIdx));
+ mappers.add(contextFactory
+ .create(this.providerMethod.getParameters()[providerParamIdx].getName(), providerParameter.getName()));
return true;
}
@@ -203,19 +200,18 @@ public abstract class AbstractArgumentsMapperCreator {
*/
protected boolean processKnownParameter(int providerParamIdx, java.lang.reflect.Parameter providerParameter,
String parameterName) {
- Integer swaggerIdx = findAndClearSwaggerParameterIndex(parameterName);
+ Integer swaggerIdx = findSwaggerParameterIndex(parameterName);
+ if (swaggerIdx == null) {
+ return false;
+ }
// complex scenes
// swagger: int add(Body x)
// producer: int add(int x, int y)
if (bodyParameter != null &&
- !SwaggerUtils.isBean(providerParameter.getType()) &&
+ !SwaggerUtils.isBean(providerParameter.getType()) &&
+ swaggerIdx == swaggerBodyIdx &&
SwaggerUtils.isBean(bodyParameter.getSchema())) {
- swaggerIdx = providerParamIdx;
- swaggerParameters.set(swaggerIdx, bodyParameter);
- }
-
- if (swaggerIdx == null) {
return false;
}
@@ -237,13 +233,13 @@ public abstract class AbstractArgumentsMapperCreator {
return false;
}
-// ArgumentMapper mapper = createSwaggerBodyFieldMapper(providerParamIdx, parameterName, swaggerBodyIdx);
-// mappers.add(mapper);
+ ArgumentMapper mapper = createSwaggerBodyFieldMapper(providerParamIdx, parameterName, swaggerBodyIdx);
+ mappers.add(mapper);
return true;
}
-// protected abstract ArgumentMapper createSwaggerBodyFieldMapper(int providerParamIdx, String parameterName,
-// int swaggerBodyIdx);
+ protected abstract ArgumentMapper createSwaggerBodyFieldMapper(int providerParamIdx, String parameterName,
+ int swaggerBodyIdx);
/**
*
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentMapper.java
index 375ebd8..0800ee1 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ArgumentMapper.java
@@ -17,8 +17,14 @@
package org.apache.servicecomb.swagger.invocation.arguments;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
public interface ArgumentMapper {
- void mapArgument(SwaggerInvocation invocation, Object[] arguments);
+ void swaggerArgumentToInvocationArguments(SwaggerInvocation swaggerInvocation, Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments);
+
+ void invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation, Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments);
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java
index a0a33b1..6e67b7b 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/ContextArgumentMapperFactory.java
@@ -20,5 +20,5 @@ package org.apache.servicecomb.swagger.invocation.arguments;
public interface ContextArgumentMapperFactory {
Class<?> getContextClass();
- ArgumentMapper create(int argumentIdx);
+ ArgumentMapper create(String invocationArgumentName, String swaggerArgumentName);
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperCommon.java
similarity index 57%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperCommon.java
index 7ff2150..7bf640a 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperCommon.java
@@ -14,24 +14,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.servicecomb.swagger.invocation.arguments.consumer;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-public class ConsumerInvocationContextMapper implements ArgumentMapper {
- private int consumerIdx;
+/**
+ * map consumer arguments to swagger arguments
+ */
+public class ArgumentsMapperCommon implements ConsumerArgumentsMapper {
+ private List<ArgumentMapper> mappers;
- public ConsumerInvocationContextMapper(int consumerIdx) {
- this.consumerIdx = consumerIdx;
+ public ArgumentsMapperCommon(List<ArgumentMapper> mappers) {
+ this.mappers = mappers;
}
@Override
- public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
- InvocationContext context = (InvocationContext) consumerArguments[consumerIdx];
- invocation.addContext(context.getContext());
- invocation.addLocalContext(context.getLocalContext());
+ public Map<String, Object> invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> invocationArguments) {
+ Map<String, Object> swaggerParameters = new HashMap<>(invocationArguments.size());
+ for (ArgumentMapper argMapper : mappers) {
+ argMapper.invocationArgumentToSwaggerArguments(swaggerInvocation, swaggerParameters, invocationArguments);
+ }
+ return swaggerParameters;
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperDirectReuse.java
similarity index 71%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperDirectReuse.java
index 658cda0..467a712 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperDirectReuse.java
@@ -14,18 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.swagger.invocation.arguments.consumer;
-package org.apache.servicecomb.swagger.invocation.arguments.producer;
+import java.util.Map;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-public class ProducerInvocationContextMapper extends AbstractProducerContextArgMapper {
- public ProducerInvocationContextMapper(int producerIdx) {
- super(producerIdx);
- }
-
+public class ArgumentsMapperDirectReuse implements ConsumerArgumentsMapper {
@Override
- public Object createContextArg(SwaggerInvocation invocation) {
- return invocation;
+ public Map<String, Object> invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> invocationArguments) {
+ return invocationArguments;
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentMapper.java
similarity index 70%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentMapper.java
index 6b48f07..0034717 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentMapper.java
@@ -17,17 +17,15 @@
package org.apache.servicecomb.swagger.invocation.arguments.consumer;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import java.util.Map;
-public class ConsumerInvocationContextMapperFactory implements ConsumerContextArgumentMapperFactory {
- @Override
- public Class<?> getContextClass() {
- return InvocationContext.class;
- }
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
- @Override
- public ArgumentMapper create(int consumerArgIdx) {
- return new ConsumerInvocationContextMapper(consumerArgIdx);
+public abstract class ConsumerArgumentMapper implements ArgumentMapper {
+ public void swaggerArgumentToInvocationArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments) {
+ throw new IllegalStateException("not expected");
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentSame.java
similarity index 60%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentSame.java
index 7ff2150..3965f99 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentSame.java
@@ -17,21 +17,24 @@
package org.apache.servicecomb.swagger.invocation.arguments.consumer;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-public class ConsumerInvocationContextMapper implements ArgumentMapper {
- private int consumerIdx;
+public final class ConsumerArgumentSame extends ConsumerArgumentMapper {
+ protected String invocationArgumentName;
+
+ protected String swaggerArgumentName;
- public ConsumerInvocationContextMapper(int consumerIdx) {
- this.consumerIdx = consumerIdx;
+ public ConsumerArgumentSame(String invocationArgumentName, String swaggerArgumentName) {
+ this.invocationArgumentName = invocationArgumentName;
+ this.swaggerArgumentName = swaggerArgumentName;
}
@Override
- public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
- InvocationContext context = (InvocationContext) consumerArguments[consumerIdx];
- invocation.addContext(context.getContext());
- invocation.addLocalContext(context.getLocalContext());
+ public void invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments) {
+ swaggerArguments.put(swaggerArgumentName, invocationArguments.get(invocationArgumentName));
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentToBodyField.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentToBodyField.java
new file mode 100644
index 0000000..fb47f53
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentToBodyField.java
@@ -0,0 +1,58 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+
+/**
+ * <pre>
+ * Typical scene of transparent RPC
+ * all parameters of consumer method wrapped to a bean in contract
+ * </pre>
+ */
+public final class ConsumerArgumentToBodyField extends ConsumerArgumentMapper {
+ private final String invocationArgumentName;
+
+ private final String parameterName;
+
+ private final String swaggerArgumentName;
+
+ public ConsumerArgumentToBodyField(String invocationArgumentName,
+ String swaggerArgumentName, String parameterName) {
+ this.invocationArgumentName = invocationArgumentName;
+ this.parameterName = parameterName;
+ this.swaggerArgumentName = swaggerArgumentName;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments) {
+ Object consumerArgument = invocationArguments.get(invocationArgumentName);
+ if (swaggerArguments.get(swaggerArgumentName) == null) {
+ swaggerArguments.put(swaggerArgumentName, new LinkedHashMap<String, Object>());
+ }
+ if (consumerArgument != null) {
+ ((Map<String, Object>) swaggerArguments.get(swaggerArgumentName)).put(parameterName, consumerArgument);
+ }
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapper.java
index 9658e4a..d26c8ba 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapper.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.swagger.invocation.arguments.consumer;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
/**
@@ -45,7 +47,7 @@ import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
* </pre>
*
*/
-// TODO: WEAK this class can be deleted
public interface ConsumerArgumentsMapper {
- void toInvocation(Object[] consumerArguments, SwaggerInvocation invocation);
+ Map<String, Object> invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> invocationArguments);
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapperCreator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapperCreator.java
new file mode 100644
index 0000000..3c5de5f
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapperCreator.java
@@ -0,0 +1,122 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterName;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
+import org.apache.servicecomb.swagger.invocation.arguments.AbstractArgumentsMapperCreator;
+import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
+import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.SerializationConfig;
+import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+
+public class ConsumerArgumentsMapperCreator extends AbstractArgumentsMapperCreator {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConsumerArgumentsMapperCreator.class);
+
+ private int unknownConsumerParams = 0;
+
+ public ConsumerArgumentsMapperCreator(SerializationConfig serializationConfig,
+ Map<Class<?>, ContextArgumentMapperFactory> contextFactorys,
+ Method consumerMethod, SwaggerOperation swaggerOperation) {
+ super(serializationConfig, contextFactorys, consumerMethod, swaggerOperation);
+ }
+
+ private boolean isAllSameMapper() {
+ for (ArgumentMapper mapper : mappers) {
+ if (mapper instanceof ConsumerArgumentSame) {
+ continue;
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public ConsumerArgumentsMapper createArgumentsMapper() {
+ doCreateArgumentsMapper();
+
+ // if all mappers are SameMapper, then no need any mapper
+ if (unknownConsumerParams == 0
+ && mappers.size() == swaggerOperation.getOperation().getParameters().size()
+ && isAllSameMapper()) {
+ return new ArgumentsMapperDirectReuse();
+ }
+
+ return new ArgumentsMapperCommon(mappers);
+ }
+
+ @Override
+ protected void processUnknownParameter(String parameterName) {
+ // real unknown parameter, new consumer invoke old producer, just ignore this parameter
+ LOGGER.warn("new consumer invoke old version producer, parameter({}) is not exist in contract, method={}:{}.",
+ parameterName, providerMethod.getDeclaringClass().getName(), providerMethod.getName());
+ unknownConsumerParams++;
+ }
+
+ @Override
+ protected ArgumentMapper createKnownParameterMapper(int consumerParamIdx, Integer swaggerIdx) {
+ return new ConsumerArgumentSame(this.providerMethod.getParameters()[consumerParamIdx].getName(),
+ this.swaggerParameters.get(swaggerIdx).getName());
+ }
+
+ @Override
+ protected ArgumentMapper createSwaggerBodyFieldMapper(int consumerParamIdx, String parameterName,
+ int swaggerBodyIdx) {
+ return new ConsumerArgumentToBodyField(this.providerMethod.getParameters()[consumerParamIdx].getName(),
+ this.swaggerParameters.get(swaggerBodyIdx).getName(), parameterName);
+ }
+
+ protected void processBeanParameter(int consumerParamIdx, java.lang.reflect.Parameter consumerParameter) {
+ ConsumerBeanParamMapper mapper = new ConsumerBeanParamMapper(
+ this.providerMethod.getParameters()[consumerParamIdx].getName());
+ JavaType consumerType = TypeFactory.defaultInstance().constructType(consumerParameter.getParameterizedType());
+ for (BeanPropertyDefinition propertyDefinition : serializationConfig.introspect(consumerType).findProperties()) {
+ String parameterName = collectParameterName(providerMethod, propertyDefinition);
+ Integer swaggerIdx = findSwaggerParameterIndex(parameterName);
+ if (swaggerIdx == null) {
+ // unknown field, ignore it
+ LOGGER.warn(
+ "new consumer invoke old version producer, bean parameter({}) is not exist in contract, method={}:{}.",
+ parameterName, providerMethod.getDeclaringClass().getName(), providerMethod.getName());
+ continue;
+ }
+
+ Getter<Object, Object> getter;
+ if (propertyDefinition.hasGetter()) {
+ getter = LambdaMetafactoryUtils.createLambda(propertyDefinition.getGetter().getAnnotated(), Getter.class);
+ } else {
+ getter = LambdaMetafactoryUtils.createGetter(propertyDefinition.getField().getAnnotated());
+ }
+
+ mapper.addField(parameterName, getter);
+ }
+ mappers.add(mapper);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerBeanParamMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerBeanParamMapper.java
new file mode 100644
index 0000000..d012faa
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerBeanParamMapper.java
@@ -0,0 +1,73 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+
+/**
+ * <pre>
+ * consumer: void add(QueryWrapper query)
+ * class QueryWrapper {
+ * int x;
+ * int y;
+ * }
+ * contract; void add(int x, int y)
+ * </pre>
+ */
+public final class ConsumerBeanParamMapper extends ConsumerArgumentMapper {
+ private class FieldMeta {
+ String swaggerArgumentName;
+
+ Getter<Object, Object> getter;
+
+ public FieldMeta(String swaggerArgumentName, Getter<Object, Object> getter) {
+ this.swaggerArgumentName = swaggerArgumentName;
+ this.getter = getter;
+ }
+ }
+
+ protected String invocationArgumentName;
+
+ private List<FieldMeta> fields = new ArrayList<>();
+
+ public ConsumerBeanParamMapper(String invocationArgumentName) {
+ this.invocationArgumentName = invocationArgumentName;
+ }
+
+ public void addField(String invocationArgumentName, Getter<Object, Object> getter) {
+ fields.add(new FieldMeta(invocationArgumentName, getter));
+ }
+
+ @Override
+ public void invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments) {
+ Object consumerArgument = invocationArguments.get(invocationArgumentName);
+ if (consumerArgument == null) {
+ return;
+ }
+ for (FieldMeta fieldMeta : fields) {
+ swaggerArguments.put(fieldMeta.swaggerArgumentName, fieldMeta.getter.get(consumerArgument));
+ }
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
index 7ff2150..df32463 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapper.java
@@ -17,20 +17,23 @@
package org.apache.servicecomb.swagger.invocation.arguments.consumer;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-public class ConsumerInvocationContextMapper implements ArgumentMapper {
- private int consumerIdx;
+public class ConsumerInvocationContextMapper extends ConsumerArgumentMapper {
+ protected String invocationArgumentName;
- public ConsumerInvocationContextMapper(int consumerIdx) {
- this.consumerIdx = consumerIdx;
+ public ConsumerInvocationContextMapper(String invocationArgumentName) {
+ this.invocationArgumentName = invocationArgumentName;
}
@Override
- public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
- InvocationContext context = (InvocationContext) consumerArguments[consumerIdx];
+ public void invocationArgumentToSwaggerArguments(SwaggerInvocation invocation,
+ Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments) {
+ InvocationContext context = (InvocationContext) invocationArguments.get(invocationArgumentName);
invocation.addContext(context.getContext());
invocation.addLocalContext(context.getLocalContext());
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java
index 6b48f07..0de0f2e 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerInvocationContextMapperFactory.java
@@ -27,7 +27,7 @@ public class ConsumerInvocationContextMapperFactory implements ConsumerContextAr
}
@Override
- public ArgumentMapper create(int consumerArgIdx) {
- return new ConsumerInvocationContextMapper(consumerArgIdx);
+ public ArgumentMapper create(String invocationArgumentName, String swaggerArgumentName) {
+ return new ConsumerInvocationContextMapper(invocationArgumentName);
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java
index 9322ee9..83ca5b0 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java
@@ -17,20 +17,25 @@
package org.apache.servicecomb.swagger.invocation.arguments.producer;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-public abstract class AbstractProducerContextArgMapper implements ArgumentMapper {
- protected int producerArgIdx;
+public abstract class AbstractProducerContextArgMapper extends ProducerArgumentMapper {
+ protected String invocationArgumentName;
+
+ protected String swaggerArgumentName;
- public AbstractProducerContextArgMapper(int producerArgIdx) {
- this.producerArgIdx = producerArgIdx;
+ public AbstractProducerContextArgMapper(String invocationArgumentName, String swaggerArgumentName) {
+ this.invocationArgumentName = invocationArgumentName;
+ this.swaggerArgumentName = swaggerArgumentName;
}
@Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
+ public void swaggerArgumentToInvocationArguments(SwaggerInvocation invocation,
+ Map<String, Object> swaggerArguments, Map<String, Object> invocationArguments) {
Object producerArg = createContextArg(invocation);
- producerArguments[producerArgIdx] = producerArg;
+ invocationArguments.put(this.invocationArgumentName, producerArg);
}
public abstract Object createContextArg(SwaggerInvocation invocation);
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentMapper.java
similarity index 70%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentMapper.java
index 258ce65..21eae4e 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentMapper.java
@@ -17,17 +17,15 @@
package org.apache.servicecomb.swagger.invocation.arguments.producer;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import java.util.Map;
-public class ProducerInvocationContextMapperFactory implements ProducerContextArgumentMapperFactory {
- @Override
- public Class<?> getContextClass() {
- return InvocationContext.class;
- }
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
- @Override
- public ArgumentMapper create(int producerArgIdx) {
- return new ProducerInvocationContextMapper(producerArgIdx);
+public abstract class ProducerArgumentMapper implements ArgumentMapper {
+ public void invocationArgumentToSwaggerArguments(SwaggerInvocation swaggerInvocation,
+ Map<String, Object> swaggerArguments,
+ Map<String, Object> invocationArguments) {
+ throw new IllegalStateException("not expected");
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
similarity index 60%
copy from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java
copy to swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
index 9322ee9..f22456a 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/AbstractProducerContextArgMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
@@ -17,21 +17,23 @@
package org.apache.servicecomb.swagger.invocation.arguments.producer;
+import java.util.Map;
+
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-public abstract class AbstractProducerContextArgMapper implements ArgumentMapper {
- protected int producerArgIdx;
+public class ProducerArgumentSame extends ProducerArgumentMapper {
+ protected String invocationArgumentName;
+
+ protected String swaggerArgumentName;
- public AbstractProducerContextArgMapper(int producerArgIdx) {
- this.producerArgIdx = producerArgIdx;
+ public ProducerArgumentSame(String invocationArgumentName, String swaggerArgumentName) {
+ this.invocationArgumentName = invocationArgumentName;
+ this.swaggerArgumentName = swaggerArgumentName;
}
@Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
- Object producerArg = createContextArg(invocation);
- producerArguments[producerArgIdx] = producerArg;
+ public void swaggerArgumentToInvocationArguments(SwaggerInvocation invocation,
+ Map<String, Object> swaggerArguments, Map<String, Object> invocationArguments) {
+ invocationArguments.put(invocationArgumentName, swaggerArguments.get(swaggerArgumentName));
}
-
- public abstract Object createContextArg(SwaggerInvocation invocation);
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java
index 1ca2971..2a7124f 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapper.java
@@ -17,7 +17,9 @@
package org.apache.servicecomb.swagger.invocation.arguments.producer;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
@@ -28,20 +30,17 @@ import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
public class ProducerArgumentsMapper {
private List<ArgumentMapper> producerArgMapperList;
- private int producerParameterCount;
-
- public ProducerArgumentsMapper(List<ArgumentMapper> producerArgMapperList, int producerParameterCount) {
+ public ProducerArgumentsMapper(List<ArgumentMapper> producerArgMapperList) {
this.producerArgMapperList = producerArgMapperList;
- this.producerParameterCount = producerParameterCount;
}
- public Object[] toProducerArgs(SwaggerInvocation invocation) {
- Object[] producerArgs = new Object[producerParameterCount];
-
+ public Map<String, Object> swaggerArgumentToInvocationArguments(SwaggerInvocation invocation,
+ Map<String, Object> swaggerArguments) {
+ Map<String, Object> invocationArguments = new HashMap<>(swaggerArguments.size());
for (ArgumentMapper argMapper : producerArgMapperList) {
- argMapper.mapArgument(invocation, producerArgs);
+ argMapper.swaggerArgumentToInvocationArguments(invocation, swaggerArguments, invocationArguments);
}
- return producerArgs;
+ return invocationArguments;
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
new file mode 100644
index 0000000..e7ca773
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
@@ -0,0 +1,117 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterName;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
+import org.apache.servicecomb.swagger.invocation.arguments.AbstractArgumentsMapperCreator;
+import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
+import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.SerializationConfig;
+import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+
+public class ProducerArgumentsMapperCreator extends AbstractArgumentsMapperCreator {
+ // swagger parameter types relate to producer
+ // because features of @BeanParam/query, and rpc mode parameter wrapper
+ // types is not always equals to producerMethod parameter types directly
+ private Map<String, Type> swaggerParameterTypes;
+
+ public ProducerArgumentsMapperCreator(SerializationConfig serializationConfig,
+ Map<Class<?>, ContextArgumentMapperFactory> contextFactorys,
+ Method producerMethod, SwaggerOperation swaggerOperation) {
+ super(serializationConfig, contextFactorys, producerMethod, swaggerOperation);
+
+ swaggerParameterTypes = new HashMap<>();
+ }
+
+ public Map<String, Type> getSwaggerParameterTypes() {
+ return swaggerParameterTypes;
+ }
+
+ public ProducerArgumentsMapper createArgumentsMapper() {
+ doCreateArgumentsMapper();
+ return new ProducerArgumentsMapper(mappers);
+ }
+
+ @Override
+ protected void processUnknownParameter(String parameterName) {
+ throw new IllegalStateException(String
+ .format("failed to find producer parameter in contract, method=%s:%s, parameter name=%s.",
+ providerMethod.getDeclaringClass().getName(), providerMethod.getName(), parameterName));
+ }
+
+ @Override
+ protected ArgumentMapper createKnownParameterMapper(int providerParamIdx, Integer swaggerIdx) {
+ String swaggerArgumentName = swaggerParameters.get(swaggerIdx).getName();
+ swaggerParameterTypes
+ .put(swaggerArgumentName, providerMethod.getParameters()[providerParamIdx].getParameterizedType());
+ return new ProducerArgumentSame(providerMethod.getParameters()[providerParamIdx].getName(), swaggerArgumentName);
+ }
+
+ @Override
+ protected ArgumentMapper createSwaggerBodyFieldMapper(int producerParamIdx, String parameterName,
+ int swaggerBodyIdx) {
+ String swaggerArgumentName = swaggerParameters.get(swaggerBodyIdx).getName();
+ swaggerParameterTypes
+ .put(swaggerArgumentName, Object.class);
+ return new SwaggerBodyFieldToProducerArgument(providerMethod.getParameters()[producerParamIdx].getName(),
+ swaggerArgumentName,
+ parameterName, providerMethod.getParameters()[producerParamIdx].getParameterizedType());
+ }
+
+ @Override
+ protected void processBeanParameter(int producerParamIdx, Parameter producerParameter) {
+ ProducerBeanParamMapper mapper = new ProducerBeanParamMapper(
+ providerMethod.getParameters()[producerParamIdx].getName(), producerParameter.getType());
+ JavaType producerType = TypeFactory.defaultInstance().constructType(producerParameter.getParameterizedType());
+ for (BeanPropertyDefinition propertyDefinition : serializationConfig.introspect(producerType)
+ .findProperties()) {
+ String parameterName = collectParameterName(providerMethod, propertyDefinition);
+
+ Integer swaggerIdx = findSwaggerParameterIndex(parameterName);
+ if (swaggerIdx == null) {
+ throw new IllegalStateException(String
+ .format("failed to find producer parameter in contract, method=%s:%s, bean parameter name=%s.",
+ providerMethod.getDeclaringClass().getName(), providerMethod.getName(), parameterName));
+ }
+
+ Setter<Object, Object> setter;
+ if (propertyDefinition.hasSetter()) {
+ setter = LambdaMetafactoryUtils.createLambda(propertyDefinition.getSetter().getAnnotated(), Setter.class);
+ } else {
+ setter = LambdaMetafactoryUtils.createSetter(propertyDefinition.getField().getAnnotated());
+ }
+
+ swaggerParameterTypes.put(parameterName, propertyDefinition.getPrimaryType());
+ mapper.addField(parameterName, setter);
+ }
+ mappers.add(mapper);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
new file mode 100644
index 0000000..0ef2207
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
@@ -0,0 +1,69 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+
+public class ProducerBeanParamMapper extends ProducerArgumentMapper {
+ private class FieldMeta {
+ String swaggerParameterName;
+
+ Setter<Object, Object> setter;
+
+ public FieldMeta(String swaggerParameterName, Setter<Object, Object> setter) {
+ this.swaggerParameterName = swaggerParameterName;
+ this.setter = setter;
+ }
+ }
+
+ protected String invocationArgumentName;
+
+ private final Class<?> producerParamType;
+
+ private List<FieldMeta> fields = new ArrayList<>();
+
+ public ProducerBeanParamMapper(String invocationArgumentName, Class<?> producerParamType) {
+ this.invocationArgumentName = invocationArgumentName;
+ this.producerParamType = producerParamType;
+ }
+
+ public void addField(String swaggerParameterName, Setter<Object, Object> setter) {
+ fields.add(new FieldMeta(swaggerParameterName, setter));
+ }
+
+ @Override
+ public void swaggerArgumentToInvocationArguments(SwaggerInvocation invocation,
+ Map<String, Object> swaggerArguments, Map<String, Object> invocationArguments) {
+ try {
+ Object paramInstance = producerParamType.newInstance();
+ invocationArguments.put(invocationArgumentName, paramInstance);
+
+ for (FieldMeta fieldMeta : fields) {
+ Object value = swaggerArguments.get(fieldMeta.swaggerParameterName);
+ fieldMeta.setter.set(paramInstance, value);
+ }
+ } catch (Throwable e) {
+ throw new IllegalStateException("failed to map bean param.", e);
+ }
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
index 658cda0..5e1454c 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapper.java
@@ -20,8 +20,8 @@ package org.apache.servicecomb.swagger.invocation.arguments.producer;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
public class ProducerInvocationContextMapper extends AbstractProducerContextArgMapper {
- public ProducerInvocationContextMapper(int producerIdx) {
- super(producerIdx);
+ public ProducerInvocationContextMapper(String invocationArgumentName, String swaggerArgumentName) {
+ super(invocationArgumentName, swaggerArgumentName);
}
@Override
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
index 258ce65..1e99e89 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerInvocationContextMapperFactory.java
@@ -27,7 +27,7 @@ public class ProducerInvocationContextMapperFactory implements ProducerContextAr
}
@Override
- public ArgumentMapper create(int producerArgIdx) {
- return new ProducerInvocationContextMapper(producerArgIdx);
+ public ArgumentMapper create(String invocationArgumentName, String swaggerArgumentName) {
+ return new ProducerInvocationContextMapper(invocationArgumentName, swaggerArgumentName);
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
new file mode 100644
index 0000000..96ad0a7
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
@@ -0,0 +1,55 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.common.utils.JsonUtils;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+
+public class SwaggerBodyFieldToProducerArgument extends ProducerArgumentMapper {
+ public static ObjectMapper mapper = JsonUtils.OBJ_MAPPER;
+
+ private final String invocationArgumentName;
+
+ private final String parameterName;
+
+ private final JavaType producerParamType;
+
+ private final String swaggerArgumentName;
+
+ public SwaggerBodyFieldToProducerArgument(String invocationArgumentName,
+ String swaggerArgumentName, String parameterName, Type producerParamType) {
+ this.invocationArgumentName = invocationArgumentName;
+ this.parameterName = parameterName;
+ this.producerParamType = TypeFactory.defaultInstance().constructType(producerParamType);
+ this.swaggerArgumentName = swaggerArgumentName;
+ }
+
+ @Override
+ public void swaggerArgumentToInvocationArguments(SwaggerInvocation invocation,
+ Map<String, Object> swaggerArguments, Map<String, Object> invocationArguments) {
+ Map<String, Object> body = (Map<String, Object>) swaggerArguments.get(swaggerArgumentName);
+ invocationArguments.put(invocationArgumentName, mapper.convertValue(body.get(parameterName), producerParamType));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V1.java
new file mode 100644
index 0000000..6a0ed23
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V1.java
@@ -0,0 +1,178 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestJaxrsV1V1 {
+ @Test
+ public void should_mapper_consumer_multi_args_to_swagger_multi_args() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ interface ConsumerAddV1_diff_order {
+ int add(int y, int x);
+ }
+
+ @Test
+ public void should_mapper_consumer_multi_args_to_swagger_multi_args_with_diff_order() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1_diff_order.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void should_mapper_consumer_multi_args_to_swagger_multi_args_gen_by_BeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void should_mapper_consumer_multi_args_to_swagger_body() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>)result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void should_mapper_consumer_wrapped_body_to_swagger_multi_args() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void should_mapper_consumer_wrapped_body_to_swagger_multi_args_gen_by_BeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void should_mapper_consumer_body_to_swagger_body() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V2.java
new file mode 100644
index 0000000..05d0692
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V2.java
@@ -0,0 +1,159 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV2;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestJaxrsV1V2 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null,result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addBeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V1.java
new file mode 100644
index 0000000..0485972
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V1.java
@@ -0,0 +1,156 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestJaxrsV2V1 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_addBeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V2.java
new file mode 100644
index 0000000..0954010
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V2.java
@@ -0,0 +1,161 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV2;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestJaxrsV2V2 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addBeanParam() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoOneArg.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoOneArg.java
new file mode 100644
index 0000000..5a58a98
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoOneArg.java
@@ -0,0 +1,93 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
+import org.apache.servicecomb.foundation.test.scaffolding.model.User;
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerOneArg;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoOneArg;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestPojoOneArg {
+ @Test
+ public void should_mapper_consumer_simple_to_swagger_body() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoOneArg.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerOneArg.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("simple").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("name", "name");
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("name");
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals("name", result.get("name"));
+ }
+
+ @Test
+ public void should_mapper_consumer_bean_to_swagger_body() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoOneArg.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerOneArg.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("bean").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("user", new User());
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ Assert.assertSame(arguments.get("user"), result.get("user"));
+ }
+
+ @Test
+ public void should_mapper_consumer_enum_to_swagger_body_field() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoOneArg.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerOneArg.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("enumBody").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("color", Color.BLUE);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("color");
+ Assert.assertEquals(1, result.size());
+ Assert.assertEquals(Color.BLUE, result.get("color"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V1.java
new file mode 100644
index 0000000..fe73f10
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V1.java
@@ -0,0 +1,157 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddWithContext;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestPojoV1V1 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ AddWrapperV1 wrapperV1 = (AddWrapperV1) result.get("addBody");
+ Assert.assertEquals(1, wrapperV1.getX());
+ Assert.assertEquals(2, wrapperV1.y);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+
+ @Test
+ public void addWithContext_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddWithContext.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ InvocationContext invocationContext = new InvocationContext();
+ invocationContext.addContext("k1", "v1");
+ invocationContext.addContext("k2", "v2");
+ invocationContext.addLocalContext("k3", "v3");
+ invocationContext.addLocalContext("k4", "v4");
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("context", invocationContext);
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, result.get("x"));
+ Assert.assertEquals(2, result.get("y"));
+
+ Assert.assertEquals(2, invocation.getContext().size());
+ Assert.assertEquals("v1", invocation.getContext().get("k1"));
+ Assert.assertEquals("v2", invocation.getContext().get("k2"));
+
+ Assert.assertEquals(2, invocation.getLocalContext().size());
+ Assert.assertEquals("v3", invocation.getLocalContext().get("k3"));
+ Assert.assertEquals("v4", invocation.getLocalContext().get("k4"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V2.java
new file mode 100644
index 0000000..7bfcf4b
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V2.java
@@ -0,0 +1,115 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestPojoV1V2 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V1.java
new file mode 100644
index 0000000..4da8146
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V1.java
@@ -0,0 +1,116 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestPojoV2V1 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V2.java
new file mode 100644
index 0000000..7a703b5
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V2.java
@@ -0,0 +1,119 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestPojoV2V2 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(arguments.get("addBody"), result.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V1.java
new file mode 100644
index 0000000..4dbd5c2
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V1.java
@@ -0,0 +1,154 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestSpringmvcV1V1 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V2.java
new file mode 100644
index 0000000..e13a49f
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V2.java
@@ -0,0 +1,159 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV2;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestSpringmvcV1V2 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void add_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(null, result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV1(1, 2));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V1.java
new file mode 100644
index 0000000..b56dd64
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V1.java
@@ -0,0 +1,158 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestSpringmvcV2V1 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V2.java
new file mode 100644
index 0000000..1738939
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V2.java
@@ -0,0 +1,163 @@
+/*
+ * 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.invocation.arguments.consumer;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV2;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV2;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV2;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.swagger.models.Swagger;
+
+public class TestSpringmvcV2V2 {
+ @Test
+ public void add_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void add_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("x-z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void add_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ arguments.put("z", 3);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ result = (Map<String, Object>) result.get("addBody");
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_add() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addWrapper() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ Assert.assertEquals(3, (int) result.get("x-z"));
+ }
+
+ @Test
+ public void addBody_addBody() {
+ SwaggerEnvironment environment = new SwaggerEnvironment();
+ Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
+
+ SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
+ ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", new AddWrapperV2(1, 2, 3));
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
+
+ Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
new file mode 100644
index 0000000..e2c7c7a
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
@@ -0,0 +1,84 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestJaxrs {
+ @Test
+ public void add() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBeanParam() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBeanParamV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ AddBeanParamV1 paramV1 = (AddBeanParamV1) result.get("wrapper");
+ Assert.assertEquals(1, paramV1.getX());
+ Assert.assertEquals(2, paramV1.y);
+ }
+
+ @Test
+ public void addBody() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBodyV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ AddWrapperV1 addBody = new AddWrapperV1();
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", addBody);
+
+ SwaggerInvocation invocation = new SwaggerInvocation();
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ Assert.assertSame(addBody, result.get("addBody"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
new file mode 100644
index 0000000..4d805df
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
@@ -0,0 +1,86 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoAddWithContextV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestPojo {
+ static Map<String, Object> addBody = new HashMap<>();
+
+ static {
+ addBody.put("x", 1);
+ addBody.put("y", 2);
+ }
+
+ @Test
+ public void add() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ SwaggerInvocation invocation = new SwaggerInvocation();
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", addBody);
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addBody() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddBodyV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ SwaggerInvocation invocation = new SwaggerInvocation();
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", addBody);
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ Assert.assertSame(addBody, result.get("addBody"));
+ }
+
+ @Test
+ public void addWithContext_add() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddWithContextV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ SwaggerInvocation invocation = new SwaggerInvocation();
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", addBody);
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(3, result.size());
+ Assert.assertSame(invocation, result.get("context"));
+ Assert.assertEquals(1, result.get("x"));
+ Assert.assertEquals(2, result.get("y"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojoOneArg.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojoOneArg.java
new file mode 100644
index 0000000..99eb56a
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojoOneArg.java
@@ -0,0 +1,52 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.PojoOneArg;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestPojoOneArg {
+ @Test
+ public void should_mapper_swagger_wrapped_body_field_to_producer_enum() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoOneArg(), null);
+ SwaggerProducerOperation swaggerProducerOperation = swaggerProducer.findOperation("enumBody");
+ Assert.assertEquals("color",
+ swaggerProducerOperation.getSwaggerOperation().getOperation().getParameters().get(0).getName());
+
+ ProducerArgumentsMapper mapper = swaggerProducerOperation.getArgumentsMapper();
+
+ SwaggerInvocation invocation = new SwaggerInvocation();
+ Map<String, Object> swaggerArguments = new HashMap<>();
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("color", "BLUE");
+ swaggerArguments.put("color", arguments);
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, swaggerArguments);
+
+ Assert.assertEquals(1, result.size());
+ Assert.assertSame(Color.BLUE, result.get("color"));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java
new file mode 100644
index 0000000..bda8ae6
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java
@@ -0,0 +1,84 @@
+/*
+ * 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.invocation.arguments.producer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
+import org.apache.servicecomb.swagger.engine.SwaggerProducer;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
+import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddBeanParamV1;
+import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestSpringmvc {
+ @Test
+ public void add() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(1, (int) result.get("x"));
+ Assert.assertEquals(2, (int) result.get("y"));
+ }
+
+ @Test
+ public void addWrapper() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddWrapperV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("x", 1);
+ arguments.put("y", 2);
+ SwaggerInvocation invocation = new SwaggerInvocation();
+
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ AddWrapperV1 paramV1 = (AddWrapperV1) result.get("wrapper");
+ Assert.assertEquals(1, paramV1.getX());
+ Assert.assertEquals(2, paramV1.y);
+ }
+
+ @Test
+ public void addBody() {
+ SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddBodyV1(), null);
+ ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
+
+ AddWrapperV1 addBody = new AddWrapperV1();
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("addBody", addBody);
+
+ SwaggerInvocation invocation = new SwaggerInvocation();
+ Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
+
+ Assert.assertEquals(1, result.size());
+ Assert.assertSame(addBody, result.get("addBody"));
+ }
+}