Search in sources :

Example 81 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class OperationGenerator method mergeBodyBasedParameters.

protected void mergeBodyBasedParameters(List<BodyParameter> bodyParameters) {
    for (Parameter parameter : bodyParameters) {
        swaggerParameters.remove(parameter);
    }
    // 将这些body包装为一个class,整体做为一个body参数
    String bodyParamName = ParamUtils.generateBodyParameterName(providerMethod);
    Class<?> cls = ClassUtils.getOrCreateBodyClass(this, bodyParameters);
    BodyParameter bodyParameter = ParamUtils.createBodyParameter(swagger, bodyParamName, cls);
    swaggerParameters.add(bodyParameter);
}
Also used : PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter) PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter)

Example 82 with Parameter

use of io.swagger.models.parameters.Parameter 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)

Example 83 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class TestApiImplicitParams method testBody.

@Test
public void testBody() {
    SwaggerGenerator swaggerGenerator = new SwaggerGeneratorForTest(context, ApiImplicitParamsAnnotation.class);
    swaggerGenerator.generate();
    Swagger swagger = swaggerGenerator.getSwagger();
    Path path = swagger.getPaths().get("/testBody");
    Operation operation = path.getOperations().get(0);
    Parameter parameter = operation.getParameters().get(0);
    JavaType javaType = ConverterMgr.findJavaType(swaggerGenerator, parameter);
    Assert.assertEquals(User.class, javaType.getRawClass());
}
Also used : Path(io.swagger.models.Path) JavaType(com.fasterxml.jackson.databind.JavaType) Swagger(io.swagger.models.Swagger) Parameter(io.swagger.models.parameters.Parameter) Operation(io.swagger.models.Operation) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) SwaggerGeneratorForTest(io.servicecomb.swagger.generator.core.unittest.SwaggerGeneratorForTest) Test(org.junit.Test)

Example 84 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class TestParamUtils method testGetRawJsonType.

@Test
public void testGetRawJsonType() {
    Parameter param = Mockito.mock(Parameter.class);
    Map<String, Object> extensions = new HashMap<>();
    when(param.getVendorExtensions()).thenReturn(extensions);
    extensions.put(SwaggerConst.EXT_RAW_JSON_TYPE, true);
    Assert.assertTrue(ClassUtils.isRawJsonType(param));
    extensions.put(SwaggerConst.EXT_RAW_JSON_TYPE, "test");
    Assert.assertFalse(ClassUtils.isRawJsonType(param));
}
Also used : HashMap(java.util.HashMap) Parameter(io.swagger.models.parameters.Parameter) Test(org.junit.Test)

Example 85 with Parameter

use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.

the class ArgumentsMapperFactory method processBodyArgMapper.

protected void processBodyArgMapper(ArgumentsMapperConfig config, int swaggerIdx) {
    Parameter swaggerParameter = config.getSwaggerParameters().get(swaggerIdx);
    // 不可以使用fieldMap的个数进行判定,那个里面是用参数名进行匹配的,而body不一定满足这个条件
    List<Integer> providerBodyIndexList = getBodyIndexList(config.getProviderParameters());
    if (providerBodyIndexList.isEmpty()) {
        // 没有匹配项
        LOGGER.warn(generateSkipParamInfo("parameter", config, swaggerParameter.getName()));
        return;
    }
    if (providerBodyIndexList.size() == 1) {
        // 如果provider参数中只有一个body,则不管名字,直接匹配
        int providerBodyArgIdx = providerBodyIndexList.get(0);
        mapBodyArg(config, providerBodyArgIdx, swaggerIdx);
        return;
    }
    // 如果有多个body,则需要按field匹配
    processBodyFieldArgMapper(config, swaggerIdx);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)86 BodyParameter (io.swagger.models.parameters.BodyParameter)50 Test (org.testng.annotations.Test)50 QueryParameter (io.swagger.models.parameters.QueryParameter)48 PathParameter (io.swagger.models.parameters.PathParameter)47 HeaderParameter (io.swagger.models.parameters.HeaderParameter)38 Swagger (io.swagger.models.Swagger)30 FormParameter (io.swagger.models.parameters.FormParameter)23 Operation (io.swagger.models.Operation)17 SerializableParameter (io.swagger.models.parameters.SerializableParameter)15 Type (java.lang.reflect.Type)13 ArrayList (java.util.ArrayList)10 Annotation (java.lang.annotation.Annotation)9 Method (java.lang.reflect.Method)9 JavaType (com.fasterxml.jackson.databind.JavaType)7 ContextParameter (io.servicecomb.swagger.extend.parameter.ContextParameter)6 Path (io.swagger.models.Path)6 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)5 Reader (io.swagger.jaxrs.Reader)5 Response (io.swagger.models.Response)4