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