Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
use jsonobject instead of string as schema input
Browse files Browse the repository at this point in the history
  • Loading branch information
nvnieuwk committed Jan 24, 2024
1 parent a3d3f93 commit e00f576
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import java.util.regex.Matcher
public class JsonSchemaValidator {

private static ValidatorFactory validator
private static String schema
private static JSONObject schema
private static Pattern uriPattern = Pattern.compile('^#/(\\d*)?/?(.*)$')

JsonSchemaValidator(String schemaString) {
this.schema = schemaString
this.schema = new JSONObject(schemaString)
this.validator = new ValidatorFactory()
.withJsonNodeFactory(new OrgJsonNode.Factory())
// .withDialect() // TODO define the dialect
Expand All @@ -35,7 +35,6 @@ public class JsonSchemaValidator {
private static List<String> validateObject(JsonNode input, String validationType, Object rawJson) {
def Validator.Result result = this.validator.validate(this.schema, input)
def List<String> errors = []
def JSONObject schemaObject = new JSONObject(this.schema)
for (error : result.getErrors()) {
def String errorString = error.getError()
// Skip double error in the parameter schema
Expand All @@ -52,7 +51,7 @@ public class JsonSchemaValidator {
def JSONPointer schemaPointer = new JSONPointer("${schemaLocation}/errorMessage")
def String customError = ""
try{
customError = schemaPointer.queryFrom(schemaObject) ?: ""
customError = schemaPointer.queryFrom(this.schema) ?: ""
} catch (JSONPointerException e) {
customError = ""
}
Expand Down

0 comments on commit e00f576

Please sign in to comment.