Search in sources :

Example 41 with AnnotatedType

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

the class SimpleGenerationTest method testSimple.

@Test
public void testSimple() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(SimpleBean.class));
    assertNotNull(model);
    assertEquals(model.getDescription(), "DESC");
    final Map<String, Schema> props = model.getProperties();
    assertEquals(props.size(), 6);
    for (Map.Entry<String, Schema> entry : props.entrySet()) {
        final String name = entry.getKey();
        final Schema prop = entry.getValue();
        if ("a".equals(name)) {
            assertEquals(prop.getType(), "string");
        } else if ("b".equals(name)) {
            assertEquals(prop.getType(), "integer");
            assertEquals(prop.getFormat(), "int32");
        } else if ("c".equals(name)) {
            assertEquals(prop.getType(), "integer");
            assertEquals(prop.getFormat(), "int64");
        } else if ("d".equals(name)) {
            assertEquals(prop.getType(), "number");
            assertEquals(prop.getFormat(), "float");
        } else if ("e".equals(name)) {
            assertEquals(prop.getType(), "number");
            assertEquals(prop.getFormat(), "double");
        } else if ("f".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) Test(org.testng.annotations.Test)

Example 42 with AnnotatedType

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

the class SimpleGenerationTest method testStringDateMap.

@Test
public void testStringDateMap() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(StringDateMapBean.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, "stuff");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 43 with AnnotatedType

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

the class SimpleGenerationTest method testOrdering.

@Test
public void testOrdering() throws Exception {
    final Schema jsonOrderBean = context.resolve(new AnnotatedType(JsonOrderBean.class));
    final Map<String, Schema> props = jsonOrderBean.getProperties();
    assertEquals(new ArrayList<String>(props.keySet()), Arrays.asList("a", "b", "c", "d"));
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 44 with AnnotatedType

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

the class Ticket2189Test method testTicket2189.

@Test
public void testTicket2189() {
    final Schema model = context.resolve(new AnnotatedType(BaseClass.class));
    assertNotNull(model);
    String yaml = "BaseClass:\n" + "  type: object\n" + "  properties:\n" + "    property:\n" + "      type: string\n" + "    type:\n" + "      type: string\n" + "SubClass:\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/BaseClass'\n" + "  - type: object\n" + "    properties:\n" + "      subClassProperty:\n" + "        type: string";
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), yaml);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 45 with AnnotatedType

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

the class Ticket2862SubtypeTest method testSubType.

@Test
public void testSubType() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve(new AnnotatedType(Ticket2862Model.class));
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Ticket2862Model:\n" + "  type: object\n" + "  properties:\n" + "    Ticket2862Model:\n" + "      type: object\n" + "Ticket2862ModelImpl:\n" + "  type: string\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Ticket2862Model'\n" + "  enum:\n" + "  - VALUE1\n" + "  - VALUE2\n");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Ticket2862Model(io.swagger.v3.core.resolving.resources.Ticket2862Model) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) 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