Search in sources :

Example 1 with DecimalProperty

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");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Test(org.testng.annotations.Test)

Example 2 with DecimalProperty

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");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Test(org.testng.annotations.Test)

Example 3 with DecimalProperty

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;
}
Also used : XmlEnum(javax.xml.bind.annotation.XmlEnum) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) StringProperty(io.swagger.models.properties.StringProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) BigDecimal(java.math.BigDecimal) XmlType(javax.xml.bind.annotation.XmlType) RefProperty(io.swagger.models.properties.RefProperty) LongProperty(io.swagger.models.properties.LongProperty) ArrayList(java.util.ArrayList) List(java.util.List) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property)

Aggregations

ArrayProperty (io.swagger.models.properties.ArrayProperty)3 DecimalProperty (io.swagger.models.properties.DecimalProperty)3 Test (org.testng.annotations.Test)2 BooleanProperty (io.swagger.models.properties.BooleanProperty)1 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)1 IntegerProperty (io.swagger.models.properties.IntegerProperty)1 LongProperty (io.swagger.models.properties.LongProperty)1 Property (io.swagger.models.properties.Property)1 RefProperty (io.swagger.models.properties.RefProperty)1 StringProperty (io.swagger.models.properties.StringProperty)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 XmlEnum (javax.xml.bind.annotation.XmlEnum)1 XmlType (javax.xml.bind.annotation.XmlType)1