use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class CustomConverterTest method testCustomConverter.
@Test(description = "it should ignore properties with type Bar")
public void testCustomConverter() {
// add the custom converter
final ModelConverters converters = new ModelConverters();
converters.addConverter(new CustomConverter());
final Schema model = converters.read(Foo.class).get("Foo");
assertNotNull(model);
assertEquals(model.getProperties().size(), 1);
final Schema barProperty = (Schema) model.getProperties().get("bar");
assertNull(barProperty);
final Schema titleProperty = (Schema) model.getProperties().get("title");
assertNotNull(titleProperty);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class GericModelConverter method resolve.
@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> next) {
if (type.getType() instanceof Class<?>) {
Class<?> cls = (Class<?>) type.getType();
if (GenericModel.class.isAssignableFrom(cls)) {
Schema impl = new Schema();
impl.title(cls.getSimpleName());
for (Entry<String, Class<?>> entry : GenericModel.getDeclaredProperties().entrySet()) {
impl.addProperties(entry.getKey(), context.resolve(new AnnotatedType(entry.getValue())));
}
context.defineModel(impl.getTitle(), impl);
return impl;
}
}
if (next.hasNext()) {
return next.next().resolve(type, context, next);
} else {
return null;
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ComposedSchemaTest method readComposedSchema_ticket2616.
@Test(description = "read single composed schem refs #2616")
public void readComposedSchema_ticket2616() {
Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObject2616.TestObject2616_Schema.class);
Schema model = schemas.get("TestObject2616_Schema");
Assert.assertNotNull(model);
Map<String, Schema> properties = model.getProperties();
Assert.assertNotNull(properties.get("object"));
Assert.assertTrue(properties.get("object").get$ref().equals("#/components/schemas/AbstractObject"));
model = schemas.get("AbstractObject");
Assert.assertNotNull(model);
Assert.assertTrue(model instanceof ComposedSchema);
Assert.assertTrue(((ComposedSchema) model).getOneOf().size() == 2);
model = schemas.get("AObject");
Assert.assertNotNull(model);
model = schemas.get("BObject");
Assert.assertNotNull(model);
model = schemas.get("objects");
Assert.assertNull(model);
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ComposedSchemaTest method readComposedSchema_ticket2900.
@Test(description = "read composed schem refs #2900")
public void readComposedSchema_ticket2900() {
Json.mapper().addMixIn(TestObjectTicket2900.GsonJsonPrimitive.class, TestObjectTicket2900.GsonJsonPrimitiveMixIn.class);
Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObjectTicket2900.class);
Schema model = schemas.get("SomeDTO");
Assert.assertNotNull(model);
Map<String, Schema> properties = model.getProperties();
Assert.assertNotNull(properties.get("value"));
Assert.assertEquals(properties.get("value").get$ref(), "#/components/schemas/MyJsonPrimitive");
Assert.assertEquals(properties.get("valueWithMixIn").get$ref(), "#/components/schemas/GsonJsonPrimitive");
model = schemas.get("MyJsonPrimitive");
Assert.assertNotNull(model);
Assert.assertTrue(((ComposedSchema) model).getOneOf().size() == 2);
Assert.assertEquals(((ComposedSchema) model).getOneOf().get(0).getType(), "string");
Assert.assertEquals(((ComposedSchema) model).getOneOf().get(1).getType(), "number");
model = schemas.get("GsonJsonPrimitive");
Assert.assertNotNull(model);
Assert.assertTrue(((ComposedSchema) model).getOneOf().size() == 2);
Assert.assertEquals(((ComposedSchema) model).getOneOf().get(0).getType(), "string");
Assert.assertEquals(((ComposedSchema) model).getOneOf().get(1).getType(), "number");
Assert.assertNull(model.getProperties());
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ComposedSchemaTest method readArrayComposedSchema_ticket2616.
@Test(description = "read composed schem refs #2616")
public void readArrayComposedSchema_ticket2616() {
Map<String, Schema> schemas = ModelConverters.getInstance().readAll(TestObject2616.class);
Schema model = schemas.get("testObject");
Assert.assertNotNull(model);
Map<String, Schema> properties = model.getProperties();
Assert.assertNotNull(properties.get("objects"));
Assert.assertTrue(properties.get("objects") instanceof ArraySchema);
model = schemas.get("AbstractObject");
Assert.assertNotNull(model);
Assert.assertTrue(model instanceof ComposedSchema);
Assert.assertTrue(((ComposedSchema) model).getOneOf().size() == 2);
model = schemas.get("AObject");
Assert.assertNotNull(model);
model = schemas.get("BObject");
Assert.assertNotNull(model);
model = schemas.get("objects");
Assert.assertNull(model);
}
Aggregations