Referencing other local JSON Schemas
See original GitHub issueI have strong doubts whether this is a bug or not, but it is definitely a nice-to-have feature which is foreseen by the JSON Schema specification.
What the specification states
The Schema References With “$ref” section states the following:
Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by “$id”. In all cases, dereferencing a “$ref” reference involves first resolving its value as a URI reference against the current base URI per RFC 3986.
As an example it provides the following simple case:
When an implementation encounters the reference to
"other.json"
, it resolves this to<http://example.net/other.json>
, which is not defined in this document. If a schema with that identifier has otherwise been supplied to the implementation, it can also be used automatically.
And this is how it works in the latest version of the Manifold, no offense here. 😄 We are able to reference the schema with the same base URI, i.e. on the same level in the filesystem’s directory structure. It compiles and it runs smoothly.
At the same time, it is impossible to introduce any hierarchical structure on top of one’s schemas, i.e. to use subdirectories and reference other schemas relatively in both directions: forth with "sub/other.json"
and back with "../other.json"
.
But there are these “can be identified by any URI” and “In all cases <…> resolving its value as a URI reference against the current base URI” parts that make me believe that such a scenario is also considered possible, yet omitted in the current Manifold’s implementation.
What the specification doesn’t state yet
What causes my doubts is an associated cite reference:
What should implementations do when the referenced schema is not known? Are there circumstances in which automatic network dereferencing is allowed? A same origin policy? A user-configurable option? In the case of an evolving API described by Hyper-Schema, it is expected that new schemas will be added to the system dynamically, so placing an absolute requirement of pre-loading schema documents is not feasible.
While it is not feasible in the wild (a.k.a. World Wild Web), we are dealing with a special case of “static resources as Java Types” and it would seem that it doesn’t matter much. However, there might be matters to discuss.
What everyone (including myself) definitely wants to be able to do is to work with such references without fuss in the Manifold’s “dynamic mode”.
Scenarios in scope
Test 1
Checks an ability to reference the "sub/other.json"
schema from the current one.
Manifold is unable to compile such a schema in the current implementation:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project manifold-json-subschema-test: Compilation failure: Compilation failure:
[ERROR] /abc/res/Test1.java:[39,11] cannot find symbol
[ERROR] symbol: class SubTest1
[ERROR] location: interface abc.res.Test1
[ERROR] /abc/res/Test1.java:[44,27] cannot find symbol
[ERROR] symbol: class SubTest1
[ERROR] location: interface abc.res.Test1
[ERROR] /abc/res/Test1.java:[70,32] cannot find symbol
[ERROR] symbol: class SubTest1
[ERROR] location: class abc.res.Test1.Builder
[ERROR] /abc/res/Test1.java:[82,27] cannot find symbol
[ERROR] symbol: class SubTest1
[ERROR] location: class abc.res.Test1.Copier
It also happens that Manifold’s IntelliJ plugin is dealing fine (w/o "No such file or directory"
error) with such a "$ref"
.
Test 2
Checks an ability to back-reference the "../other.json"
schema from the current one.
⚠️ In case Test 1 succeeds, this one is also expected to pass according to the URI Relative Resolution rules.
Now it gives almost the same compilation error:
[ERROR] /abc/res/sub/SubTest2.java:[39,11] cannot find symbol
[ERROR] symbol: class Test2
[ERROR] location: interface abc.res.sub.SubTest2
[ERROR] /abc/res/sub/SubTest2.java:[44,25] cannot find symbol
[ERROR] symbol: class Test2
[ERROR] location: interface abc.res.sub.SubTest2
[ERROR] /abc/res/sub/SubTest2.java:[70,30] cannot find symbol
[ERROR] symbol: class Test2
[ERROR] location: class abc.res.sub.SubTest2.Builder
[ERROR] /abc/res/sub/SubTest2.java:[82,25] cannot find symbol
[ERROR] symbol: class Test2
[ERROR] location: class abc.res.sub.SubTest2.Copier
And is equally located by the IntelliJ plugin.
As always, test project is available here: https://github.com/marksto/manifold-json-subschema-test
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Fix available in release 0.65-alpha
Superb, will check this out soon!