JSON schema cross file references using $anchor and $ref

Oxygen general issues.
spql
Posts: 2
Joined: Wed Nov 30, 2022 6:57 pm

JSON schema cross file references using $anchor and $ref

Post 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"}
}
}
spql
Posts: 2
Joined: Wed Nov 30, 2022 6:57 pm

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

Post 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>
tavy
Posts: 340
Joined: Thu Jul 01, 2004 12:29 pm

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

Post 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
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply