Search in sources :

Example 11 with DoubleProperty

use of io.swagger.models.properties.DoubleProperty in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeDoubleProperty.

@Test(description = "it should deserialize a DoubleProperty")
public void deserializeDoubleProperty() throws IOException {
    final String json = "{\"type\":\"number\",\"format\":\"double\"}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "number");
    assertEquals(p.getFormat(), "double");
    assertEquals(p.getClass(), DoubleProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 12 with DoubleProperty

use of io.swagger.models.properties.DoubleProperty in project swagger-core by swagger-api.

the class AbstractSerializableParameter method setProperty.

public void setProperty(Property property) {
    setType(property.getType());
    this.format = property.getFormat();
    if (property instanceof StringProperty) {
        final StringProperty string = (StringProperty) property;
        setEnum(string.getEnum());
    } else if (property instanceof IntegerProperty) {
        setEnumValue(((IntegerProperty) property).getEnum());
    } else if (property instanceof LongProperty) {
        setEnumValue(((LongProperty) property).getEnum());
    } else if (property instanceof FloatProperty) {
        setEnumValue(((FloatProperty) property).getEnum());
    } else if (property instanceof DoubleProperty) {
        setEnumValue(((DoubleProperty) property).getEnum());
    } else if (property instanceof ArrayProperty) {
        final ArrayProperty array = (ArrayProperty) property;
        setItems(array.getItems());
    }
}
Also used : BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) StringProperty(io.swagger.models.properties.StringProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty)

Example 13 with DoubleProperty

use of io.swagger.models.properties.DoubleProperty in project swagger-core by swagger-api.

the class DoublePropertyTest method testEquals.

@Test
public void testEquals() {
    final DoubleProperty prop1 = new DoubleProperty();
    prop1.setName(PROP_1);
    prop1.setRequired(true);
    final DoubleProperty prop2 = new DoubleProperty();
    prop2.setName(PROP_2);
    assertNotEquals(prop1, prop2);
    prop2.setName(PROP_1);
    prop2.setRequired(true);
    assertEquals(prop1, prop2);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) Test(org.testng.annotations.Test)

Example 14 with DoubleProperty

use of io.swagger.models.properties.DoubleProperty in project swagger-parser by swagger-api.

the class ModelPropertyConverterTest method convertDoubleModelProperty.

@Test
public void convertDoubleModelProperty() throws Exception {
    ModelProperty property = new ModelProperty();
    property.setType("number");
    property.setFormat(Format.DOUBLE);
    property.setDescription("a simple double property");
    property.setMinimum("1.23");
    property.setMaximum("4.56");
    Property converted = converter.convertProperty(property);
    assertEquals(converted.getClass(), DoubleProperty.class);
    assertEquals(converted.getType(), "number");
    assertEquals(converted.getFormat(), "double");
    DoubleProperty prop = (DoubleProperty) converted;
    assertEquals(prop.getMinimum(), new BigDecimal("1.23"));
    assertEquals(prop.getMaximum(), new BigDecimal("4.56"));
}
Also used : ModelProperty(io.swagger.models.apideclaration.ModelProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ModelProperty(io.swagger.models.apideclaration.ModelProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 15 with DoubleProperty

use of io.swagger.models.properties.DoubleProperty in project springfox by springfox.

the class EnumMapper method maybeAddFacets.

@SuppressWarnings({ "NPathComplexity", "CyclomaticComplexity" })
static Property maybeAddFacets(Property property, ElementFacetSource facets) {
    if (facets == null) {
        return property;
    }
    facets.elementFacet(EnumerationFacet.class).ifPresent(f -> {
        if (property instanceof StringProperty) {
            StringProperty stringProperty = (StringProperty) property;
            stringProperty.setEnum(f.getAllowedValues());
        } else if (property instanceof IntegerProperty) {
            IntegerProperty integerProperty = (IntegerProperty) property;
            integerProperty.setEnum(convert(f.getAllowedValues(), Integer.class));
        } else if (property instanceof LongProperty) {
            LongProperty longProperty = (LongProperty) property;
            longProperty.setEnum(convert(f.getAllowedValues(), Long.class));
        } else if (property instanceof DoubleProperty) {
            DoubleProperty doubleProperty = (DoubleProperty) property;
            doubleProperty.setEnum(convert(f.getAllowedValues(), Double.class));
        } else if (property instanceof FloatProperty) {
            FloatProperty floatProperty = (FloatProperty) property;
            floatProperty.setEnum(convert(f.getAllowedValues(), Float.class));
        }
    });
    if (property instanceof AbstractNumericProperty) {
        facets.elementFacet(NumericElementFacet.class).ifPresent(f -> {
            AbstractNumericProperty numeric = (AbstractNumericProperty) property;
            numeric.setMaximum(f.getMaximum());
            numeric.exclusiveMaximum(f.getExclusiveMaximum());
            numeric.setMinimum(f.getMinimum());
            numeric.exclusiveMinimum(f.getExclusiveMinimum());
        });
    }
    if (property instanceof ArrayProperty) {
        facets.elementFacet(CollectionElementFacet.class).ifPresent(f -> {
            ArrayProperty arrayProperty = (ArrayProperty) property;
            arrayProperty.setMinItems(f.getMinItems());
            arrayProperty.setMaxItems(f.getMaxItems());
        });
    }
    if (property instanceof StringProperty) {
        StringProperty stringProperty = (StringProperty) property;
        facets.elementFacet(StringElementFacet.class).ifPresent(f -> {
            stringProperty.maxLength(f.getMaxLength());
            stringProperty.minLength(f.getMinLength());
            if (f.getPattern() != null) {
                stringProperty.pattern(f.getPattern());
            }
        });
    }
    return property;
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) CollectionElementFacet(springfox.documentation.schema.CollectionElementFacet) StringProperty(io.swagger.models.properties.StringProperty) NumericElementFacet(springfox.documentation.schema.NumericElementFacet) AbstractNumericProperty(io.swagger.models.properties.AbstractNumericProperty) LongProperty(io.swagger.models.properties.LongProperty) StringElementFacet(springfox.documentation.schema.StringElementFacet) DoubleProperty(io.swagger.models.properties.DoubleProperty) FloatProperty(io.swagger.models.properties.FloatProperty) EnumerationFacet(springfox.documentation.schema.EnumerationFacet)

Aggregations

DoubleProperty (io.swagger.models.properties.DoubleProperty)15 StringProperty (io.swagger.models.properties.StringProperty)13 IntegerProperty (io.swagger.models.properties.IntegerProperty)12 ArrayProperty (io.swagger.models.properties.ArrayProperty)11 LongProperty (io.swagger.models.properties.LongProperty)10 Property (io.swagger.models.properties.Property)9 FloatProperty (io.swagger.models.properties.FloatProperty)8 Test (org.testng.annotations.Test)8 BooleanProperty (io.swagger.models.properties.BooleanProperty)5 RefProperty (io.swagger.models.properties.RefProperty)5 BigDecimal (java.math.BigDecimal)4 DateProperty (io.swagger.models.properties.DateProperty)3 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)3 MapProperty (io.swagger.models.properties.MapProperty)3 Model (io.swagger.models.Model)2 Response (io.swagger.models.Response)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)2 AbstractNumericProperty (io.swagger.models.properties.AbstractNumericProperty)2 ObjectProperty (io.swagger.models.properties.ObjectProperty)2 ArrayList (java.util.ArrayList)2