use of com.github.fge.jsonschema.main.JsonSchemaFactory in project useful-java-links by Vedenin.
the class JsonSchemaValidatorHelloWorld method main.
public static void main(final String... args) throws IOException, ProcessingException {
final JsonNode fstabSchema = Utils.loadResource("/fstab.json");
final JsonNode good = Utils.loadResource("/fstab-good.json");
final JsonNode bad = Utils.loadResource("/fstab-bad.json");
final JsonNode bad2 = Utils.loadResource("/fstab-bad2.json");
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(fstabSchema);
ProcessingReport report;
report = schema.validate(good);
System.out.println(report);
report = schema.validate(bad);
System.out.println(report);
report = schema.validate(bad2);
System.out.println(report);
}
use of com.github.fge.jsonschema.main.JsonSchemaFactory 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;
}
Aggregations