use of io.swagger.models.properties.DecimalProperty in project swagger-core by swagger-api.
the class AbstractSerializableParameterTest method testGetExampleWithDecimalProperty.
@Test
public void testGetExampleWithDecimalProperty() {
// given
instance.setProperty(new DecimalProperty());
example = "14.1";
// when
instance.setExample(example);
// then
assertEquals(instance.getExample(), 14.1, "The get example must be the same as the set one");
// given
example = "wrong format";
// when
instance.setExample(example);
// then
assertEquals(instance.getExample(), example, "The example value must not change when the format is wrong");
// when
instance.setProperty(new ArrayProperty());
// then
assertEquals(instance.getExample(), example, "The example value must not change when when set an array property");
}
use of io.swagger.models.properties.DecimalProperty in project swagger-core by swagger-api.
the class AbstractSerializableParameterTest method testGetDefaultWithDecimalProperty.
@Test
public void testGetDefaultWithDecimalProperty() {
// given
instance.setProperty(new DecimalProperty());
defaultValue = 14.1;
// when
instance.setDefault(defaultValue);
// then
assertEquals(instance.getDefault(), 14.1, "The get default must be the same as the set one");
// given
defaultValue = "wrong format";
// when
instance.setDefault(defaultValue);
// then
assertEquals(instance.getDefault(), defaultValue, "The get default must be the same as the set one");
// when
instance.setProperty(new ArrayProperty());
assertEquals(instance.getDefault(), defaultValue, "Default must not change when we set an array property");
}
use of io.swagger.models.properties.DecimalProperty 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;
}
Aggregations