Search in sources :

Example 1 with ModelConverters

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");
}
Also used : Model(io.swagger.models.Model) ModelConverters(io.swagger.converter.ModelConverters) Test(org.testng.annotations.Test)

Example 2 with ModelConverters

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);
}
Also used : Model(io.swagger.models.Model) ModelConverters(io.swagger.converter.ModelConverters) Test(org.testng.annotations.Test)

Example 3 with ModelConverters

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);
}
Also used : Model(io.swagger.models.Model) ModelConverters(io.swagger.converter.ModelConverters) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

ModelConverters (io.swagger.converter.ModelConverters)3 Model (io.swagger.models.Model)3 Test (org.testng.annotations.Test)3 Property (io.swagger.models.properties.Property)1