java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.63k stars 399 forks source link

Cannot easily override default schemas in ValidationConfigurationBuilder #297

Open michaelboyles opened 5 years ago

michaelboyles commented 5 years ago

When solving https://github.com/java-json-tools/json-schema-validator/issues/294 I noticed that there is no way to create a ValidationConfigurationBuilder without the builder already including the defaults.

This means that if you attempt to override any of the defaults, you will get an IllegalArgumentException (though interestingly, due to the nature of the check, it actually will have been overridden, it's just an annoying unchecked exception I have to deal with). This seems like a gap in the API to me.

Reproducible example:

final ValidationConfigurationBuilder builder = ValidationConfiguration.newBuilder();
builder.addLibrary("http://json-schema.org/draft-04/schema#", Library.newBuilder().freeze());

This could be solved in a few ways with non-breaking API changes:

builder.overrideLibrary("http://json-schema.org/draft-04/schema#", myLib);
builder.clearLibraries();
builder.getLibraries().clear();