Skip to content

Failing to load draft-07 type schemas (probably lower ones too) #29

Closed
@elisherer

Description

@elisherer

Using SchemaStore::loadSchema(Object document) get stuck in an infinite loop trying to fetch the meta-schema of draft-07.
Getting logs:

net.jimblackler.jsonschemafriend.SchemaStore: Was not valid JSON: http://json-schema.org/draft-07/schema

It began today (2023-10-02) and probably is related to a change made at https://json-schema.org/blog/posts/new-website.

Issue

  • It seems that the issue is with the http stream not following 301 redirects.
  • Also getting into an infinite loop instead of failing fast makes the service unresponsive.

Reproduce

  • I think any piece of code (like the one in the README.md) which loads draft-07 schema will fail.

Workaround

Workaround 1:

Using a url rewriter (a bit dangerous)

public class SchemaForceHttpsUrlRewriter implements UrlRewriter {
    @Override
    public URI rewrite(URI in) {
        if (in.toString().startsWith("http:")) {
            return URI.create(in.toString().replaceFirst("http:", "https:"));
        }
        return in;
    }
}

Initialize store with store = new SchemaStore(new SchemaForceHttpsUrlRewriter());

Workaround 2:

not using a validator when using loadSchema

store.loadSchema(obj, null);

Workaround 3:

Storing the meta schemas as resources in the module and pre-loading them before calling loadSchema
Using SchemaStore::store(URI uri, Object document)
or SchemaStore::register(URI path, Schema schema)

(Maybe as a premanent solution it would be best to bundle all meta-schema draft-03+ with the library and prevent even trying to download them)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions