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