Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make schema validation errors critical #178

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class JsonSchemaContentValidator
private final Schema schema;

/**
* Construct a new JSON schema validator using the provided reader to load the
* JSON schema.
* Construct a new JSON schema validator using the provided reader to load the JSON schema.
*
* @param reader
* the JSON schema reader
Expand All @@ -45,8 +44,7 @@ public JsonSchemaContentValidator(@NonNull Reader reader) {
}

/**
* Construct a new JSON schema validator using the provided input stream to load
* the JSON schema.
* Construct a new JSON schema validator using the provided input stream to load the JSON schema.
*
* @param is
* the JSON schema input source
Expand All @@ -56,8 +54,7 @@ public JsonSchemaContentValidator(@NonNull InputStream is) {
}

/**
* Construct a new JSON schema validator using the provided JSON object for the
* JSON schema.
* Construct a new JSON schema validator using the provided JSON object for the JSON schema.
*
* @param jsonSchema
* the JSON schema
Expand All @@ -67,8 +64,7 @@ public JsonSchemaContentValidator(@NonNull JSONObject jsonSchema) {
}

/**
* Construct a new JSON schema validator using the provided JSON tokenizer to
* load the schema.
* Construct a new JSON schema validator using the provided JSON tokenizer to load the schema.
*
* @param tokenizer
* the JSON schema token stream
Expand Down Expand Up @@ -125,8 +121,8 @@ public IValidationResult validate(@NonNull JSONObject json, @NonNull URI resourc
* Build validation findings from a validation exception.
*
* @param exception
* the JSON schema validation exception generated during schema
* validation representing the issue
* the JSON schema validation exception generated during schema validation representing the
* issue
* @param resourceUri
* the resource the issue was found in
* @return the stream of findings
Expand All @@ -138,15 +134,12 @@ protected Stream<JsonValidationFinding> handleValidationException(
@NonNull URI resourceUri) {
JsonValidationFinding finding = new JsonValidationFinding(exception, resourceUri);
Stream<JsonValidationFinding> childFindings = exception.getCausingExceptions().stream()
.flatMap(ex -> {
return handleValidationException(ex, resourceUri);
});
.flatMap(ex -> handleValidationException(ex, resourceUri));
return Stream.concat(Stream.of(finding), childFindings);
}

/**
* Records an identified individual validation result found during JSON schema
* validation.
* Records an identified individual validation result found during JSON schema validation.
*/
public static class JsonValidationFinding implements IValidationFinding {
@NonNull
Expand All @@ -155,12 +148,12 @@ public static class JsonValidationFinding implements IValidationFinding {
private final URI documentUri;

/**
* Construct a new XML schema validation finding, which represents an issue
* identified during XML schema validation.
* Construct a new XML schema validation finding, which represents an issue identified during XML
* schema validation.
*
* @param exception
* the JSON schema validation exception generated during schema
* validation representing the issue
* the JSON schema validation exception generated during schema validation representing the
* issue
* @param resourceUri
* the resource the issue was found in
*/
Expand All @@ -184,7 +177,7 @@ public Kind getKind() {

@Override
public IConstraint.Level getSeverity() {
return IConstraint.Level.ERROR;
return IConstraint.Level.CRITICAL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public XmlSchemaContentValidator(@NonNull List<? extends Source> schemaSources)
}

/**
* Construct a new XML schema validator using the provided pre-parsed XML
* schema(s).
* Construct a new XML schema validator using the provided pre-parsed XML schema(s).
*
* @param schema
* the pre-parsed XML schema(s) to use for validation
Expand Down Expand Up @@ -109,8 +108,7 @@ public IValidationResult validate(InputStream is, URI documentUri) throws IOExce
}

/**
* Records an identified individual validation result found during XML schema
* validation.
* Records an identified individual validation result found during XML schema validation.
*/
public static class XmlValidationFinding implements IValidationFinding, IResourceLocation {
@NonNull
Expand All @@ -121,14 +119,14 @@ public static class XmlValidationFinding implements IValidationFinding, IResourc
private final Level severity;

/**
* Construct a new XML schema validation finding, which represents an issue
* identified during XML schema validation.
* Construct a new XML schema validation finding, which represents an issue identified during XML
* schema validation.
*
* @param severity
* the finding significance
* @param exception
* the XML schema validation exception generated during schema
* validation representing the issue
* the XML schema validation exception generated during schema validation representing the
* issue
* @param resourceUri
* the resource the issue was found in
*/
Expand Down Expand Up @@ -249,7 +247,7 @@ public void warning(SAXParseException ex) throws SAXException {
@Override
public void error(SAXParseException ex) throws SAXException {
findings.add(new XmlValidationFinding(Level.ERROR, ex, getDocumentUri()));
adjustHighestSeverity(Level.ERROR);
adjustHighestSeverity(Level.CRITICAL);
}

@SuppressWarnings("null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ public ExitStatus execute() {
validationResult = this.validateWithSchema(source, asFormat);
}

if (!cmdLine.hasOption(NO_CONSTRAINT_VALIDATION_OPTION)
&& (validationResult == null || validationResult.isPassing())) {
if (!cmdLine.hasOption(NO_CONSTRAINT_VALIDATION_OPTION)) {
// perform constraint validation
IValidationResult constraintValidationResult = bindingContext.validateWithConstraints(source, configuration);
validationResult = validationResult == null
Expand Down