Search in sources :

Example 6 with SwaggerProducer

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"));
}
Also used : SpringmvcAddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1) AddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1) SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) SpringmvcAddBodyV1(org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 7 with SwaggerProducer

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"));
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SpringmvcAddV1(org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 8 with SwaggerProducer

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);
}
Also used : Expectations(mockit.Expectations) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) Swagger(io.swagger.models.Swagger) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Example 9 with SwaggerProducer

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;
}
Also used : Executor(java.util.concurrent.Executor) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) Swagger(io.swagger.models.Swagger) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Example 10 with SwaggerProducer

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;
}
Also used : Executor(java.util.concurrent.Executor) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Aggregations

SwaggerProducer (org.apache.servicecomb.swagger.engine.SwaggerProducer)14 SwaggerEnvironment (org.apache.servicecomb.swagger.engine.SwaggerEnvironment)12 HashMap (java.util.HashMap)10 SwaggerInvocation (org.apache.servicecomb.swagger.invocation.SwaggerInvocation)10 Test (org.junit.Test)10 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)5 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)4 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)4 Swagger (io.swagger.models.Swagger)3 AddWrapperV1 (org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1)3 Executor (java.util.concurrent.Executor)2 Expectations (mockit.Expectations)2 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)2 SpringmvcAddWrapperV1 (org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1)2 ProtoSchema (org.apache.servicecomb.codec.protobuf.internal.converter.model.ProtoSchema)1 SpringmvcSwaggerGenerator (org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGenerator)1 JaxrsAddBeanParamV1 (org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1)1 JaxrsAddBodyV1 (org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1)1 JaxrsAddV1 (org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1)1 PojoAddBodyV1 (org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1)1