3131import java .io .IOException ;
3232import java .nio .file .Files ;
3333import java .nio .file .Path ;
34- import java .util .Collection ;
34+ import java .util .List ;
3535import java .util .Map .Entry ;
3636import java .util .Set ;
3737
@@ -55,9 +55,12 @@ public final void testSchema() throws IOException {
5555 JsonSchema jsonSchema = factory .getSchema (mapper .readTree (Files .newInputStream (p )), config );
5656
5757 // ensure the schema meets certain criteria like not empty, strictness
58- assertTrue ("found empty schema" , jsonSchema .getValidators ().size () > 0 );
59- assertTrue ("schema lacks at least 1 required field" , jsonSchema .hasRequiredValidator ());
60- assertSchemaStrictness (jsonSchema .getValidators ().values (), jsonSchema .getSchemaPath ());
58+ assertFalse ("found empty schema" , jsonSchema .getValidators ().isEmpty ());
59+ assertTrue (
60+ "schema lacks at least 1 required field" ,
61+ jsonSchema .getValidators ().stream ().anyMatch (v -> v .getKeyword ().equals ("required" ))
62+ );
63+ assertSchemaStrictness (jsonSchema .getValidators (), jsonSchema .getSchemaLocation ().toString ());
6164
6265 for (int runs = 0 ; runs < NUMBER_OF_TEST_RUNS ; runs ++) {
6366 BytesReference xContent = XContentHelper .toXContent (createTestInstance (), XContentType .JSON , getToXContentParams (), false );
@@ -107,14 +110,7 @@ protected SpecVersion.VersionFlag getSchemaVersion() {
107110 * Uses the ootb factory but replaces the loader for sub schema's stored on the file system.
108111 */
109112 private JsonSchemaFactory initializeSchemaFactory () {
110- JsonSchemaFactory factory = JsonSchemaFactory .builder (JsonSchemaFactory .getInstance (getSchemaVersion ())).uriFetcher (uri -> {
111- String fileName = uri .toString ().substring (uri .getScheme ().length () + 1 );
112- Path path = getDataPath (getSchemaLocation () + fileName );
113- logger .debug ("loading sub-schema [{}] from: [{}]" , uri , path );
114- return Files .newInputStream (path );
115- }, "file" ).build ();
116-
117- return factory ;
113+ return JsonSchemaFactory .builder (JsonSchemaFactory .getInstance (getSchemaVersion ())).build ();
118114 }
119115
120116 /**
@@ -130,23 +126,23 @@ private JsonSchemaFactory initializeSchemaFactory() {
130126 * Note: we might not catch all places, but at least it works for nested objects and
131127 * array items.
132128 */
133- private static void assertSchemaStrictness (Collection <JsonValidator > validatorSet , String path ) {
129+ private static void assertSchemaStrictness (List <JsonValidator > validatorSet , String path ) {
134130 boolean additionalPropertiesValidatorFound = false ;
135131 boolean subSchemaFound = false ;
136132
137133 for (JsonValidator validator : validatorSet ) {
138134 if (validator instanceof PropertiesValidator propertiesValidator ) {
139135 subSchemaFound = true ;
140136 for (Entry <String , JsonSchema > subSchema : propertiesValidator .getSchemas ().entrySet ()) {
141- assertSchemaStrictness (subSchema .getValue ().getValidators (). values () , propertiesValidator .getSchemaPath ());
137+ assertSchemaStrictness (subSchema .getValue ().getValidators (), propertiesValidator .getSchemaLocation (). toString ());
142138 }
143139 } else if (validator instanceof ItemsValidator itemValidator ) {
144140 if (itemValidator .getSchema () != null ) {
145- assertSchemaStrictness (itemValidator .getSchema ().getValidators (). values () , itemValidator .getSchemaPath ());
141+ assertSchemaStrictness (itemValidator .getSchema ().getValidators (), itemValidator .getSchemaLocation (). toString ());
146142 }
147143 if (itemValidator .getTupleSchema () != null ) {
148144 for (JsonSchema subSchema : itemValidator .getTupleSchema ()) {
149- assertSchemaStrictness (subSchema .getValidators (). values () , itemValidator .getSchemaPath ());
145+ assertSchemaStrictness (subSchema .getValidators (), itemValidator .getSchemaLocation (). toString ());
150146 }
151147 }
152148 } else if (validator instanceof AdditionalPropertiesValidator ) {
0 commit comments