use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class TestPath method testQueryVarParamWriter.
@Test
public void testQueryVarParamWriter() throws Exception {
boolean status = true;
new MockUp<RestParam>() {
@Mock
public String getParamName() {
return "queryVar";
}
};
new MockUp<QueryVarParamWriter>() {
@Mock
protected Object getParamValue(Object[] args) {
return args[0];
}
};
Parameter parameter = new QueryParameter();
QueryVarParamWriter writer = new QueryVarParamWriter('&', new RestParam(0, parameter, String.class));
try {
verify(writer, "T", "&queryVar=T");
verify(writer, null, "&");
verify(writer, new String[] { "a", "b" }, "&queryVar=a&queryVar=b");
verify(writer, new String[] { "a", null, "b" }, "&queryVar=a&queryVar=&queryVar=b");
verify(writer, Arrays.asList("Lars", "Simon"), "&queryVar=Lars&queryVar=Simon");
verify(writer, "测试", "&queryVar=%E6%B5%8B%E8%AF%95");
verify(writer, "a b", "&queryVar=a+b");
verify(writer, "a+b", "&queryVar=a%2Bb");
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class TestRestCodec method beforeClass.
@BeforeClass
public static void beforeClass() {
restOperation = Mockito.mock(RestOperationMeta.class);
// clientRequest = Mockito.mock(RestClientRequest.class);
paramList = new ArrayList<>();
Parameter hp = new HeaderParameter();
hp.setName("header");
paramList.add(new RestParam(0, hp, int.class));
when(restOperation.getParamList()).thenReturn(paramList);
}
use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class TestPath method testUrlPathBuilder.
@Test
public void testUrlPathBuilder() throws Exception {
Map<String, RestParam> paramMap = new HashMap<>();
Parameter pathParameter = new PathParameter();
pathParameter.setName("id");
RestParam oRestParam = new RestParam(0, pathParameter, int.class);
paramMap.put(oRestParam.getParamName(), oRestParam);
Parameter queryParameter = new QueryParameter();
queryParameter.setName("q");
oRestParam = new RestParam(1, queryParameter, String.class);
paramMap.put(oRestParam.getParamName(), oRestParam);
URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
Object[] args = new Object[] { 100, "query" };
Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(args));
Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(args));
}
use of io.swagger.models.parameters.Parameter 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);
}
}
use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class AnnotationUtils method createParameter.
public static Parameter createParameter(Swagger swagger, ApiImplicitParam paramAnnotation) {
Parameter parameter = createParameterInstance(paramAnnotation);
Type dataType = ReflectionUtils.typeFromString(paramAnnotation.dataType());
parameter = ParameterProcessor.applyAnnotations(swagger, parameter, dataType, Arrays.asList(paramAnnotation));
return parameter;
}
Aggregations