Page 1 of 1

JSON schema cross file references using $anchor and $ref

Posted: Wed Nov 30, 2022 7:30 pm
by spql
I need to reference common definitions in a number for schema, but can get it working in oxygenxml v.25.0

I've created a common.jschema file with the common $defs definition with an $achor and $id. However when I try to reference this from another schema in a $ref it can't resolve the reference. The $ref in the file my_schema,jshema gives an error "#/properties/name/$ref: ro.sync.net.protocol.http.HttpExceptionWithDetails: 404 Not Found for: https://example.com/schemas/common"

Is this supported in oxygenxl v.25.0? How do is this done?

Here are the two examples; All files are in the same directory -
common.jschema:
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"$id": "https://example.com/schemas/common",
"$defs": {
"non-empty-string": {
"$anchor": "non-empty-string",
"type": "string",
"minLength": 1
}
}
}

my_string.jschema:
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"$id": "https://example.com/schemas/my_string",

"type": "object",
"properties": {
"name": {"$ref": "/schemas/common#non-empty_string"}
}
}

Re: JSON schema cross file references using $anchor and $ref

Posted: Thu Dec 01, 2022 4:06 pm
by spql
I've resolved this issue. Here is the solution in case anyone else needs it:

Compound schema documents, where a schema refers to a schema in another file, require the URIs to be mapped to the actual shema file location
In Oxygen xml this is done using can XML Catalogue
Create an XML Catalogue file (File-> New ->XML Catalogue) called for example "catalogue.xml"
Add mapping to the file e.g. <uri name="https://example.com/schemas/common" uri="common.jschema"/>
Add this catalogue to the list of cats the Oxygenxml searches: Options-> Preferences->XML->XML Catalogue – <add the catalogue file>

Re: JSON schema cross file references using $anchor and $ref

Posted: Fri Dec 02, 2022 11:55 am
by tavy
Hello,

Yes, if you have references to remote schemas you can use an XML Catalog to resolve the references locally.
There is a topic in our user manual that explains the resolving references with an XML Catalog:
https://www.oxygenxml.com/doc/versions/ ... talog.html

Best Regards,
Octavian

Re: JSON schema cross file references using $anchor and $ref

Posted: Mon Jul 31, 2023 10:53 pm
by spql
I've come back to this and tried to get this working again but can't. I'd like to produce a very simple example of a schema referencing a common definition schema file and using an XML catalogue to resolve the URI of the common reference to a local file in the same directory. I've tryed using the above example but can't get it working and can't find any worked example.

Re: JSON schema cross file references using $anchor and $ref

Posted: Fri Aug 04, 2023 4:49 pm
by florin_nica
Hello,

Oxygen does not support $anchor references. Instead, references can be resolved in JSON Schema Design Page if you add a $id value (URI fragment) to your local resource. So, all you have to do in order to have a working example is to go to common.jschema file and replace

Code: Select all

"$anchor": "non-empty-string"
with

Code: Select all

"$id": "#non-empty-string"
Let me know if that worked for you.

Regards,
Florin