Search in sources :

Example 21 with ArraySchema

use of io.swagger.v3.oas.models.media.ArraySchema 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 22 with ArraySchema

use of io.swagger.v3.oas.models.media.ArraySchema 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 23 with ArraySchema

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

the class PropertySerializationTest method serializeArrayStringProperty.

@Test(description = "it should serialize a string array property")
public void serializeArrayStringProperty() throws IOException {
    final Schema p = new ArraySchema().items(new StringSchema());
    final String json = "{\"type\":\"array\",\"items\":{\"type\":\"string\"}}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) 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) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 24 with ArraySchema

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

the class ContainerTest method testArray.

@Test
public void testArray() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve(new AnnotatedType(ArrayBean.class));
    final Map<String, Schema> props = model.getProperties();
    assertEquals(1, props.size());
    final Schema prop = props.get("a");
    assertNotNull(prop);
    assertEquals(prop.getType(), "array");
    final Schema items = ((ArraySchema) prop).getItems();
    assertNotNull(items);
    assertEquals(items.getType(), "integer");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Example 25 with ArraySchema

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

the class XMLInfoTest method testSimple.

@Test
public void testSimple() throws Exception {
    final ModelConverter mr = modelResolver();
    ModelConverterContextImpl ctx = new ModelConverterContextImpl(mr);
    final Schema model = mr.resolve(new AnnotatedType(XmlDecoratedBean.class), ctx, null);
    final XML xml = model.getXml();
    assertNotNull(xml);
    assertEquals(xml.getName(), "xmlDecoratedBean");
    // Cast it to an array property
    final ArraySchema property = (ArraySchema) model.getProperties().get("elements");
    assertNotNull(property);
    final XML propertyXml = property.getXml();
    assertNotNull(propertyXml);
    assertNull(propertyXml.getName());
    assertTrue(propertyXml.getWrapped());
    // Get the xml for items for the array property
    final XML itemsXml = property.getItems().getXml();
    assertNotNull(itemsXml);
    // Check the name of item name
    assertEquals(itemsXml.getName(), "element");
    assertNotNull(model.getProperties().get("elementC"));
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) XML(io.swagger.v3.oas.models.media.XML) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ModelConverter(io.swagger.v3.core.converter.ModelConverter) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Aggregations

ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)32 Test (org.testng.annotations.Test)28 Schema (io.swagger.v3.oas.models.media.Schema)23 StringSchema (io.swagger.v3.oas.models.media.StringSchema)18 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)12 MapSchema (io.swagger.v3.oas.models.media.MapSchema)8 Parameter (io.swagger.v3.oas.models.parameters.Parameter)8 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)7 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)4 OpenAPI (io.swagger.v3.oas.models.OpenAPI)4 HeaderParameter (io.swagger.v3.oas.models.parameters.HeaderParameter)4 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)4 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)4 LinkedHashMap (java.util.LinkedHashMap)4 Operation (io.swagger.v3.oas.models.Operation)3 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)3 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)3 Annotation (java.lang.annotation.Annotation)3 BigDecimal (java.math.BigDecimal)3 Map (java.util.Map)3