use of io.swagger.models.parameters.HeaderParameter in project swagger-core by swagger-api.
the class ParameterProcessorTest method resourceWithArrayParamTest.
@Test
public void resourceWithArrayParamTest() throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod("arrayParametrizedMethod", List.class);
final Type[] genericParameterTypes = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
final HeaderParameter param = (HeaderParameter) ParameterProcessor.applyAnnotations(null, new HeaderParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
assertNotNull(param);
assertEquals((int) param.getMinItems(), 5);
assertEquals((int) param.getMaxItems(), 10);
}
use of io.swagger.models.parameters.HeaderParameter 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.HeaderParameter in project swagger-core by swagger-api.
the class ParameterProcessorTest method beanValidationArrayParametrizedMethodTest.
@Test
public void beanValidationArrayParametrizedMethodTest() throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod("beanValidationArrayParametrizedMethod", List.class, List.class, List.class, String.class);
final Type[] genericParameterTypes = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
//First param - items specified
HeaderParameter headerParam1 = new HeaderParameter().type(ArrayProperty.TYPE).items(new LongProperty());
HeaderParameter param1 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam1, genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
assertNotNull(param1);
assertEquals((int) param1.getMinItems(), 5);
assertEquals((int) param1.getMaxItems(), 10);
Property items1 = param1.getItems();
assertTrue(items1 instanceof LongProperty);
LongProperty longItems = (LongProperty) items1;
assertEquals(longItems.getMinimum(), new BigDecimal(5));
assertNull(longItems.getExclusiveMinimum());
assertEquals(longItems.getMaximum(), new BigDecimal(10));
assertNull(longItems.getExclusiveMaximum());
//Second param - items specified
HeaderParameter headerParam2 = new HeaderParameter().type(ArrayProperty.TYPE).items(new DoubleProperty());
HeaderParameter param2 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam2, genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
assertNotNull(param2);
assertEquals((int) param2.getMinItems(), 5);
assertEquals((int) param2.getMaxItems(), 10);
Property items2 = param2.getItems();
assertTrue(items2 instanceof DoubleProperty);
DoubleProperty doubleItems = (DoubleProperty) items2;
assertEquals(doubleItems.getMinimum(), new BigDecimal(5.5));
assertTrue(doubleItems.getExclusiveMinimum());
assertEquals(doubleItems.getMaximum(), new BigDecimal(10.5));
assertTrue(doubleItems.getExclusiveMaximum());
//Third param - items specified
HeaderParameter headerParam3 = new HeaderParameter().type(ArrayProperty.TYPE).items(new StringProperty());
HeaderParameter param3 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam3, genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
assertNotNull(param3);
assertEquals((int) param3.getMinItems(), 5);
assertEquals((int) param3.getMaxItems(), 10);
Property items3 = param3.getItems();
assertTrue(items3 instanceof StringProperty);
StringProperty stringItems = (StringProperty) items3;
assertEquals(stringItems.getPattern(), TEST_PATTERN_REGXP);
//Fourth param - items specified
HeaderParameter headerParam4 = new HeaderParameter().type(StringProperty.TYPE);
HeaderParameter param4 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam4, genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
assertNotNull(param4);
assertEquals(param4.getType(), ArrayProperty.TYPE);
assertEquals((int) param4.getMinItems(), 5);
assertEquals((int) param4.getMaxItems(), 10);
Property items4 = param4.getItems();
assertTrue(items4 instanceof StringProperty);
}
use of io.swagger.models.parameters.HeaderParameter in project swagger-core by swagger-api.
the class DefaultParameterExtension method extractParameters.
@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
if (shouldIgnoreType(type, typesToSkip)) {
return new ArrayList<Parameter>();
}
List<Parameter> parameters = new ArrayList<Parameter>();
Parameter parameter = null;
for (Annotation annotation : annotations) {
if (annotation instanceof QueryParam) {
QueryParam param = (QueryParam) annotation;
QueryParameter qp = new QueryParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
qp.setProperty(schema);
}
parameter = qp;
} else if (annotation instanceof PathParam) {
PathParam param = (PathParam) annotation;
PathParameter pp = new PathParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
pp.setProperty(schema);
}
parameter = pp;
} else if (annotation instanceof HeaderParam) {
HeaderParam param = (HeaderParam) annotation;
HeaderParameter hp = new HeaderParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
hp.setProperty(schema);
}
parameter = hp;
} else if (annotation instanceof CookieParam) {
CookieParam param = (CookieParam) annotation;
CookieParameter cp = new CookieParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
cp.setProperty(schema);
}
parameter = cp;
} else if (annotation instanceof FormParam) {
FormParam param = (FormParam) annotation;
FormParameter fp = new FormParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
fp.setProperty(schema);
}
parameter = fp;
} else {
handleAdditionalAnnotation(parameters, annotation, type, typesToSkip);
}
}
if (parameter != null) {
parameters.add(parameter);
}
return parameters;
}
use of io.swagger.models.parameters.HeaderParameter in project swagger-core by swagger-api.
the class Reader method readImplicitParam.
protected Parameter readImplicitParam(ApiImplicitParam param) {
final Parameter p;
if (param.paramType().equalsIgnoreCase("path")) {
p = new PathParameter();
} else if (param.paramType().equalsIgnoreCase("query")) {
p = new QueryParameter();
} else if (param.paramType().equalsIgnoreCase("form") || param.paramType().equalsIgnoreCase("formData")) {
p = new FormParameter();
} else if (param.paramType().equalsIgnoreCase("body")) {
p = null;
} else if (param.paramType().equalsIgnoreCase("header")) {
p = new HeaderParameter();
} else {
LOGGER.warn("Unknown implicit parameter type: [{}]", param.paramType());
return null;
}
final Type type = param.dataTypeClass() == Void.class ? ReflectionUtils.typeFromString(param.dataType()) : param.dataTypeClass();
return ParameterProcessor.applyAnnotations(swagger, p, (type == null) ? String.class : type, Arrays.<Annotation>asList(param));
}
Aggregations