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

jsonschema.exceptions._RefResolutionError: hypothesis-jsonschema does not fetch remote references #109

Closed
nbro10 opened this issue Oct 21, 2024 · 5 comments

Comments

@nbro10
Copy link

nbro10 commented Oct 21, 2024

My understanding is that we can refer to other local JSON schemas using $ref. So, I have these 2 schemas in my local file system (in the same directory)

main.json

{
    "type": "object",
    "properties": {
        "language": {
            "$ref": "./language.json#"
        },
        "required": [
            "language",
        ],
        "additionalProperties": false
    }
}

And language.json

{
    "type": "string",
    "enum": [
        "en",
        "fr"
    ]
}

Now, I was trying to generate a random sample by calling from_schema(my_schema).example(), but I keep getting the error

jsonschema.exceptions._RefResolutionError: hypothesis-jsonschema does not fetch remote references (uri='./language.json')

and I'm not sure why.

Instead of "./language.json#", I also tried "language.json#" and other variations I've seen on the web...

Does this library support this? If yes, how? If not, what alternative do you suggest?

@nbro10 nbro10 changed the title jsonschema.exceptions._RefResolutionError: hypothesis-jsonschema does not fetch remote references (uri='./language.json') jsonschema.exceptions._RefResolutionError: hypothesis-jsonschema does not fetch remote references Oct 21, 2024
@Zac-HD
Copy link
Member

Zac-HD commented Oct 21, 2024

A "remote reference" is anything outside the current document, so unfortunately this is working as intended - local filesystem and remote URL both involve IO, and that's the problematic part.

@Zac-HD Zac-HD closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2024
@nbro10
Copy link
Author

nbro10 commented Oct 21, 2024

@Zac-HD Why is it problematic to read from the file system? Can you clarify?

@Zac-HD
Copy link
Member

Zac-HD commented Oct 21, 2024

IO and state make managing the logic much more difficult, introduce performance issues, and make caching unsafe. I'd suggest resolving the schema into a single document before handing that to hypothesis-jsonschema.

@nbro10
Copy link
Author

nbro10 commented Oct 21, 2024

Ok, but you'd not be forced to use it. If you want performance, you can just create a single schema, if you want composability, you'd need $ref. It looks like a big limitation to me and I'd assume that I am not the first one asking or looking for this feature.

@roversch
Copy link

Hey I totally understand where you're coming from @Zac-HD , but can you add a note somewhere? I just lost 2 hours before I stumbled upon this issue.

As of version 0.11, this includes resolving non-recursive references!

This signals that $ref into other file is supported.

Anyway, thanks for the great library!

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