use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.
the class SwaggerFieldConverterTest method shouldConvertFieldsToProperties.
@Test
public void shouldConvertFieldsToProperties() {
Property property = SwaggerFieldConverter.fieldToProperty(field(DateTime.class));
verifySimpleProperty(property, "string", "date-time");
property = SwaggerFieldConverter.fieldToProperty(field(Date.class));
verifySimpleProperty(property, "string", "date-time");
property = SwaggerFieldConverter.fieldToProperty(field(LocalDate.class));
verifySimpleProperty(property, "string", "date");
property = SwaggerFieldConverter.fieldToProperty(field(String.class));
verifySimpleProperty(property, "string", null);
property = SwaggerFieldConverter.fieldToProperty(field(Locale.class));
verifySimpleProperty(property, "string", null);
property = SwaggerFieldConverter.fieldToProperty(field(Integer.class));
verifySimpleProperty(property, "integer", "int32");
property = SwaggerFieldConverter.fieldToProperty(field(Long.class));
verifySimpleProperty(property, "integer", "int64");
property = SwaggerFieldConverter.fieldToProperty(field(Double.class));
verifySimpleProperty(property, "number", "double");
property = SwaggerFieldConverter.fieldToProperty(field(Boolean.class));
verifySimpleProperty(property, "boolean", null);
}
use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.
the class SwaggerFieldConverterTest method verifyComboboxProperty.
private void verifyComboboxProperty(Property property, boolean shouldProvideEnumList) {
assertNotNull(property);
assertEquals("array", property.getType());
assertNull(property.getFormat());
Property items = property.getItems();
assertNotNull(items);
assertEquals("string", items.getType());
assertNull(items.getFormat());
if (shouldProvideEnumList) {
assertEquals(asList("a", "b", "c"), items.getEnumValues());
} else {
assertNull(items.getEnumValues());
}
}
use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.
the class SwaggerFieldConverterTest method shouldConvertComboboxes.
@Test
public void shouldConvertComboboxes() {
// not user-supplied
Property property = SwaggerFieldConverter.fieldToProperty(field(List.class));
verifySimpleProperty(property, "string", null);
Entity entity = new Entity("org.example.Something");
Field field = FieldTestHelper.fieldWithComboboxSettings(entity, "name", "disp name", List.class, true, false, asList("a", "b", "c"));
property = SwaggerFieldConverter.fieldToProperty(field);
verifyComboboxProperty(property, true);
// user-supplied
FieldTestHelper.setAllowUserSupplied(field, true);
property = SwaggerFieldConverter.fieldToProperty(field);
verifyComboboxProperty(property, false);
}
use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.
the class SwaggerFieldConverter method toComboboxProperty.
private static Property toComboboxProperty(Field field) {
if (field.getType().isCombobox()) {
ComboboxHolder cbHolder = new ComboboxHolder(field);
Property itemProperty = new Property(STRING_TYPE);
// user-supplied comoboxes are actually strings or list of strings
if (!cbHolder.isAllowUserSupplied()) {
itemProperty.setEnumValues(Arrays.asList(cbHolder.getValues()));
}
if (cbHolder.isAllowMultipleSelections()) {
return new Property(ARRAY_TYPE, itemProperty);
} else {
return itemProperty;
}
} else {
return null;
}
}
use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.
the class SwaggerGeneratorTest method verifyExampleEntDefinitionProps.
private void verifyExampleEntDefinitionProps(Map<String, Property> properties, boolean shouldIncludeAutoGenerated, boolean shouldIncludeId) {
int expectedPropCount = 6;
assertNotNull(properties);
verifyProperty(properties.get("doubleField"), "number", "double");
verifyProperty(properties.get("dateField"), "string", "date-time");
verifyProperty(properties.get("dtField"), "string", "date-time");
verifyProperty(properties.get("ldField"), "string", "date");
verifyProperty(properties.get("localeField"), "string");
Property listProp = properties.get("listField");
assertNotNull(listProp);
assertEquals("array", listProp.getType());
assertNull(listProp.getFormat());
Property itemProp = listProp.getItems();
assertEquals("string", itemProp.getType());
assertEquals(asList("one", "two", "three"), itemProp.getEnumValues());
assertNull(itemProp.getFormat());
assertNull(itemProp.getItems());
if (shouldIncludeAutoGenerated) {
// - 1 for the id field
expectedPropCount += Constants.Util.GENERATED_FIELD_NAMES.length - 1;
verifyAutoGeneratedProps(properties);
}
if (shouldIncludeId) {
expectedPropCount++;
verifyProperty(properties.get("id"), "integer", "int64");
}
assertEquals(expectedPropCount, properties.size());
}
Aggregations