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);
}
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"));
}
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);
}
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);
}
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");
}
Aggregations