Search in sources :

Example 96 with ArraySchema

use of io.swagger.v3.oas.annotations.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 97 with ArraySchema

use of io.swagger.v3.oas.annotations.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 98 with ArraySchema

use of io.swagger.v3.oas.annotations.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 99 with ArraySchema

use of io.swagger.v3.oas.annotations.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 100 with ArraySchema

use of io.swagger.v3.oas.annotations.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)107 Schema (io.swagger.v3.oas.models.media.Schema)85 Test (org.testng.annotations.Test)76 StringSchema (io.swagger.v3.oas.models.media.StringSchema)63 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)53 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)53 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)51 OpenAPI (io.swagger.v3.oas.models.OpenAPI)49 MapSchema (io.swagger.v3.oas.models.media.MapSchema)28 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)22 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)21 PathItem (io.swagger.v3.oas.models.PathItem)16 Parameter (io.swagger.v3.oas.models.parameters.Parameter)16 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)16 MediaType (io.swagger.v3.oas.models.media.MediaType)15 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)15 Operation (io.swagger.v3.oas.models.Operation)14 Content (io.swagger.v3.oas.models.media.Content)12 DateSchema (io.swagger.v3.oas.models.media.DateSchema)11 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)11