Search in sources :

Example 6 with Property

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);
}
Also used : Property(org.motechproject.mds.docs.swagger.model.Property) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 7 with Property

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());
    }
}
Also used : Property(org.motechproject.mds.docs.swagger.model.Property)

Example 8 with Property

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);
}
Also used : Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Property(org.motechproject.mds.docs.swagger.model.Property) Test(org.junit.Test)

Example 9 with Property

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;
    }
}
Also used : ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) Property(org.motechproject.mds.docs.swagger.model.Property)

Example 10 with Property

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());
}
Also used : Property(org.motechproject.mds.docs.swagger.model.Property)

Aggregations

Property (org.motechproject.mds.docs.swagger.model.Property)12 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Definition (org.motechproject.mds.docs.swagger.model.Definition)3 Test (org.junit.Test)2 Parameter (org.motechproject.mds.docs.swagger.model.Parameter)2 Field (org.motechproject.mds.domain.Field)2 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 Response (org.motechproject.mds.docs.swagger.model.Response)1 ResponseWithSchema (org.motechproject.mds.docs.swagger.model.ResponseWithSchema)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 Entity (org.motechproject.mds.domain.Entity)1