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);
}
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);
}
}
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());
}
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));
}
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);
}
Aggregations