use of org.apache.servicecomb.swagger.engine.SwaggerProducer in project java-chassis by ServiceComb.
the class TestSpringmvc method addBody.
@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"));
}
use of org.apache.servicecomb.swagger.engine.SwaggerProducer in project java-chassis by ServiceComb.
the class TestSpringmvc method add.
@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"));
}
use of org.apache.servicecomb.swagger.engine.SwaggerProducer in project java-chassis by ServiceComb.
the class TestSchemaMetaCodec method mockSchemaMeta.
private void mockSchemaMeta(String schemaId, AbstractSwaggerGenerator swaggerGenerator, Object producerInstance) throws Exception {
new Expectations() {
{
providerMicroserviceMeta.getMicroserviceName();
result = "test";
providerMicroserviceMeta.getExtData(ProtobufManager.EXT_ID);
result = null;
consumerMicroserviceMeta.getMicroserviceName();
result = "test";
consumerMicroserviceMeta.getExtData(ProtobufManager.EXT_ID);
result = null;
}
};
Swagger swagger = swaggerGenerator.generate();
SwaggerEnvironment swaggerEnvironment = new SwaggerEnvironment();
providerSchemaMeta = new SchemaMeta(providerMicroserviceMeta, schemaId, swagger);
SwaggerProducer swaggerProducer = swaggerEnvironment.createProducer(producerInstance, swagger);
for (SwaggerProducerOperation producerOperation : swaggerProducer.getAllOperations()) {
OperationMeta operationMeta = providerSchemaMeta.ensureFindOperation(producerOperation.getOperationId());
operationMeta.setSwaggerProducerOperation(producerOperation);
}
consumerSchemaMeta = new SchemaMeta(consumerMicroserviceMeta, schemaId, swagger);
}
use of org.apache.servicecomb.swagger.engine.SwaggerProducer in project java-chassis by ServiceComb.
the class ProducerProviderManager method registerSchema.
public SchemaMeta registerSchema(String schemaId, Class<?> schemaInterface, Object instance) {
MicroserviceMeta producerMicroserviceMeta = scbEngine.getProducerMicroserviceMeta();
Swagger swagger = scbEngine.getSwaggerLoader().loadLocalSwagger(producerMicroserviceMeta.getAppId(), producerMicroserviceMeta.getShortName(), schemaId);
SwaggerProducer swaggerProducer = scbEngine.getSwaggerEnvironment().createProducer(instance, schemaInterface, swagger);
swagger = swaggerProducer.getSwagger();
registerUrlPrefixToSwagger(swagger);
SchemaMeta schemaMeta = producerMicroserviceMeta.registerSchemaMeta(schemaId, swagger);
schemaMeta.putExtData(CoreMetaUtils.SWAGGER_PRODUCER, swaggerProducer);
Executor reactiveExecutor = scbEngine.getExecutorManager().findExecutorById(ExecutorManager.EXECUTOR_REACTIVE);
for (SwaggerProducerOperation producerOperation : swaggerProducer.getAllOperations()) {
OperationMeta operationMeta = schemaMeta.ensureFindOperation(producerOperation.getOperationId());
operationMeta.setSwaggerProducerOperation(producerOperation);
if (CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType())) {
operationMeta.setExecutor(scbEngine.getExecutorManager().findExecutor(operationMeta, reactiveExecutor));
}
}
return schemaMeta;
}
use of org.apache.servicecomb.swagger.engine.SwaggerProducer in project incubator-servicecomb-java-chassis by apache.
the class ProducerSchemaFactory method getOrCreateProducerSchema.
// 只会在启动流程中调用
public SchemaMeta getOrCreateProducerSchema(String microserviceName, String schemaId, Class<?> producerClass, Object producerInstance) {
MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microserviceName);
ProducerSchemaContext context = new ProducerSchemaContext();
context.setMicroserviceMeta(microserviceMeta);
context.setSchemaId(schemaId);
context.setProviderClass(producerClass);
context.setProducerInstance(producerInstance);
SchemaMeta schemaMeta = getOrCreateSchema(context);
SwaggerProducer producer = swaggerEnv.createProducer(producerInstance, schemaMeta.getSwagger());
Executor reactiveExecutor = BeanUtils.getBean(ExecutorManager.EXECUTOR_REACTIVE);
for (OperationMeta operationMeta : schemaMeta.getOperations()) {
SwaggerProducerOperation producerOperation = producer.findOperation(operationMeta.getOperationId());
operationMeta.putExtData(Const.PRODUCER_OPERATION, producerOperation);
if (CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType())) {
operationMeta.setExecutor(ExecutorManager.findExecutor(operationMeta, reactiveExecutor));
}
}
return schemaMeta;
}
Aggregations