Search in sources :

Example 1 with OperationGenerator

use of io.servicecomb.swagger.generator.core.OperationGenerator in project java-chassis by ServiceComb.

the class OpMeta method init.

protected void init() {
    Class<?> swaggerInterface = ClassUtils.getOrCreateInterface(swagger, null, null);
    for (OperationGenerator operationGenerator : providerGenerator.getOperationGeneratorMap().values()) {
        String methodName = operationGenerator.getProviderMethod().getName();
        Method swaggerMethod = ReflectUtils.findMethod(swaggerInterface, methodName);
        List<Parameter> swaggerParameters = findParameter(swagger, methodName);
        List<Parameter> providerParameters = findParameter(providerGenerator, methodName);
        ARGS_MAPPER argsMapper = factory.createArgumentsMapper(swagger, swaggerMethod, swaggerParameters, operationGenerator.getProviderMethod(), providerParameters);
        swaggerMethodMap.put(methodName, swaggerMethod);
        operationArgsMapperMap.put(methodName, argsMapper);
    }
}
Also used : Parameter(io.swagger.models.parameters.Parameter) Method(java.lang.reflect.Method) OperationGenerator(io.servicecomb.swagger.generator.core.OperationGenerator)

Example 2 with OperationGenerator

use of io.servicecomb.swagger.generator.core.OperationGenerator in project java-chassis by ServiceComb.

the class ProducerSchemaFactory method connectToProvider.

@Override
protected void connectToProvider(ProducerSchemaContext context) {
    if (context.getGenerator() == null) {
        generateSwagger(context);
    }
    // 建立契约与producer之间的参数映射关系
    Class<?> swaggerIntf = ClassUtils.getJavaInterface(context.getSchemaMeta().getSwagger());
    for (OperationMeta operationMeta : context.getSchemaMeta().getOperations()) {
        OperationGenerator operationGenerator = context.getGenerator().getOperationGeneratorMap().get(operationMeta.getOperationId());
        Method swaggerMethod = ReflectUtils.findMethod(swaggerIntf, operationMeta.getOperationId());
        List<Parameter> swaggerParameters = operationMeta.getSwaggerOperation().getParameters();
        Method producerMethod = operationGenerator.getProviderMethod();
        List<Parameter> producerParameters = operationGenerator.getProviderParameters();
        ProducerArgumentsMapper argsMapper = producerArgsMapperFactory.createArgumentsMapper(context.getSchemaMeta().getSwagger(), swaggerMethod, swaggerParameters, producerMethod, producerParameters);
        createOperation(context, operationMeta, argsMapper);
    }
}
Also used : ProducerArgumentsMapper(io.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper) Parameter(io.swagger.models.parameters.Parameter) OperationMeta(io.servicecomb.core.definition.OperationMeta) Method(java.lang.reflect.Method) OperationGenerator(io.servicecomb.swagger.generator.core.OperationGenerator)

Example 3 with OperationGenerator

use of io.servicecomb.swagger.generator.core.OperationGenerator in project java-chassis by ServiceComb.

the class ConsumerSchemaFactory method mapDiffIntfParameters.

protected void mapDiffIntfParameters(ConsumerSchemaContext context) {
    // 建立契约与consumer之间的参数映射关系
    Class<?> swaggerIntf = ClassUtils.getJavaInterface(context.getSchemaMeta().getSwagger());
    SwaggerGenerator generator = generateSwagger(context);
    for (OperationMeta operationMeta : context.getSchemaMeta().getOperations()) {
        OperationGenerator operationGenerator = generator.getOperationGeneratorMap().get(operationMeta.getOperationId());
        // swagger集合可能大于consumer集合
        if (operationGenerator == null) {
            continue;
        }
        Method swaggerMethod = ReflectUtils.findMethod(swaggerIntf, operationMeta.getOperationId());
        List<Parameter> swaggerParameters = operationMeta.getSwaggerOperation().getParameters();
        Method consumerMethod = operationGenerator.getProviderMethod();
        List<Parameter> consumerParameters = operationGenerator.getProviderParameters();
        ConsumerArgumentsMapper argsMapper = consumerArgsMapperFactory.createArgumentsMapper(context.getSchemaMeta().getSwagger(), swaggerMethod, swaggerParameters, consumerMethod, consumerParameters);
        createOperation(context, operationMeta, argsMapper);
    }
}
Also used : ConsumerArgumentsMapper(io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapper) SwaggerGenerator(io.servicecomb.swagger.generator.core.SwaggerGenerator) Parameter(io.swagger.models.parameters.Parameter) ConsumerOperationMeta(io.servicecomb.core.provider.consumer.ConsumerOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) Method(java.lang.reflect.Method) OperationGenerator(io.servicecomb.swagger.generator.core.OperationGenerator)

Aggregations

OperationGenerator (io.servicecomb.swagger.generator.core.OperationGenerator)3 Parameter (io.swagger.models.parameters.Parameter)3 Method (java.lang.reflect.Method)3 OperationMeta (io.servicecomb.core.definition.OperationMeta)2 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)1 SwaggerGenerator (io.servicecomb.swagger.generator.core.SwaggerGenerator)1 ConsumerArgumentsMapper (io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapper)1 ProducerArgumentsMapper (io.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper)1