use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class SwaggerJersey2JaxrsTest method returnProperBeanParam.
@Test(description = "return the proper @BeanParam Parameters based on the call to extractParameters")
public void returnProperBeanParam() throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod("testRoute", BaseBean.class, ChildBean.class, RefBean.class, EnumBean.class, Integer.class);
final List<Pair<Type, Annotation[]>> parameters = getParameters(method.getGenericParameterTypes(), method.getParameterAnnotations());
for (Pair<Type, Annotation[]> parameter : parameters) {
Type parameterType = parameter.first();
List<Parameter> swaggerParams = new SwaggerJersey2Jaxrs().extractParameters(Arrays.asList(parameter.second()), parameterType, new HashSet<Type>(), SwaggerExtensions.chain());
// Ensure proper number of parameters returned
if (parameterType.equals(BaseBean.class)) {
assertEquals(swaggerParams.size(), 2);
} else if (parameterType.equals(ChildBean.class)) {
assertEquals(swaggerParams.size(), 5);
} else if (parameterType.equals(RefBean.class)) {
assertEquals(swaggerParams.size(), 5);
} else if (parameterType.equals(EnumBean.class)) {
assertEquals(swaggerParams.size(), 1);
HeaderParameter enumParam = (HeaderParameter) swaggerParams.get(0);
assertEquals(enumParam.getType(), "string");
final Set<String> enumValues = Sets.newHashSet(Collections2.transform(Arrays.asList(TestEnum.values()), Functions.toStringFunction()));
assertEquals(enumParam.getEnum(), enumValues);
} else if (parameterType.equals(Integer.class)) {
assertEquals(swaggerParams.size(), 0);
} else {
fail(String.format("Parameter of type %s was not expected", parameterType));
}
// Ensure the proper parameter type and name is returned (The rest is handled by pre-existing logic)
for (Parameter param : swaggerParams) {
assertEquals(param.getName(), param.getClass().getSimpleName().replace("eter", ""));
}
}
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class PathTest method testParameters.
@Test
public void testParameters() {
// given
Path path = new Path();
Parameter parameter = Mockito.mock(Parameter.class);
path.setParameters(null);
// when
path.addParameter(parameter);
// then
assertTrue(path.getParameters().contains(parameter), "The parameters list must contain the newly added one");
}
use of io.swagger.models.parameters.Parameter in project swagger-core by swagger-api.
the class ImplicitParametersTest method detailedTest.
@Test
public void detailedTest() throws NoSuchMethodException {
final Operation operation = new Operation();
final ReaderContext context = createDefaultContext();
extension.applyImplicitParameters(context, operation, findMethod(context, "testMethod3"));
final List<Parameter> parameters = operation.getParameters();
final Parameter parameter1 = parameters.get(0);
Assert.assertNotNull(parameter1);
Assert.assertTrue(parameter1 instanceof PathParameter);
Assert.assertEquals(parameter1.getName(), "param1");
Assert.assertEquals(parameter1.getIn(), "path");
Assert.assertEquals(parameter1.getDescription(), "Param 1");
Assert.assertTrue(parameter1.getRequired());
final Parameter parameter5 = parameters.get(4);
Assert.assertNotNull(parameter5);
Assert.assertTrue(parameter5 instanceof BodyParameter);
Assert.assertEquals(parameter5.getName(), "param5");
Assert.assertEquals(parameter5.getIn(), "body");
Assert.assertEquals(parameter5.getDescription(), "Param 5");
Assert.assertFalse(parameter5.getRequired());
}
use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class ApiImplicitParamMethodProcessor method process.
@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
ApiImplicitParam paramAnnotation = (ApiImplicitParam) annotation;
Parameter parameter = AnnotationUtils.createParameter(operationGenerator.getSwagger(), paramAnnotation);
operationGenerator.addMethodAnnotationParameter(parameter);
}
use of io.swagger.models.parameters.Parameter in project java-chassis by ServiceComb.
the class OperationGenerator method processBodyBasedParameter.
protected void processBodyBasedParameter() {
List<BodyParameter> bodyParameters = collectBodyBasedParameters();
if (bodyParameters.isEmpty()) {
return;
}
if (bodyParameters.size() == 1) {
Parameter bodyParameter = bodyParameters.get(0);
replaceBodyBasedParameter(bodyParameter);
return;
}
// 将多个pending合并成一个body
mergeBodyBasedParameters(bodyParameters);
}
Aggregations