Search in sources :

Example 11 with ModelResolver

use of io.swagger.v3.core.jackson.ModelResolver in project swagger-core by swagger-api.

the class Ticket3197Test method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    ModelResolver.composedModelPropertiesAsSibling = false;
    modelResolver = new ModelResolver(new ObjectMapper());
    context = new ModelConverterContextImpl(modelResolver);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with ModelResolver

use of io.swagger.v3.core.jackson.ModelResolver in project swagger-core by swagger-api.

the class Ticket3197Test method testTicket3197AsSibling.

@Test
public void testTicket3197AsSibling() throws Exception {
    ModelResolver.composedModelPropertiesAsSibling = true;
    ModelResolver myModelResolver = new ModelResolver(new ObjectMapper());
    ModelResolver.composedModelPropertiesAsSibling = true;
    ModelConverterContextImpl myContext = new ModelConverterContextImpl(myModelResolver);
    final Schema model = myContext.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" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    model:\n" + "      type: string\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n" + "SportCar:\n" + "  required:\n" + "  - id\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: integer\n" + "      format: int64\n" + "    model:\n" + "      type: string\n" + "  allOf:\n" + "  - $ref: '#/components/schemas/Car'\n";
    SerializationMatchers.assertEqualsToYaml(myContext.getDefinedModels(), yaml);
    ModelResolver.composedModelPropertiesAsSibling = false;
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 13 with ModelResolver

use of io.swagger.v3.core.jackson.ModelResolver in project swagger-core by swagger-api.

the class Ticket3697Test method testHiddenJsonCreator.

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

Example 14 with ModelResolver

use of io.swagger.v3.core.jackson.ModelResolver in project swagger-core by swagger-api.

the class Ticket3904Test method testJsonValueSchemaAnnotation.

@Test
public void testJsonValueSchemaAnnotation() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    Schema model = context.resolve(new AnnotatedType(Request.class));
    SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Request:\n" + "  type: object\n" + "  properties:\n" + "    id:\n" + "      type: string\n" + "      description: Description of ID.");
}
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) Test(org.testng.annotations.Test)

Example 15 with ModelResolver

use of io.swagger.v3.core.jackson.ModelResolver in project swagger-core by swagger-api.

the class ContainerTest method testMap.

@Test
public void testMap() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve(new AnnotatedType(MapBean.class));
    final Map<String, Schema> props = model.getProperties();
    assertEquals(1, props.size());
    final Schema prop = props.get("stuff");
    assertNotNull(prop);
    assertEquals(prop.getType(), "object");
    final Schema items = (Schema) prop.getAdditionalProperties();
    assertNotNull(items);
    assertEquals(items.getType(), "string");
    assertEquals(items.getFormat(), "date-time");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) 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

ModelConverterContextImpl (io.swagger.v3.core.converter.ModelConverterContextImpl)33 ModelResolver (io.swagger.v3.core.jackson.ModelResolver)30 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)25 Schema (io.swagger.v3.oas.models.media.Schema)25 Test (org.testng.annotations.Test)24 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)7 ModelConverter (io.swagger.v3.core.converter.ModelConverter)6 BeforeMethod (org.testng.annotations.BeforeMethod)5 XML (io.swagger.v3.oas.models.media.XML)3 BeforeTest (org.testng.annotations.BeforeTest)3 OpenAPISchema2JsonSchema (io.swagger.v3.core.util.OpenAPISchema2JsonSchema)2 StringSchema (io.swagger.v3.oas.models.media.StringSchema)2 Map (java.util.Map)2 MyThing (io.swagger.v3.core.resolving.resources.MyThing)1 TestObject2915 (io.swagger.v3.core.resolving.resources.TestObject2915)1 TestObject2972 (io.swagger.v3.core.resolving.resources.TestObject2972)1 TestObject2992 (io.swagger.v3.core.resolving.resources.TestObject2992)1 TestObject3697 (io.swagger.v3.core.resolving.resources.TestObject3697)1 Ticket2862Model (io.swagger.v3.core.resolving.resources.Ticket2862Model)1