@@ -69,12 +69,19 @@ private void initJetty(final File documentRoot) {
69
69
}
70
70
}
71
71
72
+ private static JSONObject fileAsJson (File file ) {
73
+ try {
74
+ return new JSONObject (new JSONTokener (new FileInputStream (file )));
75
+ } catch (FileNotFoundException e ) {
76
+ throw new UncheckedIOException (e );
77
+ }
78
+ }
79
+
72
80
private Schema loadSchema () {
73
81
Optional <File > schemaFile = fileByName ("schema.json" );
74
82
try {
75
83
if (schemaFile .isPresent ()) {
76
- JSONObject schemaObj = new JSONObject (
77
- new JSONTokener (new FileInputStream (schemaFile .get ())));
84
+ JSONObject schemaObj = fileAsJson (schemaFile .get ());
78
85
return SchemaLoader .load (schemaObj );
79
86
}
80
87
throw new RuntimeException (issueDir .getCanonicalPath () + "/schema.json is not found" );
@@ -99,18 +106,29 @@ public void test() {
99
106
stopJetty ();
100
107
}
101
108
109
+ private Validator createValidator () {
110
+ Validator .ValidatorBuilder builder = Validator .builder ();
111
+ fileByName ("validator-config.json" ).map (file -> fileAsJson (file ))
112
+ .map (json -> json .getBoolean ("failEarly" ))
113
+ .filter (bool -> Boolean .TRUE .equals (bool ))
114
+ .ifPresent (t -> builder .failEarly ());
115
+ return builder .build ();
116
+ }
117
+
102
118
private void validate (final File file , final Schema schema , final boolean shouldBeValid ) {
103
119
ValidationException thrown = null ;
104
120
105
121
Object subject = loadJsonFile (file );
106
122
107
123
try {
108
- schema .validate (subject );
124
+ Validator validator = createValidator ();
125
+ validator .performValidation (schema , subject );
109
126
} catch (ValidationException e ) {
110
127
thrown = e ;
111
128
}
112
129
113
130
if (shouldBeValid && thrown != null ) {
131
+ thrown .getAllMessages ().forEach (System .out ::println );
114
132
StringBuilder failureBuilder = new StringBuilder ("validation failed with: " + thrown );
115
133
for (ValidationException e : thrown .getCausingExceptions ()) {
116
134
failureBuilder .append ("\n \t " ).append (e .getMessage ());
0 commit comments