use of io.swagger.v3.core.jackson.ModelResolver 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.jackson.ModelResolver 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.jackson.ModelResolver 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.jackson.ModelResolver 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");
}
use of io.swagger.v3.core.jackson.ModelResolver in project swagger-core by swagger-api.
the class Ticket2992Test method testLocalTime.
@Test
public void testLocalTime() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
Schema model = context.resolve(new AnnotatedType(TestObject2992.class));
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "LocalTime:\n" + " type: object\n" + " properties:\n" + " hour:\n" + " type: integer\n" + " format: int32\n" + " minute:\n" + " type: integer\n" + " format: int32\n" + " second:\n" + " type: integer\n" + " format: int32\n" + " nano:\n" + " type: integer\n" + " format: int32\n" + "TestObject2992:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " a:\n" + " $ref: '#/components/schemas/LocalTime'\n" + " b:\n" + " $ref: '#/components/schemas/LocalTime'\n" + " c:\n" + " $ref: '#/components/schemas/LocalTime'\n" + " d:\n" + " type: string\n" + " format: date-time\n" + " e:\n" + " type: string\n" + " format: date-time\n" + " f:\n" + " type: string\n" + " format: date-time");
PrimitiveType.enablePartialTime();
context = new ModelConverterContextImpl(modelResolver);
context.resolve(new AnnotatedType(TestObject2992.class));
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "TestObject2992:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " a:\n" + " type: string\n" + " format: partial-time\n" + " b:\n" + " type: string\n" + " format: partial-time\n" + " c:\n" + " type: string\n" + " format: partial-time\n" + " d:\n" + " type: string\n" + " format: date-time\n" + " e:\n" + " type: string\n" + " format: date-time\n" + " f:\n" + " type: string\n" + " format: date-time");
}
Aggregations