Search in sources :

Example 1 with Property

use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.

the class SwaggerGenerator method buildDefinitionProperties.

private void buildDefinitionProperties(Map<String, Property> properties, List<String> required, Entity entity, boolean includeAuto, boolean includeId) {
    if (includeId) {
        properties.put(Constants.Util.ID_FIELD_NAME, new Property(INTEGER_TYPE, INT64_FORMAT));
    }
    for (Field field : entity.getFields()) {
        final String fieldName = field.getName();
        if (field.isExposedViaRest()) {
            // auto generated fields included only in responses
            if (!field.isAutoGenerated() || includeAuto) {
                Property property = SwaggerFieldConverter.fieldToProperty(field);
                properties.put(fieldName, property);
                if (field.isRequired()) {
                    required.add(fieldName);
                }
            }
        }
    }
}
Also used : Field(org.motechproject.mds.domain.Field) Property(org.motechproject.mds.docs.swagger.model.Property)

Example 2 with Property

use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.

the class SwaggerGenerator method buildMetadataDefinition.

private Definition buildMetadataDefinition() {
    final Definition definition = new Definition();
    final Map<String, Property> properties = new LinkedHashMap<>();
    properties.put("entity", new Property(STRING_TYPE));
    properties.put("className", new Property(STRING_TYPE));
    properties.put("module", new Property(STRING_TYPE));
    properties.put("namespace", new Property(STRING_TYPE));
    properties.put("totalCount", new Property(INTEGER_TYPE, INT64_FORMAT));
    properties.put("page", new Property(INTEGER_TYPE, INT32_FORMAT));
    properties.put("pageSize", new Property(INTEGER_TYPE, INT32_FORMAT));
    final List<String> required = new ArrayList<>();
    required.add("totalCount");
    required.add("page");
    required.add("pageSize");
    required.add("module");
    required.add("entity");
    required.add("namespace");
    required.add("className");
    definition.setProperties(properties);
    definition.setRequired(required);
    return definition;
}
Also used : Definition(org.motechproject.mds.docs.swagger.model.Definition) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.docs.swagger.model.Property) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Property

use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.

the class SwaggerGenerator method definitionWithMetadata.

private Definition definitionWithMetadata(Entity entity) {
    final Definition definition = new Definition();
    Property metadata = new Property();
    metadata.setRef(definitionPath("Metadata"));
    Property data = new Property(ARRAY_TYPE);
    data.setRef(definitionPath(entity.getClassName()));
    final Map<String, Property> properties = new LinkedHashMap<>();
    properties.put("metadata", metadata);
    properties.put("data", data);
    final List<String> required = new ArrayList<>();
    required.add("metadata");
    required.add("data");
    definition.setProperties(properties);
    definition.setRequired(required);
    return definition;
}
Also used : Definition(org.motechproject.mds.docs.swagger.model.Definition) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.docs.swagger.model.Property) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Property

use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.

the class SwaggerFieldConverter method fieldToProperty.

/**
 * Converts the given field based on its type to a Swagger property.
 * @param field the field to be converted
 * @return the Swagger property version of the given fields type
 */
public static Property fieldToProperty(Field field) {
    final String typeClass = field.getType().getTypeClassName();
    Property property = toNumberProperty(typeClass);
    if (property != null) {
        return property;
    }
    property = toDateProperty(typeClass);
    if (property != null) {
        return property;
    }
    property = toComboboxProperty(field);
    if (property != null) {
        return property;
    }
    return toMiscProperty(typeClass);
}
Also used : Property(org.motechproject.mds.docs.swagger.model.Property)

Example 5 with Property

use of org.motechproject.mds.docs.swagger.model.Property in project motech by motech.

the class SwaggerFieldConverter method lookupParameter.

public static Parameter lookupParameter(String lookupFieldName, Field field, LookupFieldType lookupFieldType, String paramDescription) {
    // first convert this to property
    Property property;
    if (lookupFieldType == LookupFieldType.RANGE) {
        // range is a string in the format of 1..5
        property = new Property(STRING_TYPE);
    } else {
        property = fieldToProperty(field);
        // in case of a set we nest the property
        if (lookupFieldType == LookupFieldType.SET) {
            property = new Property(ARRAY_TYPE, property);
        }
    }
    // then convert to a parameter
    Parameter parameter = new Parameter(property);
    parameter.setName(lookupFieldName);
    parameter.setIn(ParameterType.QUERY);
    parameter.setDescription(paramDescription);
    return parameter;
}
Also used : Parameter(org.motechproject.mds.docs.swagger.model.Parameter) 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