use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelSerializerTest method testPrimitiveModel.
@Test
public void testPrimitiveModel() throws Exception {
String json = "{\n" + " \"type\": \"string\",\n" + " \"enum\": [\n" + " \"a\",\n" + " \"b\",\n" + " \"c\"\n" + " ]\n" + "}";
final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
assertNotNull(model.getEnum());
assertTrue(model.getEnum().size() == 3);
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelSerializerTest method convertModel.
@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
final ModelImpl pet = new ModelImpl();
final HashMap<String, Property> props = new HashMap<String, Property>();
props.put("intValue", new IntegerProperty());
props.put("longValue", new LongProperty());
props.put("dateValue", new DateProperty());
props.put("dateTimeValue", new DateTimeProperty());
pet.setProperties(props);
pet.setRequired(Arrays.asList("intValue", "name"));
final String json = "{\n" + " \"required\":[\n" + " \"intValue\"\n" + " ],\n" + " \"properties\":{\n" + " \"dateValue\":{\n" + " \"type\":\"string\",\n" + " \"format\":\"date\"\n" + " },\n" + " \"longValue\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int64\"\n" + " },\n" + " \"dateTimeValue\":{\n" + " \"type\":\"string\",\n" + " \"format\":\"date-time\"\n" + " },\n" + " \"intValue\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\"\n" + " }\n" + " }\n" + "}";
SerializationMatchers.assertEqualsToJson(pet, json);
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelSerializerTest method testIssue2064Neg.
@Test
public void testIssue2064Neg() throws Exception {
String json = "{\n" + " \"type\": \"string\",\n" + " \"uniqueItems\": false\n" + "}";
final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
assertFalse(model.getUniqueItems());
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelSerializerTest method testIssue2064.
@Test
public void testIssue2064() throws Exception {
String json = "{\n" + " \"type\": \"string\",\n" + " \"uniqueItems\": true\n" + "}";
final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
assertTrue(model.getUniqueItems());
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ModelSerializerTest method deserializeModelWithObjectExample.
@Test(description = "it should deserialize a model with object example")
public void deserializeModelWithObjectExample() throws IOException {
final String json = "{\n" + " \"title\":\"Error\",\n" + " \"type\":\"object\",\n" + " \"properties\":{\n" + " \"code\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\"\n" + " },\n" + " \"message\":{\n" + " \"type\":\"string\"\n" + " },\n" + " \"fields\":{\n" + " \"type\":\"string\"\n" + " }\n" + " },\n" + " \"example\":{\n" + " \"code\":1,\n" + " \"message\":\"hello\",\n" + " \"fields\":\"abc\"\n" + " }\n" + "}";
final ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
assertEquals(Json.mapper().writeValueAsString(model.getExample()), "{\"code\":1,\"message\":\"hello\",\"fields\":\"abc\"}");
}
Aggregations