Search in sources :

Example 1 with JsonSchemaFactory

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);
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with JsonSchemaFactory

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;
}
Also used : ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) JsonSchemaFactory(com.github.fge.jsonschema.main.JsonSchemaFactory) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException)

Aggregations

ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)2 JsonSchema (com.github.fge.jsonschema.main.JsonSchema)2 JsonSchemaFactory (com.github.fge.jsonschema.main.JsonSchemaFactory)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1