use of io.swagger.converter.ModelConverters in project swagger-core by swagger-api.
the class OverrideTest method test.
@Test
public void test() {
GenericModel.declareProperty(NAME, String.class);
GenericModel.declareProperty(COUNT, int.class);
// create new instead of use singleton
final ModelConverters converters = new ModelConverters();
converters.addConverter(new GericModelConverter());
final Map<String, Model> read = converters.read(GenericModel.class);
assertTrue(read.containsKey(GenericModel.class.getSimpleName()));
final Model model = read.get(GenericModel.class.getSimpleName());
assertTrue(model.getProperties().containsKey(NAME));
assertEquals(model.getProperties().get(NAME).getType(), "string");
assertTrue(model.getProperties().containsKey(COUNT));
assertEquals(model.getProperties().get(COUNT).getType(), "integer");
}
use of io.swagger.converter.ModelConverters in project swagger-core by swagger-api.
the class SnakeCaseConverterTest method testConvert.
@Test(description = "it should change naming style")
public void testConvert() {
// add the custom converter
final SnakeCaseConverter snakeCaseConverter = new SnakeCaseConverter();
final ModelConverters converters = new ModelConverters();
converters.addConverter(snakeCaseConverter);
final Map<String, Model> models = converters.readAll(SnakeCaseModel.class);
final String json = "{" + " \"bar\":{" + " \"type\":\"object\"," + " \"properties\":{" + " \"foo\":{" + " \"type\":\"string\"" + " }" + " }" + " }," + " \"snake_case_model\":{" + " \"type\":\"object\"," + " \"properties\":{" + " \"bar\":{" + " \"$ref\":\"#/definitions/bar\"" + " }," + " \"title\":{" + " \"type\":\"string\"" + " }" + " }," + " \"xml\":{" + " \"name\":\"snakeCaseModel\"" + " }" + " }" + "}";
SerializationMatchers.assertEqualsToJson(models, json);
}
use of io.swagger.converter.ModelConverters 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 Model model = converters.read(Foo.class).get("Foo");
assertNotNull(model);
assertEquals(model.getProperties().size(), 1);
final Property barProperty = model.getProperties().get("bar");
assertNull(barProperty);
final Property titleProperty = model.getProperties().get("title");
assertNotNull(titleProperty);
}
Aggregations