use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testIssue1261InlineSchemaExample.
@Test(description = "it should read an example within an inlined schema")
public void testIssue1261InlineSchemaExample() throws Exception {
Operation operation = Yaml.mapper().readValue(" produces:\n" + " - application/json\n" + " responses:\n" + " 200:\n" + " description: OK\n" + " schema:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " name:\n" + " type: string\n" + " required: [id, name]\n" + " example:\n" + " id: 42\n" + " name: Arthur Dent\n", Operation.class);
Response response = operation.getResponses().get("200");
assertNotNull(response);
Property schema = response.getSchema();
Object example = schema.getExample();
assertNotNull(example);
assertTrue(example instanceof ObjectNode);
ObjectNode objectNode = (ObjectNode) example;
assertEquals(objectNode.get("id").intValue(), 42);
assertEquals(objectNode.get("name").textValue(), "Arthur Dent");
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class PropertyDeserializerTest method deserializeParameterWithMinimumMaximumValues.
@Test
public void deserializeParameterWithMinimumMaximumValues() throws Exception {
String json = "{\n" + " \"in\": \"query\",\n" + " \"type\": \"integer\",\n" + " \"format\": \"int32\",\n" + " \"minimum\": 32,\n" + " \"maximum\": 100\n" + "}";
Property property = Json.mapper().readValue(json, Property.class);
assertTrue(property instanceof IntegerProperty);
IntegerProperty ip = (IntegerProperty) property;
assertEquals(ip.getMinimum(), new BigDecimal("32"));
assertEquals(ip.getMaximum(), new BigDecimal("100"));
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeRefProperty.
@Test(description = "it should deserialize a RefProperty")
public void deserializeRefProperty() throws IOException {
final String json = "{\"$ref\":\"#/definitions/Dog\"}";
final Property p = m.readValue(json, Property.class);
assertEquals(p.getClass(), RefProperty.class);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeStringMapProperty.
@Test(description = "it should deserialize a string MapProperty")
public void deserializeStringMapProperty() throws IOException {
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}";
final Property p = m.readValue(json, Property.class);
assertEquals(p.getType(), "object");
assertEquals(p.getClass(), MapProperty.class);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class PropertySerializationTest method deserializeEnumIntegerProperty.
@Test(description = "it should deserialize an IntegerProperty with enums")
public void deserializeEnumIntegerProperty() throws IOException {
final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
final Property p = m.readValue(json, Property.class);
assertEquals(p.getType(), "integer");
List<Integer> _enum = ((IntegerProperty) p).getEnum();
assertNotNull(_enum);
assertEquals(_enum, Arrays.asList(1, 2));
assertEquals(p.getClass(), IntegerProperty.class);
assertEquals(m.writeValueAsString(p), json);
}
Aggregations