Search in sources :

Example 6 with AnnotatedType

use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.

the class InheritedBeanTest method testHierarchy.

@Test
public void testHierarchy() throws Exception {
    final Schema baseModel = context.resolve(new AnnotatedType(BaseBean3.class));
    assertNotNull(baseModel);
    assertBasePropertiesValid(baseModel.getProperties());
    assertEquals(baseModel.getDiscriminator().getPropertyName(), "type");
    assertEquals(baseModel.getDiscriminator().getMapping().get("ChildBean3Mapped"), "#/components/schemas/ChildBean3");
    final Schema subModel = context.getDefinedModels().get("ChildBean3");
    assertNotNull(subModel);
    // make sure child points at parent
    assertTrue(subModel instanceof ComposedSchema);
    ComposedSchema cm = (ComposedSchema) subModel;
    assertEquals(cm.getAllOf().get(0).get$ref(), "#/components/schemas/BaseBean3");
    // make sure parent properties are filtered out of subclass
    assertSub1PropertiesValid(cm.getAllOf().get(1).getProperties());
    // assert grandchild
    final Schema subSubModel = context.getDefinedModels().get("GrandChildBean3");
    assertNotNull(subSubModel);
    // make sure child points at parent
    assertTrue(subSubModel instanceof ComposedSchema);
    cm = (ComposedSchema) subSubModel;
    assertEquals(cm.getAllOf().get(0).get$ref(), "#/components/schemas/ChildBean3");
    // make sure parent properties are filtered out of subclass
    assertSub2PropertiesValid(cm.getAllOf().get(1).getProperties());
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 7 with AnnotatedType

use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.

the class InheritedBeanTest method testInheritedBean.

@Test
public void testInheritedBean() throws Exception {
    final Schema baseModel = context.resolve(new AnnotatedType(BaseBean.class));
    assertNotNull(baseModel);
    assertBasePropertiesValid(baseModel.getProperties());
    assertEquals(baseModel.getDiscriminator().getPropertyName(), "type");
    assertEquals(baseModel.getDiscriminator().getMapping().get("Sub1BeanMapped"), "#/components/schemas/Sub1Bean");
    final Schema subModel = context.getDefinedModels().get("Sub1Bean");
    assertNotNull(subModel);
    // make sure child points at parent
    assertTrue(subModel instanceof ComposedSchema);
    ComposedSchema cm = (ComposedSchema) subModel;
    assertEquals(cm.getAllOf().get(0).get$ref(), "#/components/schemas/BaseBean");
    // make sure parent properties are filtered out of subclass
    assertSub1PropertiesValid(cm.getAllOf().get(1).getProperties());
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 8 with AnnotatedType

use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.

the class InheritedBeanTest method testComposedChildBean.

@Test
public void testComposedChildBean() throws Exception {
    final Schema subModel = context.resolve(new AnnotatedType(Sub2Bean.class));
    assertNotNull(subModel);
    // make sure child points at parent
    assertTrue(subModel instanceof ComposedSchema);
    ComposedSchema cm = (ComposedSchema) subModel;
    assertEquals(cm.getAllOf().get(0).get$ref(), "#/components/schemas/BaseBean2");
    // make sure parent properties are filtered out of subclass
    assertSub1PropertiesValid(cm.getAllOf().get(1).getProperties());
    final Schema baseModel = context.getDefinedModels().get("BaseBean2");
    assertNotNull(baseModel);
    assertBase2PropertiesValid(baseModel.getProperties());
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 9 with AnnotatedType

use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.

the class SimpleGenerationTest method testComplex.

@Test
public void testComplex() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(ComplexBean.class));
    assertNotNull(model);
    final Map<String, Schema> props = model.getProperties();
    assertEquals(props.size(), 6);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 10 with AnnotatedType

use of io.swagger.v3.core.converter.AnnotatedType in project swagger-core by swagger-api.

the class SimpleGenerationTest method testIntArray.

@Test
public void testIntArray() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(IntArrayBean.class));
    final Map<String, Schema> props = model.getProperties();
    assertEquals(props.size(), 1);
    String key = props.keySet().iterator().next();
    final Schema prop = props.get(key);
    assertEquals(key, "b");
    assertEquals(prop.getType(), "array");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Aggregations

Schema (io.swagger.v3.oas.models.media.Schema)60 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)57 Test (org.testng.annotations.Test)47 ModelConverterContextImpl (io.swagger.v3.core.converter.ModelConverterContextImpl)25 ModelResolver (io.swagger.v3.core.jackson.ModelResolver)21 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)14 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)13 AfterTest (org.testng.annotations.AfterTest)13 StringSchema (io.swagger.v3.oas.models.media.StringSchema)11 ModelConverter (io.swagger.v3.core.converter.ModelConverter)6 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)6 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)6 Annotation (java.lang.annotation.Annotation)6 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 JavaType (com.fasterxml.jackson.databind.JavaType)4 MapSchema (io.swagger.v3.oas.models.media.MapSchema)4 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)4 UUIDSchema (io.swagger.v3.oas.models.media.UUIDSchema)4 ArrayList (java.util.ArrayList)4