use of io.swagger.jaxrs.DefaultParameterExtension in project swagger-core by swagger-api.
the class SwaggerJersey2JaxrsTest method returnProperBeanParamWithDefaultParameterExtension.
@Test(description = "return the proper @BeanParam Parameters based on the call to DefaultParameterExtension.extractParameters")
public void returnProperBeanParamWithDefaultParameterExtension() 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 DefaultParameterExtension().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", ""));
}
}
}
Aggregations