use of io.swagger.models.properties.ArrayProperty in project swagger-core by swagger-api.
the class ModelImplTest method testClone.
@Test
public void testClone() {
// given
propertiesAndValues = new Object[] { "additionalProperties", new ArrayProperty(), "description", "description", "discriminator", "discriminator", "example", new Object(), "isSimple", true, "name", "name", "properties", new HashMap<String, Property>(), "required", new ArrayList<String>(), "type", "type", "xml", new Xml(), "defaultValue", "defaultValue" };
TestUtils.testClone(instance, propertiesAndValues);
}
use of io.swagger.models.properties.ArrayProperty in project java-chassis by ServiceComb.
the class TestApiOperation method testSet.
private void testSet(Path path) {
Operation operation = path.getPost();
Property result200 = operation.getResponses().get("200").getSchema();
Assert.assertEquals(ArrayProperty.class, result200.getClass());
Assert.assertEquals(true, ((ArrayProperty) result200).getUniqueItems());
}
use of io.swagger.models.properties.ArrayProperty in project java-chassis by ServiceComb.
the class TestApiOperation method testList.
private void testList(Path path) {
Operation operation = path.getPost();
Property result200 = operation.getResponses().get("200").getSchema();
Assert.assertEquals(ArrayProperty.class, result200.getClass());
Assert.assertEquals(null, ((ArrayProperty) result200).getUniqueItems());
}
use of io.swagger.models.properties.ArrayProperty in project herd by FINRAOS.
the class DefinitionGenerator method getPropertyFromType.
/**
* Gets a property from the given fieldType. This method may be called recursively.
*
* @param fieldType the field type class.
*
* @return the property.
* @throws MojoExecutionException if any problems were encountered.
*/
private Property getPropertyFromType(Class<?> fieldType) throws MojoExecutionException {
Property property;
if (String.class.isAssignableFrom(fieldType)) {
property = new StringProperty();
} else if (Integer.class.isAssignableFrom(fieldType) || int.class.isAssignableFrom(fieldType)) {
property = new IntegerProperty();
} else if (Long.class.isAssignableFrom(fieldType) || long.class.isAssignableFrom(fieldType)) {
property = new LongProperty();
} else if (BigDecimal.class.isAssignableFrom(fieldType)) {
property = new DecimalProperty();
} else if (XMLGregorianCalendar.class.isAssignableFrom(fieldType)) {
property = new DateTimeProperty();
} else if (Boolean.class.isAssignableFrom(fieldType) || boolean.class.isAssignableFrom(fieldType)) {
property = new BooleanProperty();
} else if (Collection.class.isAssignableFrom(fieldType)) {
property = new ArrayProperty(new StringProperty());
} else if (fieldType.getAnnotation(XmlEnum.class) != null) {
/*
* Enums are a string property which have enum constants
*/
List<String> enums = new ArrayList<>();
for (Enum<?> anEnum : (Enum<?>[]) fieldType.getEnumConstants()) {
enums.add(anEnum.name());
}
property = new StringProperty()._enum(enums);
} else /*
* Recursively process complex objects which is a XmlType
*/
if (fieldType.getAnnotation(XmlType.class) != null) {
processDefinitionClass(fieldType);
property = new RefProperty(fieldType.getAnnotation(XmlType.class).name());
} else {
// Default to a string property in other cases.
property = new StringProperty();
}
log.debug("Field type \"" + fieldType.getName() + "\" is a property type \"" + property.getType() + "\".");
return property;
}
use of io.swagger.models.properties.ArrayProperty in project herd by FINRAOS.
the class DefinitionGenerator method processField.
/**
* Processes a Field of a model class which can be converted into a Swagger definition property. The property is added into the given model. This method may
* be called recursively.
*
* @param field the field to process.
* @param model model the model.
*
* @throws MojoExecutionException if any problems were encountered.
*/
private void processField(Field field, ModelImpl model) throws MojoExecutionException {
log.debug("Processing field \"" + field.getName() + "\".");
if (!Modifier.isStatic(field.getModifiers())) {
Property property;
Class<?> fieldClass = field.getType();
if (Collection.class.isAssignableFrom(fieldClass)) {
property = new ArrayProperty(getPropertyFromType(FieldUtils.getCollectionType(field)));
} else {
property = getPropertyFromType(fieldClass);
}
// Set the required field based on the XmlElement that comes from the XSD.
XmlElement xmlElement = field.getAnnotation(XmlElement.class);
if (xmlElement != null) {
property.setRequired(xmlElement.required());
}
if (xsdParser != null) {
property.setDescription(xsdParser.getAnnotation(model.getName(), field.getName()));
}
// Set the property on model.
model.property(field.getName(), property);
}
}
Aggregations