Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alternate means of retrieving content #14

Open
gareth-robinson opened this issue Nov 24, 2021 · 8 comments
Open

Allow alternate means of retrieving content #14

gareth-robinson opened this issue Nov 24, 2021 · 8 comments

Comments

@gareth-robinson
Copy link
Contributor

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 #3 and need to provide their own means of resolving a schema?

@pedroteixeira
Copy link

pedroteixeira commented Dec 14, 2021

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 :)

@jimblackler
Copy link
Owner

jimblackler commented Jan 27, 2022 via email

@pedroteixeira
Copy link

pedroteixeira commented Jan 27, 2022

At the moment there's a network exception, so AFAIK the library wouldn't really work in offline mode.

@jimblackler
Copy link
Owner

Depending on how you load the schemas, providing 'null' as the validator

public Schema loadSchema(Object document, Validator validator) throws GenerationException {
should cause the metaschema not to be loaded. Can you try that?

@dilishanaidu
Copy link

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?

@jimblackler
Copy link
Owner

Sorry I thought I had made a release since then. I'll do a release when the current outstanding PR is in.

@dilishanaidu
Copy link

Hi are there any plans on releasing the latest changes?
Thanks!

@jimblackler
Copy link
Owner

Thank you for the reminder. I just pushed 0.11.3, it should show up on Jitpack shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants