jsonschemafriend
jsonschemafriend copied to clipboard
Allow alternate means of retrieving content
At the moment the SchemaStore
will, if it finds a schema that hasn't yet been resolved, call the getContent
method to retrieve it:
https://github.com/jimblackler/jsonschemafriend/blob/master/library/src/main/java/net/jimblackler/jsonschemafriend/SchemaStore.java#L144
That getContent method will then use the static CacheLoader.load method.
I see you can also preload the SchemaStore using the public store or register methods.
What I'm asking for though is the ability to intercept that getContent loading method (in my case I may want to store schemas in some persistence layer), via say an interface ContentLoader ...
public SchemaStore(UrlRewriter urlRewriter, boolean cacheSchema, ContentLoader contentLoader) {
...
this.contentLoader = contentLoader;
}
private String getContent(URI documentUri) throws IOException {
Uri uriToLoad = urlRewriter == null : documentUri : urlRewriter.rewrite(documentUri);
if (contentLoader != null) {
return contentLoader.load(uriToLoad, cacheSchema);
}
return load(uriToLoad, cacheSchema);
}
Maybe that would also help with developers who have issues like https://github.com/jimblackler/jsonschemafriend/issues/3 and need to provide their own means of resolving a schema?
Hi, I was checking out this library, and did notice it attempts to download content from https://json-schema.org/ -- in my use case, I would need application to work offline.. so probably embed the schema files would work.
@jimblackler any advice to avoid the external download attempt? thanks :)
They can be cached on the first instance if you ever do have internet access. It's not strictly necessary to have the metaschema, it just can't validate the schemas themselves. I can't recall currently what happens if the fetch can't complete. Certainly it could be configured to continue without the schema validation against the metaschema.
On Tue, 14 Dec 2021 at 17:15, Pedro Henriques dos Santos Teixeira < @.***> wrote:
Hi, I was checking out this library, and did notice it attempts to download content from https://json-schema.org/ -- in my use case, I would need application to work offline.. so probably embed the schema files would work. Any advice to avoid the external download attempt?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jimblackler/jsonschemafriend/issues/14#issuecomment-993799800, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFH6F4CVSWQSTXAD5WU32LUQ53UNANCNFSM5IWSKY4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
At the moment there's a network exception, so AFAIK the library wouldn't really work in offline mode.
Depending on how you load the schemas, providing 'null' as the validator https://github.com/jimblackler/jsonschemafriend/blob/e2e33667772ff13ad8876c39b61b2deb32590118/library/src/main/java/net/jimblackler/jsonschemafriend/SchemaStore.java#L72 should cause the metaschema not to be loaded. Can you try that?
Hi are there any plans to release this change? In my use case, I would need the application to work offline, is there a way it can pick up the schema from resource folder if specified there?
Sorry I thought I had made a release since then. I'll do a release when the current outstanding PR is in.
Hi are there any plans on releasing the latest changes? Thanks!
Thank you for the reminder. I just pushed 0.11.3, it should show up on Jitpack shortly.