use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeBodyParameterToYaml.
@Test(description = "it should serialize a BodyParameter to yaml")
public void serializeBodyParameterToYaml() {
final ModelImpl model = new ModelImpl().name("Cat").property("name", new StringProperty());
final BodyParameter p = new BodyParameter().schema(model);
final String yaml = "---\n" + "in: \"body\"\n" + "required: false\n" + "schema:\n" + " properties:\n" + " name:\n" + " type: \"string\"";
SerializationMatchers.assertEqualsToYaml(p, yaml);
}
use of io.swagger.models.ModelImpl in project swagger-core by swagger-api.
the class ObjectPropertyTest method readModelWithObjectProperty.
@Test(description = "convert a model with object properties")
public void readModelWithObjectProperty() throws IOException {
String json = "{" + " \"properties\":{" + " \"id\":{" + " \"type\":\"string\"" + " }," + " \"someObject\":{" + " \"type\":\"object\"," + " \"x-foo\": \"vendor x\"," + " \"properties\":{" + " \"innerId\":{" + " \"type\":\"string\"" + " }" + " }" + " }" + " }" + "}";
ModelImpl model = Json.mapper().readValue(json, ModelImpl.class);
Property p = model.getProperties().get("someObject");
assertTrue(p instanceof ObjectProperty);
ObjectProperty op = (ObjectProperty) p;
Property sp = op.getProperties().get("innerId");
assertTrue(sp instanceof StringProperty);
assertTrue(op.getVendorExtensions() != null);
assertNotNull(op.getVendorExtensions().get("x-foo"));
assertEquals(op.getVendorExtensions().get("x-foo"), "vendor x");
}
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());
}
Aggregations