Search in sources :

Example 6 with PathParameter

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

the class ParameterSerializationTest method deserializeIntegerArrayPathParameter.

@Test(description = "it should deserialize a PathParameter with integer array ")
public void deserializeIntegerArrayPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"type\":\"array\"," + "   \"items\":{" + "      \"type\":\"integer\"," + "      \"format\":\"int32\"" + "   }," + "   \"collectionFormat\":\"multi\"" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 7 with PathParameter

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

the class ParameterSerializationTest method deserializeEnumPathParameter.

@Test(description = "it should deserialize a path parameter with enum")
public void deserializeEnumPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"items\":{" + "      \"type\":\"string\"" + "   }," + "   \"enum\":[\"a\",\"b\",\"c\"]" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
    assertEquals(((PathParameter) p).getEnum(), Arrays.asList("a", "b", "c"));
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 8 with PathParameter

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

the class ParameterSerializationTest method deserializeStringArrayPathParameter.

@Test(description = "it should deserialize a PathParameter with string array")
public void deserializeStringArrayPathParameter() throws IOException {
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"type\":\"array\"," + "   \"items\":{" + "      \"type\":\"string\"" + "   }," + "   \"collectionFormat\":\"multi\"" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Example 9 with PathParameter

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

the class ParameterSerializationTest method serializeStringArrayPathParameter.

@Test(description = "it should serialize a PathParameter with string array")
public void serializeStringArrayPathParameter() {
    PathParameter p = new PathParameter().type(ArrayProperty.TYPE).items(new StringProperty()).collectionFormat("multi");
    final String json = "{" + "   \"in\":\"path\"," + "   \"required\":true," + "   \"type\":\"array\"," + "   \"items\":{" + "      \"type\":\"string\"" + "   }," + "   \"collectionFormat\":\"multi\"" + "}";
    SerializationMatchers.assertEqualsToJson(p, json);
    final String yaml = "---\n" + "in: \"path\"\n" + "required: true\n" + "type: \"array\"\n" + "items:\n" + "  type: \"string\"\n" + "collectionFormat: \"multi\"";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Also used : StringProperty(io.swagger.models.properties.StringProperty) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 10 with PathParameter

use of io.swagger.models.parameters.PathParameter 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)

Aggregations

PathParameter (io.swagger.models.parameters.PathParameter)51 QueryParameter (io.swagger.models.parameters.QueryParameter)35 Parameter (io.swagger.models.parameters.Parameter)32 Test (org.testng.annotations.Test)32 BodyParameter (io.swagger.models.parameters.BodyParameter)26 HeaderParameter (io.swagger.models.parameters.HeaderParameter)16 Swagger (io.swagger.models.Swagger)14 StringProperty (io.swagger.models.properties.StringProperty)12 FormParameter (io.swagger.models.parameters.FormParameter)11 Operation (io.swagger.models.Operation)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 Response (io.swagger.models.Response)8 IntegerProperty (io.swagger.models.properties.IntegerProperty)8 RefProperty (io.swagger.models.properties.RefProperty)8 Path (io.swagger.models.Path)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 HashMap (java.util.HashMap)6 ModelImpl (io.swagger.models.ModelImpl)5 RefModel (io.swagger.models.RefModel)5 ArrayList (java.util.ArrayList)5