Search in sources :

Example 21 with ModelConverterContextImpl

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

the class ATMTest method testATMModel.

@Test
public void testATMModel() throws Exception {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve(new AnnotatedType(ATM.class));
    assertNotNull(model);
}
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 22 with ModelConverterContextImpl

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

the class EnumTest method testEnum.

@Test
public void testEnum() {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve((new AnnotatedType().type(Currency.class)));
    assertNotNull(model);
    assertTrue(model instanceof StringSchema);
    final StringSchema strModel = (StringSchema) model;
    assertNotNull(strModel.getEnum());
    final Collection<String> modelValues = new ArrayList<String>(Collections2.transform(Arrays.asList(Currency.values()), Functions.toStringFunction()));
    assertEquals(strModel.getEnum(), modelValues);
    final Schema property = context.resolve(new AnnotatedType().type(Currency.class).schemaProperty(true));
    assertNotNull(property);
    assertTrue(property instanceof StringSchema);
    final StringSchema strProperty = (StringSchema) property;
    assertNotNull(strProperty.getEnum());
    final Collection<String> values = new ArrayList<>(Collections2.transform(Arrays.asList(Currency.values()), Functions.toStringFunction()));
    assertEquals(strProperty.getEnum(), values);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) ArrayList(java.util.ArrayList) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Example 23 with ModelConverterContextImpl

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

the class EnumTest method testEnumGenerics.

@Test
public void testEnumGenerics() {
    final ModelResolver modelResolver = new ModelResolver(mapper());
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve((new AnnotatedType().type(Contract.class)));
    assertNotNull(model);
    assertEquals(model.getName(), "Contract");
    assertTrue(model.getProperties().containsKey("type"));
    assertNotNull(model.getProperties().get("type"));
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) 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 24 with ModelConverterContextImpl

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

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

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