Search in sources :

Example 1 with JsonSchemaReaderFactory

use of org.leadpony.justify.api.JsonSchemaReaderFactory in project selenium_java by sergueik.

the class Validate method validateSchemaAt.

/**
 * Reads and validates a JSON schema.
 *
 * @param location the location of the JSON schema to be read and validated.
 * @return the schema read if successful, or {@code null} if errors occcured.
 */
private JsonSchema validateSchemaAt(Location location) {
    JsonSchemaReaderFactory factory = createSchemaReaderFactory();
    try (JsonSchemaReader reader = factory.createSchemaReader(openSchema(location))) {
        JsonSchema schema = reader.read();
        console.withColor(Color.SUCCESS).print(SCHEMA_VALID, location);
        return schema;
    } catch (JsonValidatingException e) {
        List<Problem> problems = e.getProblems();
        problemPrinter.handleProblems(problems);
        console.withColor(Color.DANGER).print(SCHEMA_INVALID, location, Problems.countLeast(problems));
        setStatus(Status.INVALID);
        return null;
    } catch (JsonParsingException e) {
        console.withColor(Color.DANGER).print(SCHEMA_MALFORMED, e);
        setStatus(Status.INVALID);
        return null;
    } catch (JsonException e) {
        throw new CommandException(e);
    }
}
Also used : JsonValidatingException(org.leadpony.justify.api.JsonValidatingException) JsonException(javax.json.JsonException) JsonSchemaReader(org.leadpony.justify.api.JsonSchemaReader) JsonSchema(org.leadpony.justify.api.JsonSchema) ArrayList(java.util.ArrayList) List(java.util.List) JsonSchemaReaderFactory(org.leadpony.justify.api.JsonSchemaReaderFactory) JsonParsingException(javax.json.stream.JsonParsingException)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 JsonException (javax.json.JsonException)1 JsonParsingException (javax.json.stream.JsonParsingException)1 JsonSchema (org.leadpony.justify.api.JsonSchema)1 JsonSchemaReader (org.leadpony.justify.api.JsonSchemaReader)1 JsonSchemaReaderFactory (org.leadpony.justify.api.JsonSchemaReaderFactory)1 JsonValidatingException (org.leadpony.justify.api.JsonValidatingException)1