@Test public void testInvalidJsonSchema() throws Exception { ContentHandle content = resourceToContentHandle("jsonschema-invalid.json"); JsonSchemaContentValidator validator = new JsonSchemaContentValidator(); Assertions.assertThrows(InvalidContentException.class, () -> { validator.validate(ValidityLevel.SYNTAX_ONLY, content); }); }
@Override public void validate(ValidityLevel level, ContentHandle artifactContent) throws InvalidContentException { if (level == ValidityLevel.SYNTAX_ONLY || level == ValidityLevel.FULL) { try { JsonNode node = objectMapper.readTree(artifactContent.bytes()); if (level == ValidityLevel.FULL) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); factory.getSchema(node); } } catch (Exception e) { throw new InvalidContentException("Syntax violation for JSON Schema artifact.", e); } } }
JsonSchemaContentValidator implements ContentValidator { @Override public void validate(ValidityLevel level, ContentHandle artifactContent) throws InvalidContentException { if (level == ValidityLevel.SYNTAX_ONLY || level == ValidityLevel.FULL) { try { JsonNode node = objectMapper.readTree(artifactContent.bytes()); if (level == ValidityLevel.FULL) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); factory.getSchema(node); } } catch (Exception e) { throw new InvalidContentException("Syntax violation for JSON Schema artifact.", e); } } } }
JsonSchemaContentValidator implements ContentValidator { @Override public void validate(ValidityLevel level, ContentHandle artifactContent) throws InvalidContentException { if (level == ValidityLevel.SYNTAX_ONLY || level == ValidityLevel.FULL) { try { JsonNode node = objectMapper.readTree(artifactContent.bytes()); if (level == ValidityLevel.FULL) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); factory.getSchema(node); } } catch (Exception e) { throw new InvalidContentException("Syntax violation for JSON Schema artifact.", e); } } } JsonSchemaContentValidator(); }
JsonSchemaContentValidator implements ContentValidator { @Override public void validate(ValidityLevel level, ContentHandle artifactContent) throws InvalidContentException { if (level == ValidityLevel.SYNTAX_ONLY || level == ValidityLevel.FULL) { try { JsonNode node = objectMapper.readTree(artifactContent.bytes()); if (level == ValidityLevel.FULL) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); factory.getSchema(node); } } catch (Exception e) { throw new InvalidContentException("Syntax violation for JSON Schema artifact.", e); } } } JsonSchemaContentValidator(); @Override void validate(ValidityLevel level, ContentHandle artifactContent); }
JsonSchemaContentValidator implements ContentValidator { @Override public void validate(ValidityLevel level, ContentHandle artifactContent) throws InvalidContentException { if (level == ValidityLevel.SYNTAX_ONLY || level == ValidityLevel.FULL) { try { JsonNode node = objectMapper.readTree(artifactContent.bytes()); if (level == ValidityLevel.FULL) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); factory.getSchema(node); } } catch (Exception e) { throw new InvalidContentException("Syntax violation for JSON Schema artifact.", e); } } } JsonSchemaContentValidator(); @Override void validate(ValidityLevel level, ContentHandle artifactContent);  }