Skip to content

Commit

Permalink
Output syntax errors when throwing an InvalidSchemaException
Browse files Browse the repository at this point in the history
For this, depend on -core 1.2.3 (which fixes a missing key) and walk the
previous report to search for syntax errors; append these to the
ProcessingMessage we use to initialize the exception.

Fixes issue java-json-tools#99.

Signed-off-by: Francis Galiegue <[email protected]>
  • Loading branch information
fge committed May 25, 2014
1 parent 376c112 commit f054843
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ project.ext {
*/
dependencies {
compile(group: "com.github.fge", name: "json-schema-core",
version: "1.2.1");
version: "1.2.3");
compile(group: "javax.mail", name: "mailapi", version: "1.4.3");
compile(group: "joda-time", name: "joda-time", version: "2.3");
compile(group: "com.googlecode.libphonenumber", name: "libphonenumber",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package com.github.fge.jsonschema.processors.validation;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.github.fge.jackson.JacksonUtils;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.github.fge.jsonschema.cfg.ValidationConfiguration;
import com.github.fge.jsonschema.core.exceptions.InvalidSchemaException;
Expand Down Expand Up @@ -83,9 +85,27 @@ public FullData process(final ProcessingReport report,
*/
final ValidatorList fullContext = processor.process(report, context);

if (fullContext == null)
throw new InvalidSchemaException(new ProcessingMessage()
.setMessage(syntaxMessages.getMessage("core.invalidSchema")));
if (fullContext == null) {
/*
* OK, that's for issue #99 but that's ugly nevertheless.
*
* We want syntax error messages to appear in the exception text.
*/
final String msg = syntaxMessages.getMessage("core.invalidSchema");
final ArrayNode arrayNode = JacksonUtils.nodeFactory().arrayNode();
JsonNode node;
for (final ProcessingMessage message: report) {
node = message.asJson();
if ("syntax".equals(node.path("domain").asText()))
arrayNode.add(node);
}
final StringBuilder sb = new StringBuilder(msg);
sb.append("\nSyntax errors:\n");
sb.append(JacksonUtils.prettyPrint(arrayNode));
final ProcessingMessage message = new ProcessingMessage()
.setMessage(sb.toString());
throw new InvalidSchemaException(message);
}

/*
* Get the calculated context. Build the data.
Expand Down

0 comments on commit f054843

Please sign in to comment.