use of org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapper in project incubator-servicecomb-java-chassis by apache.
the class SwaggerEnvironment method createConsumer.
public SwaggerConsumer createConsumer(Class<?> consumerIntf, Class<?> swaggerIntf) {
SwaggerConsumer consumer = new SwaggerConsumer();
consumer.setConsumerIntf(consumerIntf);
consumer.setSwaggerIntf(swaggerIntf);
for (Method consumerMethod : consumerIntf.getMethods()) {
String swaggerMethodName = findSwaggerMethodName(consumerMethod);
// consumer参数不一定等于swagger参数
Method swaggerMethod = ReflectUtils.findMethod(swaggerIntf, swaggerMethodName);
if (swaggerMethod == null) {
// consumer大于契约,非法
String msg = String.format("consumer method %s:%s not exist in swagger.", consumerIntf.getName(), consumerMethod.getName());
throw new Error(msg);
}
ConsumerArgumentsMapper argsMapper = consumerArgumentsFactory.createArgumentsMapper(swaggerMethod, consumerMethod);
ConsumerResponseMapper responseMapper = consumerResponseMapperFactorys.createResponseMapper(swaggerMethod.getGenericReturnType(), consumerMethod.getGenericReturnType());
SwaggerConsumerOperation op = new SwaggerConsumerOperation();
op.setName(consumerMethod.getName());
op.setConsumerMethod(consumerMethod);
op.setSwaggerMethod(swaggerMethod);
op.setArgumentsMapper(argsMapper);
op.setResponseMapper(responseMapper);
consumer.addOperation(op);
}
return consumer;
}
Aggregations