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.");
}
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");
}
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"));
}
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);
}
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;
}
Aggregations