Search in sources :

Example 46 with AnnotatedType

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

the class Ticket2992Test method testLocalTime.

@Test
public void testLocalTime() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    Schema model = context.resolve(new AnnotatedType(TestObject2992.class));
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "LocalTime:\n" + "  type: object\n" + "  properties:\n" + "    hour:\n" + "      type: integer\n" + "      format: int32\n" + "    minute:\n" + "      type: integer\n" + "      format: int32\n" + "    second:\n" + "      type: integer\n" + "      format: int32\n" + "    nano:\n" + "      type: integer\n" + "      format: int32\n" + "TestObject2992:\n" + "  type: object\n" + "  properties:\n" + "    name:\n" + "      type: string\n" + "    a:\n" + "      $ref: '#/components/schemas/LocalTime'\n" + "    b:\n" + "      $ref: '#/components/schemas/LocalTime'\n" + "    c:\n" + "      $ref: '#/components/schemas/LocalTime'\n" + "    d:\n" + "      type: string\n" + "      format: date-time\n" + "    e:\n" + "      type: string\n" + "      format: date-time\n" + "    f:\n" + "      type: string\n" + "      format: date-time");
    PrimitiveType.enablePartialTime();
    context = new ModelConverterContextImpl(modelResolver);
    context.resolve(new AnnotatedType(TestObject2992.class));
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "TestObject2992:\n" + "  type: object\n" + "  properties:\n" + "    name:\n" + "      type: string\n" + "    a:\n" + "      type: string\n" + "      format: partial-time\n" + "    b:\n" + "      type: string\n" + "      format: partial-time\n" + "    c:\n" + "      type: string\n" + "      format: partial-time\n" + "    d:\n" + "      type: string\n" + "      format: date-time\n" + "    e:\n" + "      type: string\n" + "      format: date-time\n" + "    f:\n" + "      type: string\n" + "      format: date-time");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) TestObject2992(io.swagger.v3.core.resolving.resources.TestObject2992) Test(org.testng.annotations.Test)

Example 47 with AnnotatedType

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

the class Ticket2972Test method testLocalTime.

@Test
public void testLocalTime() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    Schema model = context.resolve(new AnnotatedType(TestObject2972.class));
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "TestObject2972:\n" + "  type: object\n" + "  properties:\n" + "    myField1:\n" + "      type: object\n" + "      additionalProperties:\n" + "        type: string\n" + "    myField2:\n" + "      type: object\n" + "      additionalProperties:\n" + "        type: string");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) TestObject2972(io.swagger.v3.core.resolving.resources.TestObject2972) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Example 48 with AnnotatedType

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

the class Ticket3197Test method testTicket3197.

@Test
public void testTicket3197() throws Exception {
    final Schema model = context.resolve(new AnnotatedType(Car.class));
    assertNotNull(model);
    String yaml = "Car:\n" + "  required:\n" + "  - type\n" + "  type: object\n" + "  properties:\n" + "    carMetaData:\n" + "      type: string\n" + "    type:\n" + "      type: string\n" + "  discriminator:\n" + "    propertyName: type\n" + "    mapping:\n" + "      RaceCar: '#/components/schemas/RaceCar'\n" + "      SportCar: '#/components/schemas/SportCar'\n" + "  oneOf:\n" + "  - $ref: '#/components/schemas/RaceCar'\n" + "  - $ref: '#/components/schemas/SportCar'\n" + "RaceCar:\n" + "  required:\n" + "  - carMetaData\n" + "  - id\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n" + "  - type: object\n" + "    properties:\n" + "      id:\n" + "        type: integer\n" + "        format: int64\n" + "      model:\n" + "        type: string\n" + "SportCar:\n" + "  required:\n" + "  - id\n" + "  type: object\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n" + "  - type: object\n" + "    properties:\n" + "      id:\n" + "        type: integer\n" + "        format: int64\n" + "      model:\n" + "        type: string\n";
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), yaml);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 49 with AnnotatedType

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

the class Ticket3365Test method testTicket3365.

@Test
public void testTicket3365() {
    Schema model = context.resolve(new AnnotatedType(ExampleWithJson.class));
    assertNotNull(model);
    SerializationMatchers.assertEqualsToYaml(model, "required:\n" + "- param1\n" + "type: object\n" + "properties:\n" + "  param1:\n" + "    title: Cron formatted invoice schedule\n" + "    type: object\n" + "    example:\n" + "      type: array\n" + "      items:\n" + "        type: string\n" + "        format: byte");
    model = context.resolve(new AnnotatedType(ExampleStartingWithInteger.class));
    assertNotNull(model);
    SerializationMatchers.assertEqualsToYaml(model, "required:\n" + "- param1\n" + "type: object\n" + "properties:\n" + "  param1:\n" + "    title: Cron formatted invoice schedule\n" + "    type: string\n" + "    example: 0 0 5 * *\n");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 50 with AnnotatedType

use of io.swagger.v3.core.converter.AnnotatedType 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)

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