use of io.swagger.models.properties.IntegerProperty in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeEnumIntegerProperty.
@Test(description = "it should deserialize an IntegerProperty with enums")
public void deserializeEnumIntegerProperty() throws IOException {
final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
final Property p = m.readValue(json, Property.class);
assertEquals(p.getType(), "integer");
List<Integer> _enum = ((IntegerProperty) p).getEnum();
assertNotNull(_enum);
assertEquals(_enum, Arrays.asList(1, 2));
assertEquals(p.getClass(), IntegerProperty.class);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.models.properties.IntegerProperty in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeIntegerProperty.
@Test(description = "it should deserialize a IntegerProperty")
public void deserializeIntegerProperty() throws IOException {
final String json = "{\"type\":\"integer\",\"format\":\"int32\"}";
final Property p = m.readValue(json, Property.class);
assertEquals(p.getType(), "integer");
assertEquals(p.getFormat(), "int32");
assertEquals(p.getClass(), IntegerProperty.class);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.models.properties.IntegerProperty in project swagger-core by swagger-api.
the class ModelConverterTest method serializeParameterizedType.
@Test(description = "it should serialize a parameterized type per 606")
public void serializeParameterizedType() {
final Map<String, Model> schemas = readAll(Employee.class);
final ModelImpl employee = (ModelImpl) schemas.get("employee");
final Map<String, Property> props = employee.getProperties();
final Iterator<String> et = props.keySet().iterator();
final Property id = props.get(et.next());
assertTrue(id instanceof IntegerProperty);
final Property firstName = props.get(et.next());
assertTrue(firstName instanceof StringProperty);
final Property lastName = props.get(et.next());
assertTrue(lastName instanceof StringProperty);
final Property department = props.get(et.next());
assertTrue(department instanceof RefProperty);
final Property manager = props.get(et.next());
assertTrue(manager instanceof RefProperty);
final Property team = props.get(et.next());
assertTrue(team instanceof ArrayProperty);
final ArrayProperty ap = (ArrayProperty) team;
assertTrue(ap.getUniqueItems());
assertNotNull(employee.getXml());
assertEquals(employee.getXml().getName(), "employee");
}
use of io.swagger.models.properties.IntegerProperty 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");
}
use of io.swagger.models.properties.IntegerProperty in project swagger-core by swagger-api.
the class ParameterProcessorTest method resourceWithParamRangeTest.
@Test
public void resourceWithParamRangeTest() throws NoSuchMethodException {
final Method method = getClass().getDeclaredMethod("rangedParametrizedMethod", Integer.class, Double.class, Integer.class, Integer.class);
final Type[] genericParameterTypes = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
assertNotNull(param0);
assertEquals(param0.getDefaultValue(), "5");
assertEquals(param0.getMinimum(), new BigDecimal(0.0));
assertEquals(param0.getMaximum(), new BigDecimal(10.0));
assertEquals(param0.getCollectionFormat(), "multi");
final PathParameter param1 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
assertNotNull(param1);
assertEquals(param1.getMinimum(), new BigDecimal(0.0));
assertNull(param1.getMaximum(), null);
assertTrue(param1.isExclusiveMinimum());
assertTrue(param1.isExclusiveMaximum());
final PathParameter param2 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
assertNotNull(param2);
assertNull(param2.getMinimum());
assertEquals(param2.getMaximum(), new BigDecimal(100.0));
final PathParameter param3 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter().items(new IntegerProperty()), genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
assertNotNull(param3);
final IntegerProperty items = (IntegerProperty) param3.getItems();
assertNotNull(items);
assertEquals(items.getMinimum(), new BigDecimal(0.0));
assertEquals(items.getMaximum(), new BigDecimal(5.0));
assertTrue(items.getExclusiveMinimum());
assertTrue(items.getExclusiveMaximum());
}
Aggregations