use of com.github.fge.jsonschema.core.report.ProcessingReport in project KaiZen-OpenAPI-Editor by RepreZen.
the class Validator method validateAgainstSchema.
public Set<SwaggerError> validateAgainstSchema(ErrorProcessor processor, JsonNode schemaAsJson, JsonNode documentAsJson) {
final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder().setLoadingConfiguration(loadingConfiguration).freeze();
final Set<SwaggerError> errors = Sets.newHashSet();
JsonSchema schema = null;
try {
schema = factory.getJsonSchema(schemaAsJson);
} catch (ProcessingException e) {
YEditLog.logException(e);
return errors;
}
try {
ProcessingReport report = schema.validate(documentAsJson, true);
errors.addAll(processor.processReport(report));
} catch (ProcessingException e) {
errors.addAll(processor.processMessage(e.getProcessingMessage()));
}
return errors;
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project swagger-parser by swagger-api.
the class Issue1Test method parameterWithTypeFileMustHaveCorrectConsumesAndParamType.
@Test
public void parameterWithTypeFileMustHaveCorrectConsumesAndParamType() throws ProcessingException {
final ProcessingReport report = schema.validate(instance);
assertFalse(report.isSuccess());
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project thingsboard by thingsboard.
the class BaseComponentDescriptorService method validate.
@Override
public boolean validate(ComponentDescriptor component, JsonNode configuration) {
JsonValidator validator = JsonSchemaFactory.byDefault().getValidator();
try {
if (!component.getConfigurationDescriptor().has("schema")) {
throw new DataValidationException("Configuration descriptor doesn't contain schema property!");
}
JsonNode configurationSchema = component.getConfigurationDescriptor().get("schema");
ProcessingReport report = validator.validate(configurationSchema, configuration);
return report.isSuccess();
} catch (ProcessingException e) {
throw new IncorrectParameterException(e.getMessage(), e);
}
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project arctic-sea by 52North.
the class JSONValidator method validateAndThrow.
public void validateAndThrow(JsonNode instance, String schema) throws DecodingException {
ProcessingReport report = JSONValidator.getInstance().validate(instance, schema);
if (!report.isSuccess()) {
String message = encode(report, instance);
LOG.info("Invalid JSON instance:\n{}", message);
throw new JSONDecodingException(message);
}
}
use of com.github.fge.jsonschema.core.report.ProcessingReport in project arctic-sea by 52North.
the class FieldDecoderTest method validateWithValueAndDecode.
protected SweField validateWithValueAndDecode(ObjectNode json, boolean withValue) throws DecodingException {
ProcessingReport report = validator.validate(json, withValue ? SchemaConstants.Common.FIELD_WITH_VALUE : SchemaConstants.Common.FIELD);
if (!report.isSuccess()) {
System.err.println(validator.encode(report, json));
fail("Invalid generated field!");
}
return decoder.decode(json);
}
Aggregations