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