use of org.apache.servicecomb.swagger.invocation.converter.Converter in project incubator-servicecomb-java-chassis by apache.
the class ArgumentsMapperFactory method collectSwaggerArgumentsMapper.
protected void collectSwaggerArgumentsMapper(ArgumentsMapperConfig config, List<ProviderParameter> providerNormalParams) {
Method swaggerMethod = config.getSwaggerMethod();
Type[] swaggerParams = swaggerMethod.getGenericParameterTypes();
// 普通场景,要求除了provider上的context,其他参数必须按顺序一一对应,provider上的有效参数可以与契约不一致
int minParamCount = Math.min(providerNormalParams.size(), swaggerParams.length);
for (int swaggerIdx = 0; swaggerIdx < minParamCount; swaggerIdx++) {
ProviderParameter providerParameter = providerNormalParams.get(swaggerIdx);
Type swaggerParameter = swaggerParams[swaggerIdx];
Converter converter = converterMgr.findConverter(type, providerParameter.getType(), swaggerParameter);
ArgumentMapper mapper = createArgumentMapperWithConverter(swaggerIdx, providerParameter.getIndex(), converter);
config.addArgumentMapper(mapper);
}
}
use of org.apache.servicecomb.swagger.invocation.converter.Converter in project incubator-servicecomb-java-chassis by apache.
the class TestResponseMapperFactorys method createResponseMapper_default.
@Test
public void createResponseMapper_default() {
ConsumerResponseMapper mapper = consumerResponseMapperFactorys.createResponseMapper(String.class, String.class);
Assert.assertThat(mapper, Matchers.instanceOf(DefaultConsumerResponseMapper.class));
Converter converter = Deencapsulation.getField(mapper, "converter");
Assert.assertSame(ConverterSame.getInstance(), converter);
}
use of org.apache.servicecomb.swagger.invocation.converter.Converter in project incubator-servicecomb-java-chassis by apache.
the class ArgumentsMapperFactory method collectWrapBodyMapper.
protected void collectWrapBodyMapper(ArgumentsMapperConfig config, List<ProviderParameter> providerNormalParams) {
// 将provider的参数存入唯一swagger参数的field
// 或是将唯一swagger参数的field存入provider参数
Method swaggerMethod = config.getSwaggerMethod();
Class<?> swaggerParam = swaggerMethod.getParameterTypes()[0];
Field[] swaggerParamFields = swaggerParam.getFields();
// 普通场景,要求除了provider上的context,其他参数必须按顺序一一对应,provider上的有效参数可以与契约不一致
int minParamCount = Math.min(providerNormalParams.size(), swaggerParamFields.length);
Map<Integer, FieldInfo> fieldMap = new HashMap<>();
for (int swaggerIdx = 0; swaggerIdx < minParamCount; swaggerIdx++) {
ProviderParameter providerParameter = providerNormalParams.get(swaggerIdx);
Field swaggerField = swaggerParamFields[swaggerIdx];
swaggerField.setAccessible(true);
Converter converter = converterMgr.findConverter(type, providerParameter.getType(), swaggerField.getGenericType());
FieldInfo info = new FieldInfo(swaggerField, converter);
fieldMap.put(providerParameter.getIndex(), info);
}
ArgumentMapper bodyFieldArg = createBodyFieldArgMapper(config, fieldMap);
config.addArgumentMapper(bodyFieldArg);
}
use of org.apache.servicecomb.swagger.invocation.converter.Converter in project incubator-servicecomb-java-chassis by apache.
the class ArgumentsMapperFactory method isSwaggerWrapBody.
protected boolean isSwaggerWrapBody(ArgumentsMapperConfig config, List<ProviderParameter> providerNormalParams) {
Method swaggerMethod = config.getSwaggerMethod();
if (swaggerMethod.getParameterCount() != 1) {
return false;
}
Type swaggerType = config.getSwaggerMethod().getGenericParameterTypes()[0];
if (!swaggerType.getClass().equals(Class.class)) {
return false;
}
Type firstProviderParam = providerNormalParams.get(0).getType();
if (TypeUtils.isAssignable(firstProviderParam, swaggerType)) {
return false;
}
// no public field, it's not rpc wrapper class
if (((Class<?>) swaggerType).getFields().length == 0) {
return false;
}
swaggerType = ((Class<?>) swaggerType).getFields()[0].getGenericType();
Converter converter = converterMgr.findConverter(type, firstProviderParam, swaggerType);
if (ConverterCommon.class.isInstance(converter)) {
return false;
}
// 透明rpc的包装场景
return true;
}
Aggregations