use of com.github.fge.jsonschema.core.exceptions.ProcessingException 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.exceptions.ProcessingException in project ocvn by devgateway.
the class OcdsSchemaValidatorService method validate.
/**
* Validates the incoming {@link JsonNode} against OCDS schema
*
* @param jsonNode
* @return
*/
public ProcessingReportWithNode validate(final JsonNode jsonNode) {
try {
ProcessingReport processingReport = schema.validate(jsonNode);
ProcessingReportWithNode processingReportWithNode = null;
try {
processingReportWithNode = new ProcessingReportWithNode(processingReport, processingReport.isSuccess() ? null : jacksonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode.get("ocid")));
} catch (JsonProcessingException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
return processingReportWithNode;
} catch (ProcessingException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
return null;
}
use of com.github.fge.jsonschema.core.exceptions.ProcessingException in project ocvn by devgateway.
the class OcdsSchemaValidatorService method init.
/**
* Intializes the JSON schema validator plus the provided patches
*/
public void init() {
try {
ocdsSchemaNode = JsonLoader.fromResource(schemaLocation == null ? OCDS_SCHEMA_LOCATION : schemaLocation);
if (patchResourceNames != null && patchResourceNames.length > 0) {
for (int i = 0; i < patchResourceNames.length; i++) {
JsonNode node = JsonLoader.fromResource(patchResourceNames[i]);
if (patchResourceNames[i].contains("mergepatch")) {
JsonMergePatch patch = JsonMergePatch.fromJson(node);
ocdsSchemaNode = patch.apply(ocdsSchemaNode);
} else {
JsonPatch patch = JsonPatch.fromJson(node);
ocdsSchemaNode = patch.apply(ocdsSchemaNode);
}
}
}
logger.debug(jacksonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(ocdsSchemaNode));
schema = JsonSchemaFactory.newBuilder().setReportProvider(new ListReportProvider(LogLevel.ERROR, LogLevel.FATAL)).freeze().getJsonSchema(ocdsSchemaNode);
} catch (ProcessingException | IOException e) {
logger.error(e.getMessage());
e.printStackTrace();
} catch (JsonPatchException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
Aggregations