Search in sources :

Example 16 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterProcessorTest method beanValidationMinTest.

@Test
public void beanValidationMinTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("beanValidationMin", int.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final QueryParameter param = (QueryParameter) ParameterProcessor.applyAnnotations(null, new QueryParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param);
    assertEquals(param.getMinimum(), new BigDecimal(5));
}
Also used : Type(java.lang.reflect.Type) QueryParameter(io.swagger.models.parameters.QueryParameter) Method(java.lang.reflect.Method) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 17 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterProcessorTest method parameterProcessorTest.

@Test(description = "parse parameters from method")
public void parameterProcessorTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("parametrizedMethod", String.class, List.class, String.class, String.class, Integer.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final PathParameter p1 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(p1);
    assertEquals(p1.getIn(), "path");
    assertEquals(p1.getName(), "paramName1");
    assertEquals(p1.getDescription(), "paramValue1");
    assertEquals(p1.getDefaultValue(), "value1");
    assertTrue(p1.getRequired());
    assertEquals(p1.getEnum(), Arrays.asList("one", "two", "three"));
    assertNull(p1.getAccess());
    final QueryParameter p2 = (QueryParameter) ParameterProcessor.applyAnnotations(null, new QueryParameter().items(new IntegerProperty()), genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
    assertNotNull(p2);
    final IntegerProperty items = (IntegerProperty) p2.getItems();
    assertNotNull(items);
    assertEquals(p2.getIn(), "query");
    assertEquals(p2.getName(), "paramName2");
    assertNull(p2.getDescription());
    assertEquals((int) items.getDefault(), 10);
    assertFalse(p2.getRequired());
    assertEquals(p2.getAccess(), "test");
    final Parameter p3 = ParameterProcessor.applyAnnotations(null, null, genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
    assertNull(p3);
    final Parameter p4 = ParameterProcessor.applyAnnotations(null, null, genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
    assertNull(p4);
    final BodyParameter p5 = (BodyParameter) ParameterProcessor.applyAnnotations(null, null, genericParameterTypes[4], Arrays.asList(paramAnnotations[4]));
    assertNotNull(p5);
    assertEquals(p5.getIn(), "body");
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) Type(java.lang.reflect.Type) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Method(java.lang.reflect.Method) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 18 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterProcessorTest method beanValidationPatternTest.

@Test
public void beanValidationPatternTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("beanValidationPattern", String.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final QueryParameter param = (QueryParameter) ParameterProcessor.applyAnnotations(null, new QueryParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param);
    assertEquals(param.getPattern(), TEST_PATTERN_REGXP);
}
Also used : Type(java.lang.reflect.Type) QueryParameter(io.swagger.models.parameters.QueryParameter) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Example 19 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterProcessorTest method beanValidationSizeOnStringTest.

@Test
public void beanValidationSizeOnStringTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("beanValidationSizeOnString", String.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final QueryParameter param = (QueryParameter) ParameterProcessor.applyAnnotations(null, new QueryParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param);
    assertEquals(param.getMinLength(), new Integer(5));
    assertEquals(param.getMaxLength(), new Integer(10));
}
Also used : BigInteger(java.math.BigInteger) Type(java.lang.reflect.Type) QueryParameter(io.swagger.models.parameters.QueryParameter) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Example 20 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class GenericsTest method checkCollectionsOfEnumerations.

@Test(description = "check collections of enumerations")
public void checkCollectionsOfEnumerations() {
    Operation op = getOperation("testEnumContainers");
    assertEquals(op.getParameters().size(), 5);
    testEnumCollection(getQueryParameter(op, 0), "set");
    testEnumCollection(getQueryParameter(op, 1), "list");
    testCollection(getQueryParameter(op, 2), "list2D", "string", null);
    testEnumCollection(getQueryParameter(op, 3), "array");
    QueryParameter scalar = getQueryParameter(op, 4);
    testScalar(scalar, "scalar", "string", null);
    assertEquals(scalar.getEnum(), enumValues);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Aggregations

QueryParameter (io.swagger.models.parameters.QueryParameter)88 Test (org.testng.annotations.Test)58 Parameter (io.swagger.models.parameters.Parameter)41 PathParameter (io.swagger.models.parameters.PathParameter)34 BodyParameter (io.swagger.models.parameters.BodyParameter)28 Swagger (io.swagger.models.Swagger)25 HeaderParameter (io.swagger.models.parameters.HeaderParameter)15 Operation (io.swagger.models.Operation)11 FormParameter (io.swagger.models.parameters.FormParameter)11 Test (org.junit.Test)11 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 StringProperty (io.swagger.models.properties.StringProperty)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 Type (java.lang.reflect.Type)9 BigDecimal (java.math.BigDecimal)9 HashMap (java.util.HashMap)9 RefProperty (io.swagger.models.properties.RefProperty)8 Response (io.swagger.models.Response)7 Method (java.lang.reflect.Method)7