use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class JsonDeserializationTest method shouldDeserializeArrayPropertyMinItems.
@Test
public void shouldDeserializeArrayPropertyMinItems() throws Exception {
String path = "json-schema-validation/array.json";
ArrayProperty property = (ArrayProperty) TestUtils.deserializeJsonFileFromClasspath(path, Property.class);
assertNotNull(property.getMinItems());
assertEquals(property.getMinItems().intValue(), 1);
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class GenericsTest method checkParametersOfGenericTypes.
@Test(description = "check parameters of generic types")
public void checkParametersOfGenericTypes() {
Set<String> genericTypes = new HashSet(Arrays.asList("GenericTypeString", "GenericTypeUUID", "GenericTypeGenericTypeString", "RenamedGenericTypeString", "RenamedGenericTypeRenamedGenericTypeString"));
assertTrue(swagger.getDefinitions().keySet().containsAll(genericTypes));
Operation opString = getOperation("testGenericType");
testGenericType(opString, "GenericTypeString");
Property strValue = getProperty("GenericTypeString", "value");
assertNotEquals(strValue, null);
assertEquals(strValue.getClass().getName(), StringProperty.class.getName());
Operation opUUID = getOperation("testStringBasedGenericType");
testGenericType(opUUID, "GenericTypeUUID");
Property uuidValue = getProperty("GenericTypeUUID", "value");
assertNotEquals(uuidValue, null);
assertEquals(uuidValue.getClass().getName(), UUIDProperty.class.getName());
Operation opComplex = getOperation("testComplexGenericType");
testGenericType(opComplex, "GenericTypeGenericTypeString");
Property complexValue = getProperty("GenericTypeGenericTypeString", "value");
assertNotEquals(complexValue, null);
assertEquals(complexValue.getClass().getName(), RefProperty.class.getName());
assertEquals(((RefProperty) complexValue).getSimpleRef(), "GenericTypeString");
Operation opRenamed = getOperation("testRenamedGenericType");
testGenericType(opRenamed, "RenamedGenericTypeRenamedGenericTypeString");
Property renamedComplexValue = getProperty("RenamedGenericTypeRenamedGenericTypeString", "value");
assertNotEquals(renamedComplexValue, null);
assertTrue(renamedComplexValue instanceof RefProperty);
assertEquals(((RefProperty) renamedComplexValue).getSimpleRef(), "RenamedGenericTypeString");
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class GenericsTest method checkGenericResult.
@Test(description = "check generic result")
public void checkGenericResult() {
Operation op = swagger.getPath("/generics/testGenericResult").getGet();
Property schema = op.getResponses().get("200").getSchema();
assertEquals(schema.getClass().getName(), RefProperty.class.getName());
assertEquals(((RefProperty) schema).getSimpleRef(), "GenericListWrapperTag");
Property entries = getProperty("GenericListWrapperTag", "entries");
assertNotEquals(entries, null);
assertEquals(entries.getClass().getName(), ArrayProperty.class.getName());
Property items = ((ArrayProperty) entries).getItems();
assertEquals(items.getClass().getName(), RefProperty.class.getName());
assertEquals(((RefProperty) items).getSimpleRef(), "Tag");
}
use of io.swagger.models.properties.Property in project swagger-core by swagger-api.
the class MapPropertyDeserializerTest method testMapDeserialization.
@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
Operation operation = Json.mapper().readValue(json, Operation.class);
Response response = operation.getResponses().get("200");
assertNotNull(response);
Property responseSchema = response.getSchema();
assertNotNull(responseSchema);
assertTrue(responseSchema instanceof MapProperty);
MapProperty mp = (MapProperty) responseSchema;
assertTrue(mp.getAdditionalProperties() instanceof IntegerProperty);
}
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");
}
Aggregations