@Test public void testDeserializePetStoreFile() throws Exception { TestUtils.deserializeJsonFileFromClasspath("specFiles/petstore.json", OpenAPI.class); }
@Test public void testDeserializeCompositionTest() throws Exception { TestUtils.deserializeJsonFileFromClasspath("specFiles/compositionTest.json", OpenAPI.class); }
@Test public void shouldDeserializeArrayPropertyMinItems() throws Exception { String path = "json-schema-validation/array.json"; ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class); assertNotNull(property.getMinItems()); assertEquals(property.getMinItems().intValue(), 1); }
@Test public void shouldDeserializeArrayPropertyMaxItems() throws Exception { String path = "json-schema-validation/array.json"; ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class); assertNotNull(property.getMaxItems()); assertEquals(property.getMaxItems().intValue(), 10); }
@Test public void givenMapProperty_shouldDeserializeMinProperties() { String path = "json-schema-validation/map.json"; MapSchema property = (MapSchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class); assertNotNull(property.getMinProperties()); assertEquals(property.getMinProperties().intValue(), 1); }
@Test public void givenMapProperty_shouldDeserializeMaxProperties() { String path = "json-schema-validation/map.json"; MapSchema property = (MapSchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class); assertNotNull(property.getMaxProperties()); assertEquals(property.getMaxProperties().intValue(), 10); } }
@Test public void shouldDeserializeArrayPropertyUniqueItems() throws Exception { String path = "json-schema-validation/array.json"; ArraySchema property = (ArraySchema) TestUtils.deserializeJsonFileFromClasspath(path, Schema.class); assertNotNull(property.getUniqueItems()); assertTrue(property.getUniqueItems()); }
@Test(description = "it should serialize correctly security") public void serializeSecurity() throws IOException { final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/securityDefinitions.json", OpenAPI.class); final String json = ResourceUtils.loadClassResource(getClass(), "specFiles/securityDefinitions.json"); SerializationMatchers.assertEqualsToJson(oas, json); }
@Test(description = "should deserialize a string property with constraints") public void testDeserializeConstrainedStringProperty() throws Exception { OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", OpenAPI.class); StringSchema property = (StringSchema) oas.getComponents().getSchemas().get("Health").getProperties().get("string_with_constraints"); assertEquals(property.getMinLength(), Integer.valueOf(10)); assertEquals(property.getMaxLength(), Integer.valueOf(100)); assertEquals(property.getPattern(), "apattern"); }
@Test public void testDeserializeAPathRef() throws Exception { final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/pathRef.json", OpenAPI.class); final PathItem petPath = oas.getPaths().get("/pet"); assertNotNull(petPath.get$ref()); assertEquals(petPath.get$ref(), "http://my.company.com/paths/health.json"); assertTrue(oas.getPaths().get("/user") instanceof PathItem); }
@Test(description = "should deserialize a property with vendor extensions of different types") public void testDeserializePropertyWithVendorExtensions() throws Exception { OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertyWithVendorExtensions.json", OpenAPI.class); Map<String, Object> oasVendorExtensions = oas.getExtensions(); Map<String, Object> vendorExtensions = ((Schema) oas.getComponents().getSchemas().get("Health").getProperties().get("status")).getExtensions(); assertVendorExtensions(oasVendorExtensions); assertVendorExtensions(vendorExtensions); //check for vendor extensions in array property types vendorExtensions = ((Schema) oas.getComponents().getSchemas().get("Health").getProperties().get("array")).getExtensions(); String xStringValue = (String) vendorExtensions.get("x-string-value"); assertNotNull(xStringValue); assertEquals(xStringValue, "string_value"); }
@Test(description = "should deserialize an array property with constraints") public void testDeserializeConstrainedArrayProperties() throws Exception { OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/propertiesWithConstraints.json", OpenAPI.class); Map<String, Schema> properties = oas.getComponents().getSchemas().get("Health").getProperties(); ArraySchema withMin = (ArraySchema) properties.get("array_with_min"); assertEquals(withMin.getMinItems(), Integer.valueOf(5)); assertNull(withMin.getMaxItems()); assertNull(withMin.getUniqueItems()); ArraySchema withMax = (ArraySchema) properties.get("array_with_max"); assertNull(withMax.getMinItems()); assertEquals(withMax.getMaxItems(), Integer.valueOf(10)); assertNull(withMax.getUniqueItems()); ArraySchema withUnique = (ArraySchema) properties.get("array_with_unique"); assertNull(withUnique.getMinItems()); assertNull(withUnique.getMaxItems()); assertEquals(withUnique.getUniqueItems(), Boolean.TRUE); ArraySchema withAll = (ArraySchema) properties.get("array_with_all"); assertEquals(withAll.getMinItems(), Integer.valueOf(1)); assertEquals(withAll.getMaxItems(), Integer.valueOf(10)); assertEquals(withAll.getUniqueItems(), Boolean.TRUE); }
@Test public void testDeserializeSecurity() throws Exception { final OpenAPI swagger = TestUtils.deserializeJsonFileFromClasspath("specFiles/securityDefinitions.json", OpenAPI.class);
@Test public void testDeserializeAResponseRef() throws Exception { final OpenAPI oas = TestUtils.deserializeJsonFileFromClasspath("specFiles/responseRef.json", OpenAPI.class); final ApiResponses responseMap = oas.getPaths().get("/pet").getPut().getResponses(); // TODO: missing response ref assertIsRefResponse(responseMap.get("405"), "http://my.company.com/responses/errors.json#/method-not-allowed"); assertIsRefResponse(responseMap.get("404"), "http://my.company.com/responses/errors.json#/not-found"); assertTrue(responseMap.get("400") instanceof ApiResponse); }