Search in sources :

Example 21 with AnnotatedType

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

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

Example 23 with AnnotatedType

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

the class XMLInfoTest method testReadingXmlAccessorTypeNone.

@Test
public void testReadingXmlAccessorTypeNone() throws Exception {
    final ModelConverter mr = modelResolver();
    final Schema model = mr.resolve(new AnnotatedType(XmlDecoratedBeanXmlAccessorNone.class), new ModelConverterContextImpl(mr), null);
    final XML xml = model.getXml();
    assertNotNull(xml);
    assertEquals(xml.getName(), "xmlDecoratedBean");
    final Schema property = (Schema) model.getProperties().get("a");
    assertNotNull(property);
    assertNull(model.getProperties().get("b"));
    assertNotNull(model.getProperties().get("c"));
    assertNotNull(model.getProperties().get("d"));
    assertNotNull(model.getProperties().get("e"));
    assertNotNull(model.getProperties().get("f"));
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) XML(io.swagger.v3.oas.models.media.XML) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) ModelConverter(io.swagger.v3.core.converter.ModelConverter) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) Test(org.testng.annotations.Test)

Example 24 with AnnotatedType

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

the class ComplexPropertyTest method testOuterBean.

@Test
public void testOuterBean() throws Exception {
    final ModelResolver modelResolver = modelResolver();
    final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
    final Schema model = context.resolve(new AnnotatedType(OuterBean.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 25 with AnnotatedType

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

the class ModelResolver method resolveDiscriminator.

protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) {
    io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass());
    String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty();
    if (disc.isEmpty()) {
        // longer method would involve AnnotationIntrospector.findTypeResolver(...) but:
        JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class);
        if (typeInfo != null) {
            disc = typeInfo.property();
        }
    }
    if (!disc.isEmpty()) {
        Discriminator discriminator = new Discriminator().propertyName(disc);
        if (declaredSchemaAnnotation != null) {
            DiscriminatorMapping[] mappings = declaredSchemaAnnotation.discriminatorMapping();
            if (mappings != null && mappings.length > 0) {
                for (DiscriminatorMapping mapping : mappings) {
                    if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) {
                        discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName()));
                    }
                }
            }
        }
        return discriminator;
    }
    return null;
}
Also used : DiscriminatorMapping(io.swagger.v3.oas.annotations.media.DiscriminatorMapping) AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) Discriminator(io.swagger.v3.oas.models.media.Discriminator)

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