Search in sources :

Example 36 with AnnotatedType

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

the class InheritedBeanTest method testComposedUberObject.

@Test
public void testComposedUberObject() throws Exception {
    final Schema uberModel = context.resolve(new AnnotatedType(UberObject.class));
    assertNotNull(uberModel);
    // make sure child points at parent
    assertTrue(uberModel instanceof ComposedSchema);
    ComposedSchema cm = (ComposedSchema) uberModel;
    assertEquals(cm.getAnyOf().size(), 2);
    assertEquals(cm.getAnyOf().get(0).get$ref(), "#/components/schemas/UserObject");
    // parent properties are filtered out of subclass when parent doesn't define subtypes
    assertNotNull(cm.getProperties());
    assertEquals(cm.getProperties().size(), 3);
    final Schema interfaceModel = context.getDefinedModels().get("UserObject");
    assertNotNull(interfaceModel);
    assertUserObjectPropertiesValid(interfaceModel.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 37 with AnnotatedType

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

the class InheritedBeanTest method testInheritedChildBean.

@Test
public void testInheritedChildBean() throws Exception {
    final Schema subModel = context.resolve(new AnnotatedType(Sub1Bean.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/BaseBean");
    // make sure parent properties are filtered out of subclass
    assertSub1PropertiesValid(cm.getAllOf().get(1).getProperties());
    final Schema baseModel = context.getDefinedModels().get("BaseBean");
    assertNotNull(baseModel);
    assertBasePropertiesValid(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 38 with AnnotatedType

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

the class InheritedBeanTest method testMultipleInheritedBean.

@Test
public void testMultipleInheritedBean() throws Exception {
    final Schema baseModel = context.resolve(new AnnotatedType(MultipleBaseBean.class));
    assertNotNull(baseModel);
    assertBasePropertiesValid(baseModel.getProperties());
    final Schema sub1Model = context.getDefinedModels().get("MultipleSub1Bean");
    assertNotNull(sub1Model);
    // make sure child points at parent
    assertTrue(sub1Model instanceof ComposedSchema);
    ComposedSchema cm1 = (ComposedSchema) sub1Model;
    assertEquals(cm1.getAllOf().get(0).get$ref(), "#/components/schemas/MultipleBaseBean");
    // make sure parent properties are filtered out of subclass
    assertSub1PropertiesValid(cm1.getAllOf().get(1).getProperties());
    final Schema sub2Model = context.getDefinedModels().get("MultipleSub2Bean");
    assertNotNull(sub2Model);
    assertTrue(sub2Model instanceof ComposedSchema);
    ComposedSchema cm2 = (ComposedSchema) sub2Model;
    assertEquals(cm2.getAllOf().get(0).get$ref(), "#/components/schemas/MultipleBaseBean");
    // make sure parent properties are filtered out of subclass
    assertSub2PropertiesValid(cm2.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 39 with AnnotatedType

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

the class JodaTest method testSimple.

@Test
public void testSimple() throws Exception {
    final ModelConverter mr = modelResolver();
    final Schema model = mr.resolve(new AnnotatedType(ModelWithJodaDateTime.class), new ModelConverterContextImpl(mr), null);
    assertNotNull(model);
    final Map<String, Schema> props = model.getProperties();
    assertEquals(props.size(), 2);
    for (Map.Entry<String, Schema> entry : props.entrySet()) {
        final String name = entry.getKey();
        final Schema prop = entry.getValue();
        if ("name".equals(name)) {
            assertEquals(prop.getType(), "string");
        } else if ("createdAt".equals(name)) {
            assertEquals(prop.getType(), "string");
            assertEquals(prop.getFormat(), "date-time");
        } else {
            fail(String.format("Unknown property '%s'", name));
        }
    }
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Map(java.util.Map) ModelConverter(io.swagger.v3.core.converter.ModelConverter) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 40 with AnnotatedType

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

the class SimpleGenerationTest method testTheCountBean.

@Test
public void testTheCountBean() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(TheCount.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, "theCount");
}
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