Search in sources :

Example 21 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class PropertyDeserializerTest method deserializePropertyWithMinimumMaximumValues.

@Test
public void deserializePropertyWithMinimumMaximumValues() throws Exception {
    String json = "{\n" + "  \"type\": \"integer\",\n" + "  \"format\": \"int32\",\n" + "  \"minimum\": 32,\n" + "  \"maximum\": 100\n" + "}";
    Schema param = Json.mapper().readValue(json, Schema.class);
    IntegerSchema ip = (IntegerSchema) param;
    assertEquals(ip.getMinimum(), new BigDecimal("32"));
    assertEquals(ip.getMaximum(), new BigDecimal("100"));
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 22 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class ModelPropertyTest method extractPrimitiveArray.

@Test
public void extractPrimitiveArray() {
    final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithPrimitiveArray.class);
    assertEquals(models.size(), 1);
    final Schema model = models.get("ModelWithPrimitiveArray");
    final ArraySchema longArray = (ArraySchema) model.getProperties().get("longArray");
    final Schema longArrayItems = longArray.getItems();
    assertTrue(longArrayItems instanceof IntegerSchema);
    final ArraySchema intArray = (ArraySchema) model.getProperties().get("intArray");
    assertTrue(intArray.getItems() instanceof IntegerSchema);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Test(org.testng.annotations.Test)

Example 23 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class ModelExampleTest method createModelWithExample.

@Test(description = "it should create a model with example")
public void createModelWithExample() {
    ObjectSchema model = new ObjectSchema();
    model.addProperties("name", new StringSchema().example("Tony"));
    model.addProperties("id", new IntegerSchema().example(123));
    model.example("{\"name\":\"Fred\",\"id\":123456\"}");
    assertEquals(model.getExample(), "{\"name\":\"Fred\",\"id\":123456\"}");
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 24 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class BeanValidatorTest method readBeanValidatorTest.

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

Example 25 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method serializeIntegerMapProperty.

@Test(description = "it should serialize a integer MapProperty")
public void serializeIntegerMapProperty() throws IOException {
    final Schema p = new MapSchema().additionalProperties(new IntegerSchema());
    final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : FileSchema(io.swagger.v3.oas.models.media.FileSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)33 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 Schema (io.swagger.v3.oas.models.media.Schema)24 StringSchema (io.swagger.v3.oas.models.media.StringSchema)23 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)14 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)8 Parameter (io.swagger.v3.oas.models.parameters.Parameter)8 BigDecimal (java.math.BigDecimal)8 OpenAPI (io.swagger.v3.oas.models.OpenAPI)7 Info (io.swagger.v3.oas.models.info.Info)7 DateSchema (io.swagger.v3.oas.models.media.DateSchema)6 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)6 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)6 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)6 Components (io.swagger.v3.oas.models.Components)5 Operation (io.swagger.v3.oas.models.Operation)5 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)5 MapSchema (io.swagger.v3.oas.models.media.MapSchema)5 PathItem (io.swagger.v3.oas.models.PathItem)4 Contact (io.swagger.v3.oas.models.info.Contact)4