networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
807 stars 320 forks source link

late Schema mapping not possible in 1.3.x ? #990

Closed TF88641 closed 1 month ago

TF88641 commented 4 months ago

I'm trying to upgrade from 1.0.x to 1.3.3

Previously I would obtain a JsonSchemaFactory and then do something like

jsonSchemaFactory.getSchema(schemaURI, additionalConfig);

The useful thing here was I leveraged the config ability to customise URI translation like so

config.addUriTranslator(URITranslator.map("http://some.host.com:80/request.json", "resource:/schema/request.json"));

Yes I see in the docs URITranslator is moved to SchemaMapper, but the key point is by the looks of it we can't set the mapping up in config and pass it in on the fly -correct? Instead it seems I have to know in advance and customise before calling build() method of JsonSchemaFactory .because SchemaValidatorsConfig has nothing like

config.addSchemaMapper( schemaMapper );

Unless I'm missing something?

justin-tay commented 4 months ago

Yes it is no longer directly possible. The uri cache is held in the factory and late or contradictionary mappings would be confusing when it doesn't take.

You can always create an instance of a custom schema mapper and hold its reference to add your mappings late if you want.