Search in sources :

Example 11 with ModelConverterContextImpl

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

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

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

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

use of io.swagger.v3.core.converter.ModelConverterContextImpl 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)29 Schema (io.swagger.v3.oas.models.media.Schema)27 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)26 Test (org.testng.annotations.Test)24 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)8 ModelConverter (io.swagger.v3.core.converter.ModelConverter)6 XML (io.swagger.v3.oas.models.media.XML)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 StringSchema (io.swagger.v3.oas.models.media.StringSchema)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 BeforeTest (org.testng.annotations.BeforeTest)2 JsonIdentityInfo (com.fasterxml.jackson.annotation.JsonIdentityInfo)1 JsonIdentityReference (com.fasterxml.jackson.annotation.JsonIdentityReference)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1