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

Unable to open URI's (based on $ref) for remote locations in bundeled schemas #1

Closed
A-Fromell-Private opened this issue Jan 18, 2023 · 4 comments

Comments

@A-Fromell-Private
Copy link

Ex.
root schema:
{
"$id": "https://github.com/ITxPT/schematest/raw/main/identifiers/test5",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "Must be a non-negative integer",
"$comment": "A JSON Schema that uses multiple external references",
"$defs": {
"nonNegativeInteger": {
"allOf": [
{
"$ref": "/ITxPT/schematest/raw/main/identifiers/test5-1"
},
{
"$ref": "/ITxPT/schematest/raw/main/identifiers/test5-2"
}
]
}
},
"$ref": "#/$defs/nonNegativeInteger"
}

sub-schema-1:
{
"$id": "https://github.com/ITxPT/schematest/raw/main/identifiers/test5-1",
"$schema": "https://json-schema.org/draft/2020-12/schema#",
"description": "Must be an integer",
"type": "integer"
}

sub-schema-2:
{
"$id": "https://github.com/ITxPT/schematest/raw/main/identifiers/test5-2",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "Not allowed to be negative",
"minimum": 0
}

Output:
{
"exception": "CatalogError",
"message": "A source is not available for "https://github.com/ITxPT/schematest/raw/main/identifiers/test5-1\""
}

The schemas originates from: https://apisyouwonthate.com/blog/json-schema-bundling-finally-formalised

and is modified for evaluating external/remote sub-schemas..

What am I missing??
Best regards, Anders

@marksparkza
Copy link
Owner

Hi,

Apologies for the slow response.

The jschon.dev website does not support remote schema references, for security reasons.

However, it's fairly straightforward to enable this in application code. Take a look at the jschon library documentation. The docs only provide a LocalSource example, just swap that out for RemoteSource. The following catalog setup should work for you:

from jschon import create_catalog, RemoteSource, URI

catalog = create_catalog('2020-12')

catalog.add_uri_source(
    URI("https://github.com/ITxPT/schematest/"),
    RemoteSource("https://github.com/ITxPT/schematest/", suffix=".json")
)

@A-Fromell-Private
Copy link
Author

A-Fromell-Private commented Feb 1, 2023 via email

@handrews
Copy link

@A-Fromell-ITxPT I've contributed PR marksparkza/jschon#82 as a proposed solution to fully support referencing into bundles in jschon 0.10.0. You might want to follow that to see if it gets accepted - even if this proposal doesn't work out, I'm hoping to get it solved some way.

This is just for the library - I've never even looked at the jschon.dev site code (although I have to agree about the security concerns on remote references).

@handrews
Copy link

@A-Fromell-ITxPT See also marksparkza/jschon#85 for an approach to writing LocalSource/RemoteSource variations that can handle bundling, and marksparkza/jschon#83 for registering a source that handles all URIs (which might be necessary depending on how your bundles are set up, but usually isn't).

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

3 participants