Search in sources :

Example 81 with Property

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

the class BeanValidatorTest method readBeanValidatorTest.

@Test(description = "read bean validations")
public void readBeanValidatorTest() {
    final Map<String, Model> schemas = ModelConverters.getInstance().readAll(BeanValidationsModel.class);
    final Model model = schemas.get("BeanValidationsModel");
    final Map<String, Property> properties = model.getProperties();
    final IntegerProperty age = (IntegerProperty) properties.get("age");
    Assert.assertEquals(age.getMinimum(), new BigDecimal(13.0));
    Assert.assertEquals(age.getMaximum(), new BigDecimal(99.0));
    final StringProperty password = (StringProperty) properties.get("password");
    Assert.assertEquals((int) password.getMinLength(), 6);
    Assert.assertEquals((int) password.getMaxLength(), 20);
    final StringProperty email = (StringProperty) properties.get("email");
    Assert.assertEquals((String) email.getPattern(), "(.+?)@(.+?)");
    final DoubleProperty minBalance = (DoubleProperty) properties.get("minBalance");
    Assert.assertTrue(minBalance.getExclusiveMinimum());
    final DoubleProperty maxBalance = (DoubleProperty) properties.get("maxBalance");
    Assert.assertTrue(maxBalance.getExclusiveMaximum());
    final ArrayProperty items = (ArrayProperty) properties.get("items");
    Assert.assertEquals((int) items.getMinItems(), 2);
    Assert.assertEquals((int) items.getMaxItems(), 10);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BeanValidationsModel(io.swagger.models.BeanValidationsModel) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 82 with Property

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

the class RequiredFieldModelTest method testApiModelPropertyFirstPosition.

@Test(description = "it should apply read only flag when ApiProperty annotation first")
public void testApiModelPropertyFirstPosition() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(ApiFirstRequiredFieldModel.class);
    final Model model = models.get("aaa");
    final Property prop = model.getProperties().get("a");
    assertTrue(prop.getRequired());
}
Also used : ApiFirstRequiredFieldModel(io.swagger.models.ApiFirstRequiredFieldModel) XmlFirstRequiredFieldModel(io.swagger.models.XmlFirstRequiredFieldModel) Model(io.swagger.models.Model) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 83 with Property

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

the class RequiredFieldModelTest method testApiModelPropertySecondPosition.

@Test(description = "it should apply read only flag when XmlElement annotation first")
public void testApiModelPropertySecondPosition() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(XmlFirstRequiredFieldModel.class);
    final Model model = models.get("aaa");
    final Property prop = model.getProperties().get("a");
    assertTrue(prop.getRequired());
}
Also used : ApiFirstRequiredFieldModel(io.swagger.models.ApiFirstRequiredFieldModel) XmlFirstRequiredFieldModel(io.swagger.models.XmlFirstRequiredFieldModel) Model(io.swagger.models.Model) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 84 with Property

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

the class ModelSerializerTest method deserializeModelWithReadOnlyProperty.

@Test(description = "it should deserialize a model with read-only property")
public void deserializeModelWithReadOnlyProperty() throws IOException {
    final String json = "{\n" + "   \"properties\":{\n" + "      \"id\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\",\n" + "         \"readOnly\":true\n" + "      }\n" + "   }\n" + "}";
    final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
    Property property = model.getProperties().get("id");
    assertTrue(property.getReadOnly());
}
Also used : ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 85 with Property

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

the class ModelSerializerTest method readOnlyJsonGeneration.

/*
    @Test(description = "it should deserialize a model with custom format")
    public void deserializeModelWithCustomFormat() throws IOException {
        final String json = "{\n" +
                "   \"properties\":{\n" +
                "      \"id\":{\n" +
                "         \"type\":\"string\",\n" +
                "         \"format\":\"custom\"\n" +
                "      }\n" +
                "   }\n" +
                "}";
        final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
        Json.prettyPrint(model);
    }*/
@Test(description = "it should generate a JSON with read-only from pojo, #1161")
public void readOnlyJsonGeneration() throws IOException {
    Map<String, Model> models = ModelConverters.getInstance().read(io.swagger.models.ReadOnlyModel.class);
    Model model = models.get("ReadOnlyModel");
    Property id = model.getProperties().get("id");
    assertTrue(id.getReadOnly());
    Property readWriteId = model.getProperties().get("readWriteId");
    assertNull(readWriteId.getReadOnly());
}
Also used : Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) DateProperty(io.swagger.models.properties.DateProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Aggregations

Property (io.swagger.models.properties.Property)145 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)86 StringProperty (io.swagger.models.properties.StringProperty)75 RefProperty (io.swagger.models.properties.RefProperty)65 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)52 IntegerProperty (io.swagger.models.properties.IntegerProperty)48 LongProperty (io.swagger.models.properties.LongProperty)35 DoubleProperty (io.swagger.models.properties.DoubleProperty)32 FloatProperty (io.swagger.models.properties.FloatProperty)27 BooleanProperty (io.swagger.models.properties.BooleanProperty)25 ObjectProperty (io.swagger.models.properties.ObjectProperty)25 Operation (io.swagger.models.Operation)24 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)23 DateProperty (io.swagger.models.properties.DateProperty)22 ApiModelProperty (io.swagger.annotations.ApiModelProperty)20 FileProperty (io.swagger.models.properties.FileProperty)18 ModelImpl (io.swagger.models.ModelImpl)17 Response (io.swagger.models.Response)16