use of io.apicurio.registry.rules.RuleViolationException in project apicurio-registry by Apicurio.
the class JsonSchemaContentValidator method validate.
/**
* @see io.apicurio.registry.rules.validity.ContentValidator#validate(io.apicurio.registry.rules.validity.ValidityLevel, ContentHandle)
*/
@Override
public void validate(ValidityLevel level, ContentHandle artifactContent) throws RuleViolationException {
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 RuleViolationException("Syntax violation for JSON Schema artifact.", RuleType.VALIDITY, level.name(), e);
}
}
}
use of io.apicurio.registry.rules.RuleViolationException in project apicurio-registry by Apicurio.
the class KafkaConnectContentValidator method validate.
/**
* @see io.apicurio.registry.rules.validity.ContentValidator#validate(io.apicurio.registry.rules.validity.ValidityLevel, io.apicurio.registry.content.ContentHandle)
*/
@Override
public void validate(ValidityLevel level, ContentHandle artifactContent) throws RuleViolationException {
if (level == ValidityLevel.SYNTAX_ONLY || level == ValidityLevel.FULL) {
try {
JsonNode jsonNode = mapper.readTree(artifactContent.content());
jsonConverter.asConnectSchema(jsonNode);
} catch (Exception e) {
throw new RuleViolationException("Syntax violation for Kafka Connect Schema artifact.", RuleType.VALIDITY, level.name(), e);
}
}
}
use of io.apicurio.registry.rules.RuleViolationException in project apicurio-registry by Apicurio.
the class XsdContentValidator method validate.
/**
* @see io.apicurio.registry.rules.validity.ContentValidator#validate(io.apicurio.registry.rules.validity.ValidityLevel,
* io.apicurio.registry.content.ContentHandle)
*/
@Override
public void validate(ValidityLevel level, ContentHandle artifactContent) throws RuleViolationException {
super.validate(level, artifactContent);
if (level == ValidityLevel.FULL) {
try (InputStream semanticStream = artifactContent.stream()) {
// validate that its a valid schema
Source source = new StreamSource(semanticStream);
SchemaFactoryAccessor.getSchemaFactory().newSchema(source);
} catch (Exception e) {
throw new RuleViolationException("Syntax violation for XSD Schema artifact.", RuleType.VALIDITY, level.name(), e);
}
}
}
use of io.apicurio.registry.rules.RuleViolationException in project apicurio-registry by Apicurio.
the class XsdContentValidator method validate.
/**
* @see io.apicurio.registry.rules.validity.ContentValidator#validate(ValidityLevel, ContentHandle, Map)
*/
@Override
public void validate(ValidityLevel level, ContentHandle artifactContent, Map<String, ContentHandle> resolvedReferences) throws RuleViolationException {
super.validate(level, artifactContent, resolvedReferences);
if (level == ValidityLevel.FULL) {
try (InputStream semanticStream = artifactContent.stream()) {
// validate that its a valid schema
Source source = new StreamSource(semanticStream);
SchemaFactoryAccessor.getSchemaFactory().newSchema(source);
} catch (Exception e) {
throw new RuleViolationException("Syntax violation for XSD Schema artifact.", RuleType.VALIDITY, level.name(), e);
}
}
}
use of io.apicurio.registry.rules.RuleViolationException in project apicurio-registry by Apicurio.
the class JsonSchemaContentValidatorTest method testInvalidJsonSchemaFull.
@Test
public void testInvalidJsonSchemaFull() throws Exception {
ContentHandle content = resourceToContentHandle("bad-json-schema-v1.json");
JsonSchemaContentValidator validator = new JsonSchemaContentValidator();
RuleViolationException error = Assertions.assertThrows(RuleViolationException.class, () -> {
validator.validate(ValidityLevel.FULL, content, Collections.emptyMap());
});
Assertions.assertFalse(error.getCauses().isEmpty());
Assertions.assertEquals("expected type: Number, found: Boolean", error.getCauses().iterator().next().getDescription());
Assertions.assertEquals("#/items/properties/price/exclusiveMinimum", error.getCauses().iterator().next().getContext());
}
Aggregations